gloo-lang 0.9.4 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/gloo-lang.gemspec +1 -0
  4. data/lib/VERSION +1 -1
  5. data/lib/gloo_lang/app/args.rb +0 -1
  6. data/lib/gloo_lang/app/engine.rb +10 -37
  7. data/lib/gloo_lang/app/help.rb +2 -41
  8. data/lib/gloo_lang/app/log.rb +8 -10
  9. data/lib/gloo_lang/app/platform.rb +75 -0
  10. data/lib/gloo_lang/app/settings.rb +36 -13
  11. data/lib/gloo_lang/objs/basic/container.rb +1 -12
  12. data/lib/gloo_lang/objs/basic/text.rb +2 -10
  13. data/lib/gloo_lang/objs/data/markdown.rb +2 -7
  14. data/lib/gloo_lang/objs/data/table.rb +1 -29
  15. data/lib/gloo_lang/verbs/show.rb +3 -2
  16. metadata +22 -22
  17. data/lib/gloo_lang/objs/cli/banner.rb +0 -108
  18. data/lib/gloo_lang/objs/cli/bar.rb +0 -133
  19. data/lib/gloo_lang/objs/cli/colorize.rb +0 -73
  20. data/lib/gloo_lang/objs/cli/confirm.rb +0 -96
  21. data/lib/gloo_lang/objs/cli/menu.rb +0 -206
  22. data/lib/gloo_lang/objs/cli/menu_item.rb +0 -95
  23. data/lib/gloo_lang/objs/cli/pastel.rb +0 -97
  24. data/lib/gloo_lang/objs/cli/prompt.rb +0 -110
  25. data/lib/gloo_lang/objs/cli/select.rb +0 -126
  26. data/lib/gloo_lang/objs/data/mysql.rb +0 -192
  27. data/lib/gloo_lang/objs/data/sqlite.rb +0 -159
  28. data/lib/gloo_lang/objs/dev/git.rb +0 -140
  29. data/lib/gloo_lang/objs/dev/stats.rb +0 -120
  30. data/lib/gloo_lang/objs/snd/play.rb +0 -48
  31. data/lib/gloo_lang/objs/snd/say.rb +0 -98
  32. data/lib/gloo_lang/objs/system/file_handle.rb +0 -138
  33. data/lib/gloo_lang/objs/system/ssh_exec.rb +0 -126
  34. data/lib/gloo_lang/objs/system/system.rb +0 -136
  35. data/lib/gloo_lang/verbs/alert.rb +0 -79
  36. data/lib/gloo_lang/verbs/beep.rb +0 -40
  37. data/lib/gloo_lang/verbs/cls.rb +0 -37
@@ -1,108 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # Show a large-text banner.
5
- #
6
- require 'tty-font'
7
- require 'pastel'
8
-
9
- module GlooLang
10
- module Objs
11
- class Banner < GlooLang::Core::Obj
12
-
13
- KEYWORD = 'banner'.freeze
14
- KEYWORD_SHORT = 'ban'.freeze
15
- TEXT = 'text'.freeze
16
- STYLE = 'style'.freeze
17
- COLOR = 'color'.freeze
18
-
19
- #
20
- # The name of the object type.
21
- #
22
- def self.typename
23
- return KEYWORD
24
- end
25
-
26
- #
27
- # The short name of the object type.
28
- #
29
- def self.short_typename
30
- return KEYWORD_SHORT
31
- end
32
-
33
- #
34
- # Get the banner text from the child object.
35
- #
36
- def text_value
37
- o = find_child TEXT
38
- return '' unless o
39
-
40
- return o.value
41
- end
42
-
43
- #
44
- # Get the banner style from the child object.
45
- #
46
- def style_value
47
- o = find_child STYLE
48
- return '' unless o
49
-
50
- return o.value
51
- end
52
-
53
- #
54
- # Get the banner color from the child object.
55
- #
56
- def color_value
57
- o = find_child COLOR
58
- return '' unless o
59
-
60
- return o.value
61
- end
62
-
63
- # ---------------------------------------------------------------------
64
- # Children
65
- # ---------------------------------------------------------------------
66
-
67
- # Does this object have children to add when an object
68
- # is created in interactive mode?
69
- # This does not apply during obj load, etc.
70
- def add_children_on_create?
71
- return true
72
- end
73
-
74
- # Add children to this object.
75
- # This is used by containers to add children needed
76
- # for default configurations.
77
- def add_default_children
78
- fac = $engine.factory
79
- fac.create_string TEXT, '', self
80
- fac.create_string STYLE, '', self
81
- fac.create_string COLOR, '', self
82
- end
83
-
84
- # ---------------------------------------------------------------------
85
- # Messages
86
- # ---------------------------------------------------------------------
87
-
88
- #
89
- # Get a list of message names that this object receives.
90
- #
91
- def self.messages
92
- return super + %w[show]
93
- end
94
-
95
- #
96
- # Show the banner bar
97
- #
98
- def msg_show
99
- font = TTY::Font.new self.style_value
100
- t = font.write( self.text_value )
101
- pastel = ::Pastel.new
102
- c = self.color_value.split( ' ' ).map( &:to_sym )
103
- puts pastel.decorate( t, *c )
104
- end
105
-
106
- end
107
- end
108
- end
@@ -1,133 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # Show a CLI progress bar.
5
- #
6
- require 'tty-progressbar'
7
-
8
- module GlooLang
9
- module Objs
10
- class Bar < GlooLang::Core::Obj
11
-
12
- KEYWORD = 'bar'.freeze
13
- KEYWORD_SHORT = 'bar'.freeze
14
- NAME = 'name'.freeze
15
- TOTAL = 'total'.freeze
16
-
17
- #
18
- # The name of the object type.
19
- #
20
- def self.typename
21
- return KEYWORD
22
- end
23
-
24
- #
25
- # The short name of the object type.
26
- #
27
- def self.short_typename
28
- return KEYWORD_SHORT
29
- end
30
-
31
- #
32
- # Get the bar's name from the child object.
33
- #
34
- def name_value
35
- o = find_child NAME
36
- return '' unless o
37
-
38
- return o.value
39
- end
40
-
41
- #
42
- # Get the bar's total from the child object.
43
- #
44
- def total_value
45
- o = find_child TOTAL
46
- return 100 unless o
47
-
48
- return o.value
49
- end
50
-
51
- # ---------------------------------------------------------------------
52
- # Children
53
- # ---------------------------------------------------------------------
54
-
55
- # Does this object have children to add when an object
56
- # is created in interactive mode?
57
- # This does not apply during obj load, etc.
58
- def add_children_on_create?
59
- return true
60
- end
61
-
62
- # Add children to this object.
63
- # This is used by containers to add children needed
64
- # for default configurations.
65
- def add_default_children
66
- fac = $engine.factory
67
- fac.create_string NAME, '', self
68
- fac.create_int TOTAL, 100, self
69
- end
70
-
71
- # ---------------------------------------------------------------------
72
- # Messages
73
- # ---------------------------------------------------------------------
74
-
75
- #
76
- # Get a list of message names that this object receives.
77
- #
78
- def self.messages
79
- return super + %w[start advance stop run]
80
- end
81
-
82
- #
83
- # Start the progress bar.
84
- #
85
- def msg_start
86
- msg = "#{name_value} [:bar] :percent"
87
- @bar = TTY::ProgressBar.new( msg, total: total_value )
88
- end
89
-
90
- #
91
- # Finish the progress bar.
92
- #
93
- def msg_stop
94
- @bar.finish
95
- end
96
-
97
- #
98
- # Advance the progress bar.
99
- #
100
- def msg_advance
101
- x = 1
102
- if @params&.token_count&.positive?
103
- expr = GlooLang::Expr::Expression.new( @params.tokens )
104
- x = expr.evaluate.to_i
105
- end
106
-
107
- @bar.advance x
108
- end
109
-
110
- #
111
- # Run for the given number of seconds advancing
112
- # the bar to the end.
113
- #
114
- def msg_run
115
- msg_start
116
-
117
- x = 1
118
- if @params&.token_count&.positive?
119
- expr = GlooLang::Expr::Expression.new( @params.tokens )
120
- x = expr.evaluate.to_i
121
- end
122
-
123
- 100.times do
124
- sleep ( 0.0 + x ) / 100.0
125
- @bar.advance 1
126
- end
127
-
128
- msg_stop
129
- end
130
-
131
- end
132
- end
133
- end
@@ -1,73 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # Show colorized output.
5
- #
6
- require 'colorized_string'
7
-
8
- module GlooLang
9
- module Objs
10
- class Colorize < GlooLang::Core::Obj
11
-
12
- KEYWORD = 'colorize'.freeze
13
- KEYWORD_SHORT = 'color'.freeze
14
-
15
- #
16
- # The name of the object type.
17
- #
18
- def self.typename
19
- return KEYWORD
20
- end
21
-
22
- #
23
- # The short name of the object type.
24
- #
25
- def self.short_typename
26
- return KEYWORD_SHORT
27
- end
28
-
29
- # ---------------------------------------------------------------------
30
- # Children
31
- # ---------------------------------------------------------------------
32
-
33
- # Does this object have children to add when an object
34
- # is created in interactive mode?
35
- # This does not apply during obj load, etc.
36
- def add_children_on_create?
37
- return true
38
- end
39
-
40
- # Add children to this object.
41
- # This is used by containers to add children needed
42
- # for default configurations.
43
- def add_default_children
44
- fac = $engine.factory
45
- fac.create_string 'white', '', self
46
- end
47
-
48
- # ---------------------------------------------------------------------
49
- # Messages
50
- # ---------------------------------------------------------------------
51
-
52
- #
53
- # Get a list of message names that this object receives.
54
- #
55
- def self.messages
56
- return super + [ 'run' ]
57
- end
58
-
59
- #
60
- # Run the colorize command.
61
- #
62
- def msg_run
63
- msg = ''
64
- children.each do |o|
65
- msg += ColorizedString[ o.value_display ].colorize( o.name.to_sym )
66
- end
67
- $log.show msg
68
- $engine.heap.it.set_to msg.to_s
69
- end
70
-
71
- end
72
- end
73
- end
@@ -1,96 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # Show a CLI confirmation prompt.
5
- #
6
-
7
- module GlooLang
8
- module Objs
9
- class Confirm < GlooLang::Core::Obj
10
-
11
- KEYWORD = 'confirm'.freeze
12
- KEYWORD_SHORT = 'confirm'.freeze
13
- PROMPT = 'prompt'.freeze
14
- DEFAULT_PROMPT = '> '.freeze
15
- RESULT = 'result'.freeze
16
-
17
- #
18
- # The name of the object type.
19
- #
20
- def self.typename
21
- return KEYWORD
22
- end
23
-
24
- #
25
- # The short name of the object type.
26
- #
27
- def self.short_typename
28
- return KEYWORD_SHORT
29
- end
30
-
31
- #
32
- # Get the URI from the child object.
33
- # Returns nil if there is none.
34
- #
35
- def prompt_value
36
- o = find_child PROMPT
37
- return nil unless o
38
-
39
- return o.value
40
- end
41
-
42
- #
43
- # Set the result of the system call.
44
- #
45
- def set_result( data )
46
- r = find_child RESULT
47
- return nil unless r
48
-
49
- r.set_value data
50
- end
51
-
52
- # ---------------------------------------------------------------------
53
- # Children
54
- # ---------------------------------------------------------------------
55
-
56
- # Does this object have children to add when an object
57
- # is created in interactive mode?
58
- # This does not apply during obj load, etc.
59
- def add_children_on_create?
60
- return true
61
- end
62
-
63
- # Add children to this object.
64
- # This is used by containers to add children needed
65
- # for default configurations.
66
- def add_default_children
67
- fac = $engine.factory
68
- fac.create_string PROMPT, DEFAULT_PROMPT, self
69
- fac.create_bool RESULT, nil, self
70
- end
71
-
72
- # ---------------------------------------------------------------------
73
- # Messages
74
- # ---------------------------------------------------------------------
75
-
76
- #
77
- # Get a list of message names that this object receives.
78
- #
79
- def self.messages
80
- return super + [ 'run' ]
81
- end
82
-
83
- #
84
- # Run the confirmation command.
85
- #
86
- def msg_run
87
- prompt = prompt_value
88
- return unless prompt
89
-
90
- result = $prompt.yes?( prompt )
91
- set_result result
92
- end
93
-
94
- end
95
- end
96
- end
@@ -1,206 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # A CLI menu.
5
- # The menu contains a collection of menu items, a prompt
6
- # and an option to loop until done.
7
- #
8
-
9
- module GlooLang
10
- module Objs
11
- class Menu < GlooLang::Core::Obj
12
-
13
- KEYWORD = 'menu'.freeze
14
- KEYWORD_SHORT = 'menu'.freeze
15
- PROMPT = 'prompt'.freeze
16
- ITEMS = 'items'.freeze
17
- LOOP = 'loop'.freeze
18
- HIDE_ITEMS = 'hide_items'.freeze
19
- BEFORE_MENU = 'before_menu'.freeze
20
- DEFAULT = 'default'.freeze
21
-
22
- #
23
- # The name of the object type.
24
- #
25
- def self.typename
26
- return KEYWORD
27
- end
28
-
29
- #
30
- # The short name of the object type.
31
- #
32
- def self.short_typename
33
- return KEYWORD_SHORT
34
- end
35
-
36
- #
37
- # Get the value of the prompt child object.
38
- # Returns nil if there is none.
39
- #
40
- def prompt_value
41
- o = find_child PROMPT
42
- return '' unless o
43
-
44
- return o.value
45
- end
46
-
47
- #
48
- # Get the value of the loop child object.
49
- # Should we keep looping or should we stop?
50
- #
51
- def loop?
52
- o = find_child LOOP
53
- return false unless o
54
-
55
- return o.value
56
- end
57
-
58
- # ---------------------------------------------------------------------
59
- # Children
60
- # ---------------------------------------------------------------------
61
-
62
- #
63
- # Does this object have children to add when an object
64
- # is created in interactive mode?
65
- # This does not apply during obj load, etc.
66
- #
67
- def add_children_on_create?
68
- return true
69
- end
70
-
71
- #
72
- # Add children to this object.
73
- # This is used by containers to add children needed
74
- # for default configurations.
75
- #
76
- def add_default_children
77
- fac = $engine.factory
78
- fac.create_string PROMPT, '> ', self
79
- fac.create_can ITEMS, self
80
- fac.create_bool LOOP, true, self
81
- fac.create_script DEFAULT, '', self
82
- end
83
-
84
- # ---------------------------------------------------------------------
85
- # Messages
86
- # ---------------------------------------------------------------------
87
-
88
- #
89
- # Get a list of message names that this object receives.
90
- #
91
- def self.messages
92
- return super + [ 'run' ]
93
- end
94
-
95
- #
96
- # Show the menu options, and prompt for user input.
97
- #
98
- def msg_run
99
- loop do
100
- begin_menu
101
- if prompt_value.empty?
102
- dt = DateTime.now
103
- d = dt.strftime( '%Y.%m.%d' )
104
- t = dt.strftime( '%I:%M:%S' )
105
- cmd = $prompt.ask( "#{d.yellow} #{t.white} >" )
106
- else
107
- cmd = $prompt.ask( prompt_value )
108
- end
109
- cmd ? run_command( cmd ) : run_default
110
- break unless loop?
111
- end
112
- end
113
-
114
- # ---------------------------------------------------------------------
115
- # Menu actions
116
- # ---------------------------------------------------------------------
117
-
118
- #
119
- # Begin the menu execution.
120
- # Run the before menu script if there is one,
121
- # then show options unless we are hiding them by default.
122
- #
123
- def begin_menu
124
- run_before_menu
125
-
126
- # Check to see if we should show items at all.
127
- o = find_child HIDE_ITEMS
128
- return if o && o.value == true
129
-
130
- show_options
131
- end
132
-
133
- #
134
- # If there is a before menu script, run it now.
135
- #
136
- def run_before_menu
137
- o = find_child BEFORE_MENU
138
- return unless o
139
-
140
- GlooLang::Exec::Dispatch.message 'run', o
141
- end
142
-
143
- #
144
- # Show the list of menu options.
145
- #
146
- def show_options
147
- o = find_child ITEMS
148
- return unless o
149
-
150
- o.children.each do |mitem|
151
- mitem = GlooLang::Objs::Alias.resolve_alias( mitem )
152
- puts " #{mitem.shortcut_value} - #{mitem.description_value}"
153
- end
154
- end
155
-
156
- #
157
- # Find the command matching user input.
158
- #
159
- def find_cmd( cmd )
160
- o = find_child ITEMS
161
- return nil unless o
162
-
163
- o.children.each do |mitem|
164
- mitem = GlooLang::Objs::Alias.resolve_alias( mitem )
165
- return mitem if mitem.shortcut_value.downcase == cmd.downcase
166
- end
167
-
168
- return nil
169
- end
170
-
171
- #
172
- # Run the default option.
173
- #
174
- def run_default
175
- obj = find_child DEFAULT
176
- return unless obj
177
-
178
- s = GlooLang::Exec::Script.new obj
179
- s.run
180
- end
181
-
182
- #
183
- # Run the selected command.
184
- #
185
- def run_command( cmd )
186
- obj = find_cmd cmd
187
-
188
- unless obj
189
- if cmd == '?'
190
- show_options
191
- else
192
- puts "#{cmd} is not a valid option"
193
- end
194
- return
195
- end
196
-
197
- script = obj.do_script
198
- return unless script
199
-
200
- s = GlooLang::Exec::Script.new script
201
- s.run
202
- end
203
-
204
- end
205
- end
206
- end
@@ -1,95 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # A CLI menu item. One element in a CLI menu.
5
- #
6
-
7
- module GlooLang
8
- module Objs
9
- class MenuItem < GlooLang::Core::Obj
10
-
11
- KEYWORD = 'menu_item'.freeze
12
- KEYWORD_SHORT = 'mitem'.freeze
13
- SHORTCUT = 'shortcut'.freeze
14
- DESCRIPTION = 'description'.freeze
15
- DO = 'do'.freeze
16
-
17
- #
18
- # The name of the object type.
19
- #
20
- def self.typename
21
- return KEYWORD
22
- end
23
-
24
- #
25
- # The short name of the object type.
26
- #
27
- def self.short_typename
28
- return KEYWORD_SHORT
29
- end
30
-
31
- #
32
- # Get the value of the menu item shortcut.
33
- # Returns nil if there is none.
34
- #
35
- def shortcut_value
36
- o = find_child SHORTCUT
37
- return self.name unless o
38
-
39
- return o.value
40
- end
41
-
42
- #
43
- # Get the action's description.
44
- # Returns nil if there is none.
45
- #
46
- def description_value
47
- o = find_child DESCRIPTION
48
- return self.value unless o
49
-
50
- return o.value
51
- end
52
-
53
- #
54
- # Get the action's script.
55
- # Returns nil if there is none.
56
- #
57
- def do_script
58
- return find_child DO
59
- end
60
-
61
- # ---------------------------------------------------------------------
62
- # Children
63
- # ---------------------------------------------------------------------
64
-
65
- # Does this object have children to add when an object
66
- # is created in interactive mode?
67
- # This does not apply during obj load, etc.
68
- def add_children_on_create?
69
- return true
70
- end
71
-
72
- # Add children to this object.
73
- # This is used by containers to add children needed
74
- # for default configurations.
75
- def add_default_children
76
- fac = $engine.factory
77
- fac.create_string SHORTCUT, '', self
78
- fac.create_string DESCRIPTION, '', self
79
- fac.create_script DO, '', self
80
- end
81
-
82
- # ---------------------------------------------------------------------
83
- # Messages
84
- # ---------------------------------------------------------------------
85
-
86
- #
87
- # Get a list of message names that this object receives.
88
- #
89
- def self.messages
90
- return super
91
- end
92
-
93
- end
94
- end
95
- end