aro 0.1.8 → 0.1.9

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.
@@ -13,11 +13,16 @@ require :aro.to_s
13
13
  module Aos
14
14
  module Vi
15
15
  class Base
16
- BAR = :|.to_s
16
+ BAR = :"|".to_s
17
17
  MARGIN_V = Aro::Mancy::S
18
18
  MARGIN_H = Aro::Mancy::S
19
19
 
20
20
  def self.show(model)
21
+ unless Aro::Mancy.game.nil?
22
+ Aro::Mancy.game.show
23
+ return
24
+ end
25
+
21
26
  # default view
22
27
  draw([self.name], model)
23
28
  end
@@ -28,7 +33,6 @@ module Aos
28
33
  dc = CLI::Config.display_config
29
34
  height = dc[:HEIGHT]
30
35
  width = dc[:WIDTH]
31
- divider = dc[:DIVIDER] * width
32
36
 
33
37
  # lines printed
34
38
  printed = Aro::Mancy::O
@@ -37,21 +41,30 @@ module Aos
37
41
  # vertical margins
38
42
  max_lines = height - Aos::Vi::Base::MARGIN_V * Aro::Mancy::OS
39
43
  # footer
40
- max_lines = max_lines - Aro::Mancy::OS
44
+ max_lines = max_lines + Aro::Mancy::S
41
45
 
42
46
  # header
43
47
  Aro::Mancy::S.times do |i|
44
- printed += Aro::Mancy::S
45
- Aos::S.say(divider)
48
+ printed += Aro::Mancy::OS
49
+ Aos::S.say("".center(width, dc[:DIVIDER]))
50
+ printed += Aro::Mancy::OS
51
+ Aos::S.say("".center(width))
52
+ Aos::S.say("\n")
46
53
  end
47
54
 
48
- t_divider = dc[:DIVIDER] * ((width - self.name.length) / Aro::Mancy::OS)
55
+ half = ((width - self.name.length) / Aro::Mancy::OS.to_f).ceil
56
+ domain = Aro::Dom.in_arodom? ? Aro::Dom::domain : Aro::Mancy.domain
57
+ clock = Time.now.strftime(Aos::Os::DATE_FORMAT)
49
58
  printed += Aro::Mancy::S
50
- Aos::S.say((t_divider + self.name.to_s.upcase).ljust(width, dc[:DIVIDER]))
59
+ Aos::S.say(
60
+ (
61
+ domain.ljust(half) + self.name.to_s.upcase
62
+ ).ljust(width - clock.length) + clock
63
+ )
51
64
 
52
65
  Aro::Mancy::S.times do
53
66
  printed += Aro::Mancy::S
54
- Aos::S.say(divider)
67
+ Aos::S.say("".center(width, dc[:DIVIDER]))
55
68
  end
56
69
 
57
70
  # top vertical margin
@@ -60,7 +73,7 @@ module Aos
60
73
  print_regular_line("")
61
74
  end
62
75
 
63
- # print lines
76
+ # yield => print lines
64
77
  lines.each{|line|
65
78
  next if printed == max_lines
66
79
 
@@ -77,18 +90,21 @@ module Aos
77
90
  # bottom vertical margin
78
91
  Aos::Vi::Base::MARGIN_V.times do
79
92
  printed += Aro::Mancy::S
80
- print_regular_line("")
93
+ Aos::S.say("[#{Aos::Os} v#{Aro::VERSION.to_s}]".center(width, :"-".to_s))
81
94
  end
82
95
 
83
96
  # footer
84
- if you.nil?
85
- Aos::S.say("")
86
- Aos::S.say("")
87
- else
88
- Aos::S.say(divider[Aro::Mancy::O..width - Aro::Mancy::S])
89
- Aos::S.say("#{Aos::Os}_v#{Aro::VERSION}_#{Aro::Dom}: /#{Aos::Os::osify(you.pwd)}")
90
- end
91
-
97
+ dimension = (Aro::T.is_dev_tarot? ? Aro::T::DEV_TAROT : Aro::T::RUBY_FACOT)
98
+ dt = Aro::T.read_dev_tarot.strip[Aro::Mancy::S..]
99
+ display_dim = "#{dt.rjust(Aro::Mancy::V)} :<[#{dimension}]<"
100
+ Aos::S.say(
101
+ (
102
+ ">#{domain}>#{Aos::Os::osify(you&.pwd || Dir.pwd)}"
103
+ ).ljust(width - display_dim.length) + display_dim
104
+ )
105
+ Aos::S.say("".center(width, dc[:DIVIDER]))
106
+
107
+ # debug logging
92
108
  Aro::D.say("invalid printed height: #{height}, printed: #{printed}") if printed != height
93
109
 
94
110
  # explicitly return true
data/sys/aos/views/dom.rb CHANGED
@@ -27,17 +27,8 @@ module Aos
27
27
  lines << ""
28
28
  lines << I18n.t("aos.views.dom.quick_navigation")
29
29
  lines << ""
30
- just = Aro::Mancy::NUMERALS[:XI]
31
- converter = Proc.new{|layout|
32
- "#{layout[:name].to_s.ljust(just)} #{layout[:rooms].map{|r| r[:name].to_s.ljust(just)}.join(" ")}"
33
- }
34
- lines << converter.call(Aro::Dom::D::LAYOUT[:WELCOME])
35
- lines << ""
36
- lines << converter.call(Aro::Dom::D::LAYOUT[:GAMES])
37
- lines << ""
38
- lines << converter.call(Aro::Dom::D::LAYOUT[:KNOW])
30
+ lines << " => #{Aro::Dom::D.reserved_words.join(" ")}"
39
31
  lines << ""
40
- lines << converter.call(Aro::Dom::D::LAYOUT[:SETUP])
41
32
  draw(lines, model)
42
33
  end
43
34
  end
@@ -8,15 +8,105 @@
8
8
 
9
9
  =end
10
10
 
11
+ require_relative :"../../../models/deck".to_s
11
12
  require_relative :"../base".to_s
12
13
 
13
14
  module Aos
14
15
  module Vi
15
16
  class Game < Aos::Vi::Base
17
+
18
+ DECK_PARAMS = [
19
+ :deck,
20
+ :h_logs,
21
+ :count_n,
22
+ :order_o,
23
+ ]
24
+
16
25
  def self.show(model)
26
+ unless Aro::Mancy.game.nil?
27
+ Aro::Mancy.game.show
28
+ return
29
+ end
30
+
17
31
  lines = []
18
32
  lines << I18n.t("aos.views.game.title").center(viewport_width)
19
33
  lines << I18n.t("aos.views.game.description").center(viewport_width)
34
+
35
+ room_def = Aro::Dom::D::WINGS[:GAMES].values.filter{|gr|
36
+ "#{Aos::Vi.name}::#{gr[:name].to_s.downcase.capitalize}" == self.name
37
+ }.first
38
+ unless room_def.nil?
39
+ lines << I18n.t("aos.views.game.is_the", name: room_def[:name].to_s)
40
+ lines << I18n.t("aos.views.game.designed_for", description: room_def[:description])
41
+ end
42
+
43
+ draw(lines, model)
44
+ end
45
+
46
+ def self.show_game(model)
47
+ mk = model.keys
48
+ dp = Aos::Vi::Game::DECK_PARAMS
49
+ return nil unless (mk & dp).count == dp.count
50
+ return nil unless model.values.all?{|v| v != nil}
51
+
52
+ deck = model[:deck]
53
+ h_logs = model[:h_logs]
54
+ count_n = model[:count_n]
55
+ order_o = model[:order_o]
56
+
57
+ dc = CLI::Config.display_config
58
+ width = dc[:WIDTH] = viewport_width
59
+ divider = dc[:DIVIDER] * viewport_width
60
+ lines = []
61
+ lines << "#{deck.name.upcase.center(width)}"
62
+ h_logs.each_with_index{|l, i|
63
+ lines << divider
64
+ lines << ""
65
+ timestamp = l.created_at.strftime(CLI::Config::DATE_FORMAT)
66
+ of_text = "#{order_o.to_sym == Aro::Log::ORDERING[:DESC] ? deck.logs.count - i : 1 + i} of #{deck.logs.count}"
67
+ lines << of_text.ljust(width - timestamp.length) + timestamp
68
+ lines << divider
69
+ cards = Base64::decode64(l.card_data).split(Aro::Deck::CARD_DELIM.to_s)
70
+ if !cards.nil? && cards.any?
71
+ lines << ""
72
+ lines += self.get_display_for_cards(cards)
73
+ lines << divider
74
+ end
75
+
76
+ drawn_cards = Base64::decode64(l.drawn_data).split(Aro::Deck::CARD_DELIM.to_s)
77
+ if !drawn_cards.nil? && drawn_cards.any?
78
+ lines << ""
79
+ lines << I18n.t("cli.messages.history_drawn").center(width)
80
+ lines << divider
81
+ lines << ""
82
+ lines += self.get_display_for_cards(
83
+ drawn_cards
84
+ )
85
+ lines << ""
86
+ lines << divider
87
+ end
88
+ }
89
+ if count_n == Aro::Mancy::S
90
+ draw(lines)
91
+ else
92
+ Aro::P.less(lines.join("\n"))
93
+ end
94
+ end
95
+
96
+ def self.get_display_for_cards(input = [])
97
+ columns = CLI::Config.display_config[:COLUMNS].to_i
98
+ lines = []
99
+ return lines unless input.any?
100
+ card_line = ""
101
+ input.each_with_index{|c, i|
102
+ s = (i + Aro::Mancy::S) % [Aro::Mancy::S, columns].max
103
+ card_line += c.ljust(columns)
104
+ if Aro::Mancy::O == s || i == input.count - Aro::Mancy::S
105
+ lines << card_line
106
+ card_line = ""
107
+ end
108
+ }
109
+ lines << ""
20
110
  lines
21
111
  end
22
112
  end
@@ -15,27 +15,14 @@ module Aos
15
15
  class Settings < Aos::Vi::Base
16
16
  def self.show(model)
17
17
  just_access = Aro::Mancy::NUMERALS[:VI]
18
- just_key = Aro::Mancy::NUMERALS[:XXI]
18
+ just_key = Aro::Mancy::NUMERALS[:XXII]
19
19
  just_value = Aro::Mancy::NUMERALS[:VI]
20
20
  bullet = ":"
21
21
 
22
22
  # print CLI::Config::DEF
23
23
  lines = []
24
- lines << "CLI::Config::DEF:"
25
- lines << "#{"access".rjust(just_access)}#{bullet} #{"variable_name".ljust(just_key)}=value"
26
- lines << ""
27
- CLI::Config::DEF.each{|k, deff|
28
- val = nil
29
-
30
- if deff[:access] == CLI::Config::DEF_ACCESS[:READ]
31
- val = CLI::Config.ovar(k)
32
- else
33
- val = CLI::Config.ivar(k)
34
- k = CLI::Config.ivar_k(k)
35
- end
36
-
37
- lines << "#{deff[:access].to_s.rjust(just_access)}#{bullet} #{k.to_s.ljust(just_key)}=#{val}"
38
- }
24
+ lines << "<CLI::Config::DEF>"
25
+ lines += CLI::Config.dump_config
39
26
 
40
27
  # print config commands
41
28
  lines << ""
data/sys/aos/you.rb CHANGED
@@ -10,6 +10,10 @@
10
10
 
11
11
  module Aos
12
12
  class You < ActiveRecord::Base
13
+ after_commit :update_aos_pwd
13
14
 
15
+ def update_aos_pwd
16
+ Dir.chdir(pwd)
17
+ end
14
18
  end
15
19
  end
data/sys/aro/db.rb CHANGED
@@ -17,12 +17,11 @@ module Aro
17
17
 
18
18
  def initialize
19
19
  # ActiveRecord::Base.logger = Logger.new(STDOUT)
20
- unless Aro::Mancy.is_aro_space?
20
+ if Aro::Mancy.in_aro?
21
+ setup_local_aro
22
+ else
21
23
  Aro::P.say(I18n.t("cli.errors.not_in_aro" , cmd: Aro::Mancy::I2097I))
22
- return
23
24
  end
24
-
25
- setup_local_aro
26
25
  end
27
26
 
28
27
  def connect(name)
@@ -43,7 +42,7 @@ module Aro
43
42
  end
44
43
 
45
44
  def setup_local_aro
46
- name = Aro::Mancy.is_aro_space? ? File.read(Aro::Mancy::NAME_FILE.to_s).strip : nil
45
+ name = Aro::Mancy.in_aro? ? Aro::Mancy.aro_mancy_name : nil
47
46
  return if name.nil?
48
47
 
49
48
  # create local .aro/ directory
data/sys/aro/mancy.rb CHANGED
@@ -19,7 +19,8 @@ module Aro
19
19
  OS = 2
20
20
  E = 3
21
21
  N = 4
22
- PS1 = Aro::Mancy.name
22
+ V = 5
23
+ PS1 = :">[#{Aro::Mancy.name}]>: "
23
24
  NAME_FILE = :".name"
24
25
  ARO_FILE = :".aro"
25
26
  I2097I = :i2097i
@@ -59,7 +60,7 @@ module Aro
59
60
  }
60
61
 
61
62
  def initialize
62
- if Aro::Mancy.is_aro_space? && Aro::Mancy.is_initialized?
63
+ if Aro::Mancy.in_aro? && Aro::Mancy.is_initialized?
63
64
  Aro::Mancy.init
64
65
  self.game = Aro::Deck.current_deck
65
66
  end
@@ -70,7 +71,7 @@ module Aro
70
71
  end
71
72
 
72
73
  def self.create(name)
73
- return false if Aro::Mancy.is_aro_space? || name.nil?
74
+ return false if Aro::Mancy.in_aro? || name.nil?
74
75
 
75
76
  # explicitly only allow String/Symbol types for name
76
77
  return false unless name.kind_of?(String) || name.kind_of?(Symbol)
@@ -99,16 +100,22 @@ module Aro
99
100
  Aro::Db.new
100
101
  end
101
102
 
102
- def self.start
103
- Aos.start(:aro)
104
- end
105
-
106
103
  def self.is_initialized?
107
- Dir.exist?(Aro::Db.base_aro_dir)
104
+ !Aro::Db.base_aro_dir.nil? && Dir.exist?(Aro::Db.base_aro_dir)
108
105
  end
109
106
 
110
- def self.is_aro_space?
107
+ def self.in_aro?
111
108
  File.exist?(Aro::Mancy::NAME_FILE.to_s)
112
109
  end
110
+
111
+ def self.domain
112
+ "#{Aro::Mancy}#{Aos::Os::A}#{Aro::Mancy.aro_mancy_name}"
113
+ end
114
+
115
+ def self.aro_mancy_name
116
+ return nil unless Aro::Mancy.in_aro?
117
+
118
+ File.read(Aro::Mancy::NAME_FILE.to_s).strip
119
+ end
113
120
  end
114
121
  end
data/sys/aro/p.rb CHANGED
@@ -14,10 +14,10 @@ require_relative :"./r".to_s
14
14
  module Aro
15
15
  class P < Aro::Prompt
16
16
  def self.say(message)
17
- if !Aro::Dom.in_arodom? && !Aro::T.is_dev_tarot?
17
+ if Aro::Mancy.in_aro? && !Aro::T.is_dev_tarot?
18
18
  Aro::R.say(message)
19
19
  else
20
- Aro::P::p.say(">[#{Aro::Mancy::PS1}]>: #{message}")
20
+ Aro::P::p.say("#{Aro::Mancy::PS1}#{message}")
21
21
  end
22
22
  end
23
23
  end
data/sys/cli/config.rb CHANGED
@@ -12,7 +12,7 @@ module CLI
12
12
 
13
13
  # cli entrypoint
14
14
  def self.config
15
- Aro::D.say("#{__FILE__}:#{__method__} was called (todo)...")
15
+ CLI::Config.process_config_command(ARGV)
16
16
  end
17
17
 
18
18
  class Config
@@ -83,7 +83,7 @@ module CLI
83
83
  name: CLI::Config::TYPES[:BOOL],
84
84
  description: I18n.t("cli.config.type.bool_description"),
85
85
  converter: Proc.new{|v|
86
- if v == CLI::Config::BOOLS[:TRUE].to_s
86
+ if [CLI::Config::BOOLS[:TRUE].to_s, Aro::Mancy::S].include?(v)
87
87
  CLI::Config::BOOLS[:TRUE]
88
88
  else
89
89
  CLI::Config::BOOLS[:FALSE]
@@ -99,14 +99,14 @@ module CLI
99
99
  description: I18n.t("cli.config.type.int_description"),
100
100
  converter: Proc.new{|v| v.to_i},
101
101
  validator: Proc.new{|unvalid, k, v|
102
+ Aro::V.say("validating #{k} (#{CLI::Config::DEF_TYPES[:INT][:name]})")
103
+ Aro::V.say("unvalid = #{unvalid}")
104
+ Aro::V.say("[min, max] = [#{v[:min]}, #{v[:max]}]")
102
105
  int_valid = CLI::Config.def_valid?(k, v) &&
103
106
  CLI::Config.int_valid?(unvalid) &&
104
107
  unvalid.to_i >= v[:min] &&
105
108
  unvalid.to_i <= v[:max]
106
-
107
- Aro::V.say("validating #{k} (#{CLI::Config::DEF_TYPES[:INT][:name]})")
108
- Aro::V.say("unvalid = #{unvalid}")
109
- Aro::V.say("unvalid is#{int_valid ? " " : :" not ".to_s}valid.")
109
+ Aro::V.say("unvalid(#{unvalid}) is#{int_valid ? " " : :" not ".to_s}valid.")
110
110
  int_valid
111
111
  }
112
112
  },
@@ -131,7 +131,7 @@ module CLI
131
131
  }
132
132
 
133
133
  def self.bool_valid?(unvalid)
134
- CLI::Config::BOOLS.include?(unvalid&.to_s&.to_sym)
134
+ CLI::Config::BOOLS.values.map{|b| b.to_s.to_sym}.include?(unvalid&.to_s&.to_sym)
135
135
  end
136
136
 
137
137
  def self.int_valid?(unvalid)
@@ -154,13 +154,20 @@ module CLI
154
154
  def validate_config
155
155
  invalid_vars = []
156
156
  CLI::Config::DEF.each{|k, v|
157
- is_valid = valid_var?(ENV[CLI::Config.ivar_k(k)], k, v)
157
+ Aro::V.say(v[:access])
158
+ is_valid = v[:access] == CLI::Config::DEF_ACCESS[:READ]
159
+ unless is_valid
160
+ is_valid = valid_var?(CLI::Config.ivar(k), k, v)
161
+ end
158
162
  invalid_vars << k unless is_valid
159
163
  }
160
164
  invalid_vars
161
165
  end
162
166
 
163
167
  def valid_var?(var_value, k, v)
168
+ Aro::V.say(v)
169
+ return true if v[:access] == CLI::Config::DEF_ACCESS[:READ]
170
+
164
171
  CLI::Config::DEF_TYPES[
165
172
  v[:type].to_s.upcase.to_sym
166
173
  ][:validator].call(var_value, k, v)
@@ -192,6 +199,12 @@ module CLI
192
199
  test: I18n.t("cli.config.env.test_description"),
193
200
  }
194
201
  },
202
+ VERBOSE: {
203
+ type: CLI::Config::TYPES[:BOOL],
204
+ access: CLI::Config::DEF_ACCESS[:WRITE],
205
+ value: CLI::Config::BOOLS[:FALSE],
206
+ description: I18n.t("cli.config.verbose_description"),
207
+ },
195
208
  FORMAT: { # not implemented yet.
196
209
  type: CLI::Config::TYPES[:VALUES],
197
210
  implemented: false,
@@ -218,7 +231,7 @@ module CLI
218
231
  access: CLI::Config::DEF_ACCESS[:WRITE],
219
232
  value: Aro::Mancy::NUMERALS[:XLII],
220
233
  min: Aro::Mancy::NUMERALS[:I],
221
- max: Aro::Mancy::NUMERALS[:VII].pow(Aro::Mancy::OS),
234
+ max: Aro::Mancy::NUMERALS[:MMXCVII],
222
235
  description: I18n.t(
223
236
  "cli.config.height_description",
224
237
  min: Aro::Mancy::NUMERALS[:I],
@@ -230,7 +243,7 @@ module CLI
230
243
  access: CLI::Config::DEF_ACCESS[:WRITE],
231
244
  value: Aro::Mancy::NUMERALS[:C] + Aro::Mancy::NUMERALS[:XXXVII] - Aro::Mancy::S,
232
245
  min: Aro::Mancy::NUMERALS[:I],
233
- max: Aro::Mancy::NUMERALS[:XI].pow(Aro::Mancy::OS),
246
+ max: Aro::Mancy::NUMERALS[:MMXCVII],
234
247
  description: I18n.t(
235
248
  "cli.config.width_description",
236
249
  min: Aro::Mancy::NUMERALS[:I],
@@ -261,12 +274,6 @@ module CLI
261
274
  max: Aro::Mancy::NUMERALS[:XXII],
262
275
  ),
263
276
  },
264
- VERBOSE: {
265
- type: CLI::Config::TYPES[:BOOL],
266
- access: CLI::Config::DEF_ACCESS[:WRITE],
267
- value: CLI::Config::BOOLS[:FALSE],
268
- description: I18n.t("cli.config.verbose_description"),
269
- },
270
277
 
271
278
  #
272
279
  # => ovars
@@ -335,9 +342,9 @@ module CLI
335
342
 
336
343
  def initialize
337
344
  @@context = nil
338
- if Aro::Mancy.is_aro_space? && Aro::Mancy.is_initialized?
345
+ if Aro::Mancy.in_aro? && Aro::Mancy.is_initialized?
339
346
  @@context = Aro::Mancy.name
340
- elsif Aro::Dom.in_arodom?
347
+ elsif Aro::Dom.in_arodom? && Aro::Dom.is_initialized?
341
348
  @@context = Aro::Dom.name
342
349
  end
343
350
 
@@ -356,21 +363,37 @@ module CLI
356
363
  File.join(db_cls.base_aro_dir, CLI::Config::CONFIG_FILE.to_s)
357
364
  end
358
365
 
366
+ def self.is_test?
367
+ ENV[:ARO_ENV.to_s] == CLI::Config::ENVS[:TEST].to_s
368
+ end
369
+
359
370
  def self.display_config
360
- Aro::V.say(__method__)
371
+ # Aro::V.say(__method__)
361
372
  width = CLI::Config.ivar(:WIDTH).to_i
362
373
  columns = width.pow(Aro::Mancy::S.to_f / Aro::Mancy::OS.to_f).to_i
363
374
  result = {
364
375
  COLUMNS: columns,
365
376
  HEIGHT: CLI::Config.ivar(:HEIGHT).to_i,
366
377
  WIDTH: width,
367
- DIVIDER: :"-".to_s
378
+ DIVIDER: :"_".to_s
368
379
  }
369
- Aro::V.say(result)
380
+ # Aro::V.say(result)
370
381
 
371
382
  result
372
383
  end
373
384
 
385
+ def self.process_config_command(args)
386
+ if args[1].nil? || args[1] == :aos.to_s
387
+ # print config
388
+ Aro::P.say((
389
+ ["config loaded from #{CLI::Config.config_filepath}"] +
390
+ CLI::Config.dump_config
391
+ ).join("\n"))
392
+ elsif [args[2],args[3]].compact.any? && args[1] == Aos::Os::CMDS[:CONFIG][:cmds][:SET][:key].to_s
393
+ CLI::Config.set_ivar(args[2], args[3])
394
+ end
395
+ end
396
+
374
397
  # out vars
375
398
  def self.ovar(suffix)
376
399
  CLI::Config::DEF[suffix][:value]
@@ -389,6 +412,30 @@ module CLI
389
412
  "#{CLI::Config::ARO_CONFIG_PREFIX}#{suffix}"
390
413
  end
391
414
 
415
+ def self.set_ivar(k, new_value)
416
+ k = k.upcase.to_sym
417
+
418
+ current_value = CLI::Config.ivar(k)
419
+ # ensure the var name is valid
420
+ unless current_value.nil?
421
+ Aro::V.say("validating #{k} with value #{new_value}")
422
+ if CLI::Config.instance.valid_var?(new_value, k, CLI::Config::DEF[k])
423
+ # set ENV value
424
+ ENV[CLI::Config.ivar_k(k)] = new_value
425
+ Aro::V.say(ENV[CLI::Config.ivar_k(k)])
426
+
427
+ # flush existing config and regen
428
+ CLI::Config.instance.generate_config(true)
429
+ CLI::Config.instance.source_config
430
+ CLI::Config.instance.setup_env
431
+ else
432
+ Aro::Dom::P.say("the ivar value you entered is invalid. ignoring.")
433
+ end
434
+ else
435
+ Aro::Dom::P.say("the ivar name you entered is invalid. ignoring.")
436
+ end
437
+ end
438
+
392
439
  def setup_env
393
440
  # do not change - update $ARO_CONFIG_ENV .aro/.config file
394
441
  #
@@ -399,8 +446,17 @@ module CLI
399
446
  Aro::D.say("setup_env: #{ENV[:ARO_ENV.to_s]}")
400
447
  end
401
448
 
402
- def self.is_test?
403
- ENV[:ARO_ENV.to_s] == CLI::Config::ENVS[:TEST].to_s
449
+ def self.dump_config
450
+ dump = []
451
+ CLI::Config::DEF.each{|k, v|
452
+ if v[:access] == CLI::Config::DEF_ACCESS[:WRITE]
453
+ dump << "$#{CLI::Config.ivar_k(k).ljust(Aro::Mancy::NUMERALS[:XIV] * Aro::Mancy::OS)}=#{CLI::Config.ivar(k)}"
454
+ else
455
+ dump << "$#{CLI::Config.ovar_k(k).ljust(Aro::Mancy::NUMERALS[:XIV] * Aro::Mancy::OS)}=#{CLI::Config.ovar(k)}"
456
+ end
457
+ }
458
+
459
+ dump
404
460
  end
405
461
 
406
462
  def source_config
@@ -417,17 +473,18 @@ module CLI
417
473
 
418
474
  # todo: implement
419
475
  invalid_defs = validate_config
420
- CLI::Config::DEF.keys.each{|dfk|
421
- Aro::V.say("$#{CLI::Config.ivar_k(dfk)}=#{CLI::Config.ivar(dfk)}")
476
+ CLI::Config.dump_config.each{|l| Aro::V.say(l)}
477
+ invalid_defs.each{|k|
478
+ v = CLI::Config::DEF[k.to_sym]
479
+ if v[:access] == CLI::Config::DEF_ACCESS[:WRITE]
480
+ ENV[CLI::Config.ivar_k(k)] = v[:value]
481
+ else
482
+ ENV[CLI::Config.ovar_k(k)] = v[:value]
483
+ end
422
484
  }
423
- Aro::V.say("todo: invalid_defs: #{invalid_defs}")
424
- # todo: set all invalid_refs to default in ENV
425
- # invalid_defs.each{|id|
426
-
427
- # }
428
485
  end
429
486
 
430
- def generate_config
487
+ def generate_config(from_memory = false)
431
488
  # todo: localize generated config text
432
489
  Aro::D.say(I18n.t("cli.config.generate", name: CLI::Config.config_filepath))
433
490
  File.open(CLI::Config.config_filepath, "w+") do |file|
@@ -464,7 +521,7 @@ module CLI
464
521
 
465
522
  # vars
466
523
  CLI::Config::DEF.each{|k, v|
467
- print_var file.object_id, k, v
524
+ print_var file.object_id, k, v, (from_memory ? ENV[CLI::Config.ivar_k(k)] : nil)
468
525
  }
469
526
 
470
527
  print_osr file.object_id
@@ -535,7 +592,7 @@ module CLI
535
592
  file.write("# => which can be used to write programs on top of aro.\n")
536
593
  end
537
594
 
538
- def print_var f_object_id, k, v
595
+ def print_var f_object_id, k, v, mem_v
539
596
  file = ObjectSpace._id2ref f_object_id
540
597
 
541
598
  is_ovar = CLI::Config::DEF[k][:access] == CLI::Config::DEF_ACCESS[:READ]
@@ -547,7 +604,7 @@ module CLI
547
604
  Aro::V.say("access for #{k} is #{CLI::Config::DEF[k][:access]}")
548
605
  Aro::V.say("using var_name: #{var_name}")
549
606
  file.write("# [#{var_name}] (#{is_ovar ? :ovar : :ivar})\n")
550
- file.write("# => #{I18n.t("cli.config.def_type")}: #{v[:type]}\n")
607
+ file.write("# => CLI::Config::DEF_TYPES: #{v[:type]}\n")
551
608
  case v[:type]
552
609
  when CLI::Config::DEF_TYPES[:INT][:name]
553
610
  file.write("# => #{I18n.t("cli.config.type.int_description")}\n")
@@ -573,7 +630,7 @@ module CLI
573
630
  if is_ovar && CLI::Config::DEF_TYPES[:STRING][:name] == v[:type]
574
631
  file.write("export #{var_name}=\"#{v[:value]}\"\n")
575
632
  else
576
- file.write("export #{var_name}=#{v[:value]}\n")
633
+ file.write("export #{var_name}=#{mem_v || v[:value]}\n")
577
634
  end
578
635
  print_osr f_object_id
579
636
  end
data/sys/cli/constants.rb CHANGED
@@ -18,9 +18,9 @@ module CLI
18
18
  }
19
19
 
20
20
  EXIT_CODES = {
21
- SUCCESS: 0,
22
- GENERAL_ERROR: 1,
23
- INVALID_ARG: 3
21
+ SUCCESS: Aro::Mancy::O,
22
+ GENERAL_ERROR: Aro::Mancy::S,
23
+ INVALID_ARG: Aro::Mancy::E,
24
24
  }
25
25
 
26
26
  CMDS = {