gloo 0.3.0 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.rubocop.yml +73 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +86 -83
- data/Rakefile +7 -6
- data/bin/console +4 -4
- data/gloo.gemspec +22 -18
- data/lib/gloo.rb +6 -6
- data/lib/gloo/app/args.rb +30 -31
- data/lib/gloo/app/engine.rb +80 -30
- data/lib/gloo/app/help.rb +17 -11
- data/lib/gloo/app/info.rb +3 -3
- data/lib/gloo/app/log.rb +17 -17
- data/lib/gloo/app/mode.rb +4 -4
- data/lib/gloo/app/settings.rb +51 -41
- data/lib/gloo/convert/string_to_datetime.rb +21 -0
- data/lib/gloo/convert/string_to_decimal.rb +20 -0
- data/lib/gloo/convert/string_to_integer.rb +20 -0
- data/lib/gloo/core/baseo.rb +7 -7
- data/lib/gloo/core/dictionary.rb +30 -27
- data/lib/gloo/core/error.rb +50 -0
- data/lib/gloo/core/event_manager.rb +17 -23
- data/lib/gloo/core/factory.rb +149 -39
- data/lib/gloo/core/gloo_system.rb +121 -54
- data/lib/gloo/core/heap.rb +15 -13
- data/lib/gloo/core/it.rb +5 -5
- data/lib/gloo/core/literal.rb +7 -7
- data/lib/gloo/core/obj.rb +138 -79
- data/lib/gloo/core/obj_finder.rb +9 -14
- data/lib/gloo/core/op.rb +8 -8
- data/lib/gloo/core/parser.rb +27 -26
- data/lib/gloo/core/pn.rb +68 -52
- data/lib/gloo/core/script.rb +7 -7
- data/lib/gloo/core/tokens.rb +39 -41
- data/lib/gloo/core/verb.rb +30 -19
- data/lib/gloo/exec/dispatch.rb +30 -0
- data/lib/gloo/exec/runner.rb +43 -0
- data/lib/gloo/expr/expression.rb +36 -43
- data/lib/gloo/expr/l_boolean.rb +7 -6
- data/lib/gloo/expr/l_decimal.rb +34 -0
- data/lib/gloo/expr/l_integer.rb +5 -4
- data/lib/gloo/expr/l_string.rb +13 -15
- data/lib/gloo/expr/op_div.rb +5 -5
- data/lib/gloo/expr/op_minus.rb +5 -5
- data/lib/gloo/expr/op_mult.rb +5 -5
- data/lib/gloo/expr/op_plus.rb +7 -7
- data/lib/gloo/objs/basic/alias.rb +111 -0
- data/lib/gloo/objs/basic/boolean.rb +63 -38
- data/lib/gloo/objs/basic/container.rb +71 -12
- data/lib/gloo/objs/basic/decimal.rb +96 -0
- data/lib/gloo/objs/basic/integer.rb +45 -16
- data/lib/gloo/objs/basic/script.rb +62 -38
- data/lib/gloo/objs/basic/string.rb +47 -15
- data/lib/gloo/objs/basic/text.rb +69 -21
- data/lib/gloo/objs/basic/untyped.rb +35 -10
- data/lib/gloo/objs/cli/banner.rb +137 -0
- data/lib/gloo/objs/cli/bar.rb +141 -0
- data/lib/gloo/objs/cli/colorize.rb +54 -24
- data/lib/gloo/objs/cli/confirm.rb +63 -29
- data/lib/gloo/objs/cli/menu.rb +236 -0
- data/lib/gloo/objs/cli/menu_item.rb +128 -0
- data/lib/gloo/objs/cli/pastel.rb +120 -0
- data/lib/gloo/objs/cli/prompt.rb +73 -31
- data/lib/gloo/objs/cli/select.rb +153 -0
- data/lib/gloo/objs/ctrl/each.rb +128 -61
- data/lib/gloo/objs/ctrl/repeat.rb +129 -0
- data/lib/gloo/objs/data/markdown.rb +109 -0
- data/lib/gloo/objs/data/table.rb +168 -0
- data/lib/gloo/objs/dev/git.rb +98 -64
- data/lib/gloo/objs/dt/date.rb +72 -0
- data/lib/gloo/objs/dt/datetime.rb +84 -0
- data/lib/gloo/objs/dt/time.rb +72 -0
- data/lib/gloo/objs/ror/erb.rb +82 -41
- data/lib/gloo/objs/ror/eval.rb +73 -31
- data/lib/gloo/objs/snd/play.rb +71 -0
- data/lib/gloo/objs/snd/say.rb +120 -0
- data/lib/gloo/objs/system/file_handle.rb +129 -48
- data/lib/gloo/objs/system/system.rb +84 -38
- data/lib/gloo/objs/web/http_get.rb +103 -46
- data/lib/gloo/objs/web/http_post.rb +70 -44
- data/lib/gloo/objs/web/json.rb +155 -0
- data/lib/gloo/objs/web/slack.rb +89 -58
- data/lib/gloo/objs/web/teams.rb +88 -53
- data/lib/gloo/objs/web/uri.rb +160 -0
- data/lib/gloo/persist/file_loader.rb +95 -85
- data/lib/gloo/persist/file_saver.rb +12 -12
- data/lib/gloo/persist/file_storage.rb +15 -15
- data/lib/gloo/persist/line_splitter.rb +79 -0
- data/lib/gloo/persist/persist_man.rb +63 -39
- data/lib/gloo/utils/words.rb +2 -2
- data/lib/gloo/verbs/alert.rb +67 -16
- data/lib/gloo/verbs/beep.rb +70 -0
- data/lib/gloo/verbs/cls.rb +67 -0
- data/lib/gloo/verbs/context.rb +61 -21
- data/lib/gloo/verbs/create.rb +52 -21
- data/lib/gloo/verbs/help.rb +186 -27
- data/lib/gloo/verbs/if.rb +55 -21
- data/lib/gloo/verbs/list.rb +55 -24
- data/lib/gloo/verbs/load.rb +47 -12
- data/lib/gloo/verbs/move.rb +128 -0
- data/lib/gloo/verbs/put.rb +90 -34
- data/lib/gloo/verbs/quit.rb +43 -12
- data/lib/gloo/verbs/run.rb +63 -18
- data/lib/gloo/verbs/save.rb +45 -10
- data/lib/gloo/verbs/show.rb +56 -22
- data/lib/gloo/verbs/tell.rb +45 -13
- data/lib/gloo/verbs/unless.rb +56 -21
- data/lib/gloo/verbs/version.rb +42 -12
- data/lib/gloo/verbs/wait.rb +73 -0
- data/lib/run.rb +5 -5
- metadata +90 -12
data/lib/gloo/app/engine.rb
CHANGED
|
@@ -15,24 +15,24 @@ module Gloo
|
|
|
15
15
|
attr_reader :args, :mode, :running
|
|
16
16
|
attr_reader :dictionary, :parser, :heap, :factory
|
|
17
17
|
attr_accessor :last_cmd, :persist_man, :event_manager
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
# Set up the engine with basic elements.
|
|
20
20
|
def initialize( params = [] )
|
|
21
21
|
$engine = self
|
|
22
22
|
@args = Args.new( params )
|
|
23
23
|
$settings = Settings.new( ENV[ 'GLOO_ENV' ] )
|
|
24
24
|
$log = Log.new( @args.quiet? )
|
|
25
|
-
|
|
26
|
-
$log.debug
|
|
25
|
+
$prompt = TTY::Prompt.new
|
|
26
|
+
$log.debug 'engine intialized...'
|
|
27
27
|
end
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
# Start the engine.
|
|
30
30
|
def start
|
|
31
|
-
$log.debug
|
|
31
|
+
$log.debug 'starting the engine...'
|
|
32
32
|
$log.debug Info.display_title
|
|
33
33
|
@mode = @args.detect_mode
|
|
34
34
|
@running = true
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
@dictionary = Gloo::Core::Dictionary.instance
|
|
37
37
|
@dictionary.init
|
|
38
38
|
@parser = Gloo::Core::Parser.new
|
|
@@ -40,10 +40,14 @@ module Gloo
|
|
|
40
40
|
@factory = Gloo::Core::Factory.new
|
|
41
41
|
@persist_man = Gloo::Persist::PersistMan.new
|
|
42
42
|
@event_manager = Gloo::Core::EventManager.new
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
run_mode
|
|
45
45
|
end
|
|
46
|
-
|
|
46
|
+
|
|
47
|
+
# ---------------------------------------------------------------------
|
|
48
|
+
# Run
|
|
49
|
+
# ---------------------------------------------------------------------
|
|
50
|
+
|
|
47
51
|
# Run the selected mode.
|
|
48
52
|
def run_mode
|
|
49
53
|
if @mode == Mode::VERSION
|
|
@@ -56,14 +60,14 @@ module Gloo
|
|
|
56
60
|
run
|
|
57
61
|
end
|
|
58
62
|
end
|
|
59
|
-
|
|
63
|
+
|
|
60
64
|
# Run files specified on the CLI.
|
|
61
65
|
# Then quit.
|
|
62
66
|
def run_files
|
|
63
67
|
@args.files.each do |f|
|
|
64
68
|
@persist_man.load( f )
|
|
65
69
|
end
|
|
66
|
-
|
|
70
|
+
|
|
67
71
|
quit
|
|
68
72
|
end
|
|
69
73
|
|
|
@@ -71,17 +75,17 @@ module Gloo
|
|
|
71
75
|
def run
|
|
72
76
|
# Open default files
|
|
73
77
|
self.open_start_file
|
|
74
|
-
|
|
78
|
+
|
|
75
79
|
# TODO: open any files specifed in args
|
|
76
|
-
|
|
80
|
+
|
|
77
81
|
unless @mode == Mode::SCRIPT || @args.quiet?
|
|
78
82
|
@cursor = TTY::Cursor
|
|
79
|
-
self.loop
|
|
83
|
+
self.loop
|
|
80
84
|
end
|
|
81
85
|
|
|
82
86
|
quit
|
|
83
87
|
end
|
|
84
|
-
|
|
88
|
+
|
|
85
89
|
# Get the setting for the start_with file and open it.
|
|
86
90
|
def open_start_file
|
|
87
91
|
name = $settings.start_with
|
|
@@ -94,9 +98,9 @@ module Gloo
|
|
|
94
98
|
d = dt.strftime( '%Y.%m.%d' )
|
|
95
99
|
t = dt.strftime( '%I:%M:%S' )
|
|
96
100
|
|
|
97
|
-
@last_cmd = $prompt.ask( "#{d.yellow} #{t.white} >" )
|
|
101
|
+
@last_cmd = $prompt.ask( "#{'gloo'.blue} #{d.yellow} #{t.white} >" )
|
|
98
102
|
end
|
|
99
|
-
|
|
103
|
+
|
|
100
104
|
# Is the last command entered blank?
|
|
101
105
|
def last_cmd_blank?
|
|
102
106
|
return true if @last_cmd.nil?
|
|
@@ -110,28 +114,31 @@ module Gloo
|
|
|
110
114
|
process_cmd
|
|
111
115
|
end
|
|
112
116
|
end
|
|
113
|
-
|
|
117
|
+
|
|
114
118
|
# Process the command.
|
|
115
119
|
def process_cmd
|
|
116
120
|
if last_cmd_blank?
|
|
117
121
|
clear_screen
|
|
118
122
|
return
|
|
119
123
|
end
|
|
120
|
-
|
|
121
|
-
@
|
|
122
|
-
@immediate.run if @immediate
|
|
124
|
+
|
|
125
|
+
@parser.run @last_cmd
|
|
123
126
|
end
|
|
124
127
|
|
|
125
128
|
# Request the engine to stop running.
|
|
126
129
|
def stop_running
|
|
127
130
|
@running = false
|
|
128
131
|
end
|
|
129
|
-
|
|
132
|
+
|
|
130
133
|
# Do any clean up and quit.
|
|
131
134
|
def quit
|
|
132
|
-
$log.debug
|
|
135
|
+
$log.debug 'quitting...'
|
|
133
136
|
end
|
|
134
|
-
|
|
137
|
+
|
|
138
|
+
# ---------------------------------------------------------------------
|
|
139
|
+
# Helpers
|
|
140
|
+
# ---------------------------------------------------------------------
|
|
141
|
+
|
|
135
142
|
# Show the version information and then quit.
|
|
136
143
|
def run_version
|
|
137
144
|
puts Info.display_title unless @args.quiet?
|
|
@@ -139,20 +146,63 @@ module Gloo
|
|
|
139
146
|
end
|
|
140
147
|
|
|
141
148
|
# Show the help information and then quit.
|
|
142
|
-
def run_help keep_running=false
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
def run_help( keep_running = false )
|
|
150
|
+
out = "#{Info.display_title}\n"
|
|
151
|
+
out << Help.get_help_text
|
|
152
|
+
$engine.heap.it.set_to out
|
|
153
|
+
puts out unless @args.quiet?
|
|
147
154
|
quit unless keep_running
|
|
148
155
|
end
|
|
149
|
-
|
|
156
|
+
|
|
150
157
|
# Clear the screen.
|
|
151
158
|
def clear_screen
|
|
159
|
+
@cursor ||= TTY::Cursor
|
|
152
160
|
print @cursor.clear_screen
|
|
153
161
|
print @cursor.move_to( 0, 0 )
|
|
154
162
|
end
|
|
155
|
-
|
|
163
|
+
|
|
164
|
+
# ---------------------------------------------------------------------
|
|
165
|
+
# Error Handling
|
|
166
|
+
# ---------------------------------------------------------------------
|
|
167
|
+
|
|
168
|
+
#
|
|
169
|
+
# Did the last command result in an error?
|
|
170
|
+
#
|
|
171
|
+
def error?
|
|
172
|
+
return !@heap.error.value.nil?
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
#
|
|
176
|
+
# Report an error.
|
|
177
|
+
# Write it to the log and set the heap error value.
|
|
178
|
+
#
|
|
179
|
+
def err( msg )
|
|
180
|
+
$log.error msg
|
|
181
|
+
self.heap.error.set_to msg
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# ---------------------------------------------------------------------
|
|
185
|
+
# Convert
|
|
186
|
+
# ---------------------------------------------------------------------
|
|
187
|
+
|
|
188
|
+
#
|
|
189
|
+
# Convert the given value to the specified type,
|
|
190
|
+
# or if no conversion is available, revert to default.
|
|
191
|
+
#
|
|
192
|
+
def convert( value, to_type, default = nil )
|
|
193
|
+
begin
|
|
194
|
+
name = "Gloo::Convert::#{value.class}To#{to_type}"
|
|
195
|
+
clazz = name.split( '::' ).inject( Object ) { |o, c| o.const_get c }
|
|
196
|
+
o = clazz.new
|
|
197
|
+
return o.convert( value )
|
|
198
|
+
rescue => e
|
|
199
|
+
$log.error e.message
|
|
200
|
+
$engine.heap.error.set_to e.message
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
return default
|
|
204
|
+
end
|
|
205
|
+
|
|
156
206
|
end
|
|
157
207
|
end
|
|
158
208
|
end
|
data/lib/gloo/app/help.rb
CHANGED
|
@@ -11,19 +11,25 @@ module Gloo
|
|
|
11
11
|
# Get text to display when the application is run
|
|
12
12
|
# in HELP mode.
|
|
13
13
|
def self.get_help_text
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
return <<~TEXT
|
|
15
|
+
NAME
|
|
16
|
+
\tgloo
|
|
17
|
+
|
|
18
|
+
DESCRIPTION
|
|
19
|
+
\tGloo scripting language. A scripting language built on ruby.
|
|
20
|
+
\tMore information coming soon.
|
|
21
|
+
|
|
22
|
+
SYNOPSIS
|
|
23
|
+
\tgloo [global option] [file]
|
|
24
|
+
|
|
25
|
+
GLOBAL OPTIONS
|
|
26
|
+
\t--cli \t\t - Run in CLI mode
|
|
27
|
+
\t--version \t - Show application version
|
|
28
|
+
\t--help \t\t - Show this help page
|
|
29
|
+
|
|
30
|
+
TEXT
|
|
24
31
|
end
|
|
25
32
|
|
|
26
33
|
end
|
|
27
34
|
end
|
|
28
35
|
end
|
|
29
|
-
|
data/lib/gloo/app/info.rb
CHANGED
|
@@ -8,9 +8,10 @@ module Gloo
|
|
|
8
8
|
module App
|
|
9
9
|
class Info
|
|
10
10
|
|
|
11
|
-
VERSION =
|
|
12
|
-
APP_NAME =
|
|
11
|
+
VERSION = '0.5.3'.freeze
|
|
12
|
+
APP_NAME = 'Gloo'.freeze
|
|
13
13
|
|
|
14
|
+
# Get the application display title.
|
|
14
15
|
def self.display_title
|
|
15
16
|
return "#{APP_NAME}, version #{VERSION}"
|
|
16
17
|
end
|
|
@@ -18,4 +19,3 @@ module Gloo
|
|
|
18
19
|
end
|
|
19
20
|
end
|
|
20
21
|
end
|
|
21
|
-
|
data/lib/gloo/app/log.rb
CHANGED
|
@@ -12,46 +12,46 @@ module Gloo
|
|
|
12
12
|
class Log
|
|
13
13
|
|
|
14
14
|
attr_reader :logger, :quiet
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
def initialize( quiet )
|
|
17
|
-
f = File.join( $settings.log_path,
|
|
17
|
+
f = File.join( $settings.log_path, 'gloo.log' )
|
|
18
18
|
@logger = Logger.new( f )
|
|
19
19
|
@logger.level = Logger::DEBUG
|
|
20
20
|
@quiet = quiet
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
# Show a message unless we're in quite mode.
|
|
24
|
-
def show msg
|
|
24
|
+
def show( msg )
|
|
25
25
|
puts msg unless @quiet
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
def debug msg
|
|
27
|
+
|
|
28
|
+
def debug( msg )
|
|
29
29
|
@logger.debug msg
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def info msg
|
|
32
|
+
def info( msg )
|
|
33
33
|
@logger.info msg
|
|
34
34
|
puts msg.blue unless @quiet
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
def warn msg
|
|
37
|
+
def warn( msg )
|
|
38
38
|
@logger.warn msg
|
|
39
39
|
puts msg.yellow unless @quiet
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
def error msg,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@logger.error
|
|
42
|
+
def error( msg, ex = nil, engine = nil )
|
|
43
|
+
engine&.heap&.error&.set_to msg
|
|
44
|
+
@logger.error msg
|
|
45
|
+
if ex
|
|
46
|
+
@logger.error ex.message
|
|
47
|
+
@logger.error ex.backtrace
|
|
47
48
|
puts msg.red unless @quiet
|
|
48
|
-
puts
|
|
49
|
-
puts
|
|
49
|
+
puts ex.message.red unless @quiet
|
|
50
|
+
puts ex.backtrace unless @quiet
|
|
50
51
|
else
|
|
51
|
-
@logger.error msg
|
|
52
52
|
puts msg.red unless @quiet
|
|
53
53
|
end
|
|
54
|
-
end
|
|
54
|
+
end
|
|
55
55
|
|
|
56
56
|
end
|
|
57
57
|
end
|
data/lib/gloo/app/mode.rb
CHANGED
|
@@ -7,19 +7,19 @@
|
|
|
7
7
|
module Gloo
|
|
8
8
|
module App
|
|
9
9
|
class Mode
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
EMBED = :embed # Run as embedded script processor
|
|
12
12
|
CLI = :cli # Run in interactive (CLI) mode
|
|
13
13
|
SCRIPT = :script # Run a script
|
|
14
14
|
VERSION = :version # Show version information
|
|
15
15
|
HELP = :help # Show the help screen
|
|
16
16
|
TEST = :test # Running in Unit Test mode.
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
# Get the default mode.
|
|
19
19
|
def self.default_mode
|
|
20
20
|
return EMBED
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
|
-
end
|
|
25
|
+
end
|
data/lib/gloo/app/settings.rb
CHANGED
|
@@ -13,92 +13,102 @@ module Gloo
|
|
|
13
13
|
class Settings
|
|
14
14
|
|
|
15
15
|
attr_reader :user_root, :log_path, :config_path, :project_path
|
|
16
|
-
attr_reader :start_with, :list_indent
|
|
17
|
-
|
|
16
|
+
attr_reader :start_with, :list_indent, :tmp_path
|
|
18
17
|
|
|
19
18
|
# Load setting from the yml file.
|
|
20
|
-
def initialize mode
|
|
19
|
+
def initialize( mode )
|
|
21
20
|
@mode = mode
|
|
22
21
|
init_root
|
|
23
22
|
init_path_settings
|
|
24
23
|
init_user_settings
|
|
25
24
|
end
|
|
26
|
-
|
|
25
|
+
|
|
27
26
|
def init_root
|
|
28
27
|
if in_test_mode?
|
|
29
28
|
path = File.dirname( File.dirname( File.absolute_path( __FILE__ ) ) )
|
|
30
29
|
path = File.dirname( File.dirname( path ) )
|
|
31
|
-
path = File.join( path,
|
|
30
|
+
path = File.join( path, 'test', 'gloo' )
|
|
32
31
|
@user_root = path
|
|
33
32
|
else
|
|
34
|
-
@user_root = File.join( Dir.home,
|
|
33
|
+
@user_root = File.join( Dir.home, 'gloo' )
|
|
35
34
|
end
|
|
36
35
|
end
|
|
37
|
-
|
|
36
|
+
|
|
38
37
|
# Are we in test mode?
|
|
39
38
|
def in_test_mode?
|
|
40
39
|
return @mode == 'TEST'
|
|
41
40
|
end
|
|
42
41
|
|
|
42
|
+
# Get the project path for the current mode.
|
|
43
|
+
def project_path_for_mode( settings )
|
|
44
|
+
return File.join( @user_root, 'projects' ) if in_test_mode?
|
|
45
|
+
|
|
46
|
+
return settings[ 'gloo' ][ 'project_path' ]
|
|
47
|
+
end
|
|
48
|
+
|
|
43
49
|
# Get the app's required directories.
|
|
44
50
|
def init_path_settings
|
|
45
|
-
Dir.mkdir( @user_root ) unless File.
|
|
51
|
+
Dir.mkdir( @user_root ) unless File.exist?( @user_root )
|
|
46
52
|
|
|
47
|
-
@log_path = File.join( @user_root,
|
|
48
|
-
Dir.mkdir( @log_path ) unless File.
|
|
53
|
+
@log_path = File.join( @user_root, 'logs' )
|
|
54
|
+
Dir.mkdir( @log_path ) unless File.exist?( @log_path )
|
|
49
55
|
|
|
50
|
-
@config_path = File.join( @user_root,
|
|
51
|
-
Dir.mkdir( @config_path ) unless File.
|
|
56
|
+
@config_path = File.join( @user_root, 'config' )
|
|
57
|
+
Dir.mkdir( @config_path ) unless File.exist?( @config_path )
|
|
58
|
+
|
|
59
|
+
@tmp_path = File.join( @user_root, 'tmp' )
|
|
60
|
+
Dir.mkdir( @tmp_path ) unless File.exist?( @tmp_path )
|
|
52
61
|
end
|
|
53
62
|
|
|
63
|
+
# Initialize the user settings for the currently
|
|
64
|
+
# running environment.
|
|
54
65
|
def init_user_settings
|
|
55
66
|
settings = get_settings
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
@project_path = File.join( @user_root, "projects" )
|
|
59
|
-
else
|
|
60
|
-
@project_path = settings[ 'gloo' ][ 'project_path' ]
|
|
61
|
-
end
|
|
67
|
+
|
|
68
|
+
@project_path = project_path_for_mode settings
|
|
62
69
|
@start_with = settings[ 'gloo' ][ 'start_with' ]
|
|
63
70
|
@list_indent = settings[ 'gloo' ][ 'list_indent' ]
|
|
64
71
|
end
|
|
65
|
-
|
|
72
|
+
|
|
66
73
|
# Get the app's required directories.
|
|
67
74
|
def get_settings
|
|
68
|
-
f = File.join( @config_path,
|
|
69
|
-
create_settings( f ) unless File.
|
|
70
|
-
return YAML
|
|
75
|
+
f = File.join( @config_path, 'gloo.yml' )
|
|
76
|
+
create_settings( f ) unless File.exist?( f )
|
|
77
|
+
return YAML.load_file f
|
|
71
78
|
end
|
|
72
79
|
|
|
73
80
|
# Create settings file.
|
|
74
|
-
def create_settings
|
|
75
|
-
IO.write(
|
|
81
|
+
def create_settings( file )
|
|
82
|
+
IO.write( file, get_default_settings )
|
|
76
83
|
end
|
|
77
84
|
|
|
78
85
|
# Get the value for default settings.
|
|
79
86
|
def get_default_settings
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
TEXT
|
|
87
|
+
projects = File.join( @user_root, 'projects' )
|
|
88
|
+
str = <<~TEXT
|
|
89
|
+
gloo:
|
|
90
|
+
project_path: #{projects}
|
|
91
|
+
start_with:
|
|
92
|
+
list_indent: 1
|
|
93
|
+
TEXT
|
|
88
94
|
return str
|
|
89
95
|
end
|
|
90
96
|
|
|
97
|
+
#
|
|
91
98
|
# Show the current application settings.
|
|
99
|
+
# Can be seen in app with 'help settings'
|
|
100
|
+
#
|
|
92
101
|
def show
|
|
93
102
|
puts "\nApplication Settings:".blue
|
|
94
|
-
puts
|
|
95
|
-
puts
|
|
96
|
-
puts
|
|
97
|
-
puts
|
|
98
|
-
puts
|
|
99
|
-
puts
|
|
100
|
-
puts
|
|
101
|
-
puts
|
|
103
|
+
puts ' User Root Path is here: '.yellow + @user_root.white
|
|
104
|
+
puts ' Projects directory: '.yellow + @project_path.white
|
|
105
|
+
puts ' Tmp directory: '.yellow + @tmp_path.white
|
|
106
|
+
puts ' Startup with: '.yellow + @start_with.white
|
|
107
|
+
puts ' Indent in Listing: '.yellow + @list_indent.to_s.white
|
|
108
|
+
puts ''
|
|
109
|
+
puts ' Screen Lines: '.yellow + Gloo::App::Settings.lines.to_s.white
|
|
110
|
+
puts ' Page Size: '.yellow + Gloo::App::Settings.page_size.to_s.white
|
|
111
|
+
puts ''
|
|
102
112
|
end
|
|
103
113
|
|
|
104
114
|
# Get the number of lines on screen.
|
|
@@ -122,4 +132,4 @@ TEXT
|
|
|
122
132
|
|
|
123
133
|
end
|
|
124
134
|
end
|
|
125
|
-
end
|
|
135
|
+
end
|