aro 0.2.2 → 0.2.4

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile.lock +1 -1
  4. data/aro.gemspec +9 -9
  5. data/bin/aos +10 -3
  6. data/bin/aro +26 -13
  7. data/checksums/aro-0.2.3.gem.sha512 +1 -0
  8. data/locale/en.abot.yml +81 -0
  9. data/locale/en.amg.yml +7 -7
  10. data/locale/en.aos.yml +11 -7
  11. data/locale/en.cards.yml +361 -312
  12. data/locale/en.cor.yml +47 -0
  13. data/locale/en.data.yml +3 -3
  14. data/locale/en.dom.yml +15 -13
  15. data/locale/en.flie.yml +29 -0
  16. data/locale/en.usage.yml +103 -63
  17. data/locale/en.yml +5 -49
  18. data/sys/aos/abot.rb +255 -0
  19. data/sys/aos/aos.rb +381 -164
  20. data/sys/aos/cor.rb +770 -0
  21. data/sys/aos/data.rb +3 -3
  22. data/sys/aos/db/migrate/1765148774_create_yous.rb +1 -1
  23. data/sys/aos/db/migrate/1765933985_create_agodos.rb +22 -0
  24. data/sys/aos/db/migrate/1766203888_create_fpxies.rb +18 -0
  25. data/sys/aos/db.rb +15 -17
  26. data/sys/aos/flie.rb +144 -0
  27. data/sys/aos/models/agodo.rb +95 -0
  28. data/sys/aos/models/fpxy.rb +26 -0
  29. data/sys/aos/models/ilog.rb +3 -3
  30. data/sys/aos/models/you.rb +56 -4
  31. data/sys/aos/s.rb +2 -1
  32. data/sys/aos/vws/base.rb +64 -25
  33. data/sys/aos/vws/dom.rb +1 -1
  34. data/sys/aos/vws/games/abot.rb +21 -0
  35. data/sys/aos/vws/games/{game.rb → teck.rb} +35 -28
  36. data/sys/aos/vws/home.rb +23 -0
  37. data/sys/aos/vws/root/config.rb +4 -4
  38. data/sys/aos/vws/root/flie.rb +21 -0
  39. data/sys/aos/vws/welcome.rb +40 -4
  40. data/sys/aro/d.rb +4 -2
  41. data/sys/aro/db.rb +16 -9
  42. data/sys/aro/mancy.rb +16 -20
  43. data/sys/aro/models/base_model.rb +13 -0
  44. data/sys/aro/models/teck.rb +40 -23
  45. data/sys/aro/models/tlog.rb +2 -1
  46. data/sys/aro/p.rb +1 -1
  47. data/sys/aro/r.rb +2 -1
  48. data/sys/aro/v.rb +2 -2
  49. data/sys/cli/constants.rb +5 -10
  50. data/sys/cli/create.rb +3 -4
  51. data/sys/cli/dom.rb +3 -4
  52. data/sys/cli/nterface.rb +15 -9
  53. data/sys/cli/teck.rb +29 -38
  54. data/sys/cli/usage.rb +11 -1
  55. data/sys/cli.rb +7 -9
  56. data/sys/dom/d.rb +38 -29
  57. data/sys/dom/dom.rb +62 -37
  58. data/sys/dom/p.rb +1 -1
  59. data/sys/fpx.rb +104 -0
  60. data/sys/reiquire.rb +3 -2
  61. data/sys/shr/prompt.rb +2 -2
  62. data/sys/shr/t.rb +13 -15
  63. data/sys/shr/version.rb +1 -1
  64. data/tasks/make.rake +1 -1
  65. metadata +54 -43
  66. data/sys/aos/vws/games/abpps.rb +0 -19
  67. data/sys/aos/vws/games/hbpps.rb +0 -19
  68. data/sys/aos/vws/games/shpps.rb +0 -19
  69. data/sys/aos/vws/games/vipps.rb +0 -19
  70. data/sys/dom/config.rb +0 -718
data/sys/aos/cor.rb ADDED
@@ -0,0 +1,770 @@
1
+ =begin
2
+
3
+ cor.rb
4
+
5
+ aos cor interface.
6
+
7
+ by i2097i
8
+
9
+ =end
10
+
11
+ module Aos
12
+ # cli entrypoint
13
+ def self.cor
14
+ Aos::Cor.instance.load
15
+ Aos::Cor.process_command(ARGV)
16
+ end
17
+
18
+ class Cor
19
+ include Singleton
20
+
21
+ attr_accessor :base_lines_def, :cor_path, :display_lines
22
+
23
+ ARO_IVA_PREFIX = :ARO_IVA_
24
+ ARO_OVA_PREFIX = :ARO_OVA_
25
+
26
+ COR_FILE = :".cor"
27
+
28
+ DATE_FORMAT = "%Y:%m:%d:%H:%M:%S"
29
+
30
+ DBG_MODES = [:development, :test]
31
+
32
+ # possible envs
33
+ #
34
+ # example usage:
35
+ # Aos::Cor::ENVS[:PRODUCTION]
36
+ ENVS = {
37
+ DEVELOPMENT: :development,
38
+ PRODUCTION: :production,
39
+ TEST: :test
40
+ }
41
+
42
+ # possible formats
43
+ #
44
+ # example usage:
45
+ # Aos::Cor::FORMATS[:TEXT]
46
+ FORMATS = {
47
+ TEXT: :text,
48
+ JSON: :json,
49
+ }
50
+
51
+ # possible interfaces
52
+ #
53
+ # example usage:
54
+ # Aos::Cor::INTERFACES[:TERMINAL]
55
+ INTERFACES = {
56
+ TERMINAL: :terminal,
57
+ LANIMRET: :lanimret,
58
+ }
59
+
60
+ # possible dimensions
61
+ #
62
+ # example usage:
63
+ # Aos::Cor::DMS[:DEV_TAROT]
64
+ DMS = {
65
+ DEV_TAROT: :dev_tarot,
66
+ RUBY_FACOT: :ruby_facot
67
+ }
68
+
69
+ # ovar and ivar access
70
+ #
71
+ # example usage:
72
+ # Aos::Cor::DEF_ACCESS[:READ]
73
+ DEF_ACCESS = {
74
+ READ: :read,
75
+ WRITE: :write
76
+ }
77
+
78
+ BOOLS = {
79
+ FALSE: false,
80
+ TRUE: true,
81
+ }
82
+
83
+ TYPES = {
84
+ BOOL: :bool,
85
+ INT: :int,
86
+ STRING: :string,
87
+ VALUES: :values
88
+ }
89
+
90
+ # types used in definition
91
+ #
92
+ # example usage:
93
+ # Aos::Cor::DEF_TYPES[:INT][:validator].call(unvalid, Aos::Cor::DEF[:DIMENSION])
94
+ DEF_TYPES = {
95
+ BOOL: {
96
+ name: Aos::Cor::TYPES[:BOOL],
97
+ description: I18n.t("cor.type.bool_description"),
98
+ converter: Proc.new{|v|
99
+ if [Aos::Cor::BOOLS[:TRUE].to_s, Aro::Mancy::S].include?(v)
100
+ Aos::Cor::BOOLS[:TRUE]
101
+ else
102
+ Aos::Cor::BOOLS[:FALSE]
103
+ end
104
+ },
105
+ validator: Proc.new{|unvalid, k, v|
106
+ Aos::Cor.def_valid?(k, v) &&
107
+ Aos::Cor.bool_valid?(unvalid)
108
+ }
109
+ },
110
+ INT: {
111
+ name: Aos::Cor::TYPES[:INT],
112
+ description: I18n.t("cor.type.int_description"),
113
+ converter: Proc.new{|v| v.to_i},
114
+ validator: Proc.new{|unvalid, k, v|
115
+ Aro::V.say("validating #{k} (#{Aos::Cor::DEF_TYPES[:INT][:name]})")
116
+ Aro::V.say("unvalid = #{unvalid}")
117
+ Aro::V.say("[min, max] = [#{v[:min]}, #{v[:max]}]")
118
+ int_valid = Aos::Cor.def_valid?(k, v) &&
119
+ Aos::Cor.int_valid?(unvalid) &&
120
+ unvalid.to_i >= v[:min] &&
121
+ unvalid.to_i <= v[:max]
122
+ Aro::V.say("unvalid(#{unvalid}) is#{int_valid ? " " : :" not ".to_s}valid.")
123
+ int_valid
124
+ }
125
+ },
126
+ STRING: {
127
+ name: Aos::Cor::TYPES[:STRING],
128
+ description: I18n.t("cor.type.string_description"),
129
+ converter: Proc.new{|v| v.to_s},
130
+ validator: Proc.new{|unvalid, k, v|
131
+ Aos::Cor.def_valid?(k, v) &&
132
+ Aos::Cor.string_valid?(unvalid)
133
+ }
134
+ },
135
+ VALUES: {
136
+ name: Aos::Cor::TYPES[:VALUES],
137
+ description: I18n.t("cor.type.values_description"),
138
+ converter: Proc.new{|v| v.to_s},
139
+ validator: Proc.new{|unvalid, k, v|
140
+ Aos::Cor.def_valid?(k, v) &&
141
+ v[:possible_values].keys.include?(unvalid&.to_sym)
142
+ }
143
+ },
144
+ }
145
+
146
+ def self.bool_valid?(unvalid)
147
+ Aos::Cor::BOOLS.values.map{|b| b.to_s.to_sym}.include?(unvalid&.to_s&.to_sym)
148
+ end
149
+
150
+ def self.int_valid?(unvalid)
151
+ !unvalid&.to_i.nil?
152
+ end
153
+
154
+ def self.string_valid?(unvalid)
155
+ unvalid.is_a?(String)
156
+ end
157
+
158
+ def self.def_valid?(key, deff)
159
+ def_valid = deff == Aos::Cor::DEF[key]
160
+ unless def_valid
161
+ Aro::V.say("invalid def! #{key} => #{deff}")
162
+ end
163
+
164
+ def_valid
165
+ end
166
+
167
+ def validate_config
168
+ invalid_vars = []
169
+ Aos::Cor::DEF.each{|k, v|
170
+ is_valid = v[:access] == Aos::Cor::DEF_ACCESS[:READ]
171
+ unless is_valid
172
+ is_valid = valid_var?(Aos::Cor.ivar(k), k, v)
173
+ end
174
+ invalid_vars << k unless is_valid
175
+ }
176
+ invalid_vars
177
+ end
178
+
179
+ def valid_var?(var_value, k, v)
180
+ Aro::V.say(v)
181
+ return true if v[:access] == Aos::Cor::DEF_ACCESS[:READ]
182
+
183
+ Aos::Cor::DEF_TYPES[
184
+ v[:type].to_s.upcase.to_sym
185
+ ][:validator].call(var_value, k, v)
186
+ end
187
+
188
+ def convert_var_for_def(k)
189
+ Aos::Cor::DEF_TYPES[
190
+ Aos::Cor::DEF[k][:type].upcase
191
+ ][:converter].call(ENV[Aos::Cor.ivar_k(k)])
192
+ end
193
+
194
+ # adapts I18n translations to generate bash environment vars.
195
+ #
196
+ # example usage:
197
+ # Aos::Cor::DEF[:Z_MAX]
198
+ DEF = {
199
+
200
+ #
201
+ # => ivars
202
+ #
203
+ ENV: {
204
+ type: Aos::Cor::TYPES[:VALUES],
205
+ access: Aos::Cor::DEF_ACCESS[:WRITE],
206
+ value: Aos::Cor::ENVS[:PRODUCTION],
207
+ description: I18n.t("cor.env.description"),
208
+ possible_values: {
209
+ development: I18n.t("cor.env.development_description"),
210
+ production: I18n.t("cor.env.production_description"),
211
+ test: I18n.t("cor.env.test_description"),
212
+ }
213
+ },
214
+ VERBOSE: {
215
+ type: Aos::Cor::TYPES[:BOOL],
216
+ access: Aos::Cor::DEF_ACCESS[:WRITE],
217
+ value: Aos::Cor::BOOLS[:FALSE],
218
+ description: I18n.t("cor.verbose_description"),
219
+ },
220
+ LOG_AOS_DB: {
221
+ type: Aos::Cor::TYPES[:BOOL],
222
+ access: Aos::Cor::DEF_ACCESS[:WRITE],
223
+ value: Aos::Cor::BOOLS[:FALSE],
224
+ description: I18n.t("cor.log_aos_db_description"),
225
+ },
226
+ LOG_ARO_DB: {
227
+ type: Aos::Cor::TYPES[:BOOL],
228
+ access: Aos::Cor::DEF_ACCESS[:WRITE],
229
+ value: Aos::Cor::BOOLS[:FALSE],
230
+ description: I18n.t("cor.log_aro_db_description"),
231
+ },
232
+ FORMAT: {
233
+ type: Aos::Cor::TYPES[:VALUES],
234
+ implemented: false,
235
+ access: Aos::Cor::DEF_ACCESS[:WRITE],
236
+ value: Aos::Cor::FORMATS[:TEXT],
237
+ description: I18n.t("cor.format.description"),
238
+ possible_values: {
239
+ text: I18n.t("cor.format.text_description"),
240
+ json: I18n.t("cor.format.json_description")
241
+ }
242
+ },
243
+ INTERFACE: {
244
+ type: Aos::Cor::TYPES[:VALUES],
245
+ implemented: false,
246
+ access: Aos::Cor::DEF_ACCESS[:WRITE],
247
+ value: Aos::Cor::INTERFACES[:TERMINAL],
248
+ description: I18n.t("cor.interface.description"),
249
+ possible_values: {
250
+ terminal: I18n.t("cor.interface.terminal_description"),
251
+ lanimret: I18n.t("cor.interface.lanimret_description")
252
+ }
253
+ },
254
+ DIMENSION: {
255
+ type: Aos::Cor::TYPES[:VALUES],
256
+ access: Aos::Cor::DEF_ACCESS[:WRITE],
257
+ value: Aos::Cor::DMS[:DEV_TAROT],
258
+ description: I18n.t("cor.dimension.description"),
259
+ possible_values: {
260
+ dev_tarot: I18n.t("cor.dimension.dev_tarot_description"),
261
+ ruby_facot: I18n.t("cor.dimension.ruby_facot_description"),
262
+ }
263
+ },
264
+ HEIGHT: {
265
+ type: Aos::Cor::TYPES[:INT],
266
+ access: Aos::Cor::DEF_ACCESS[:WRITE],
267
+ value: Aro::Mancy::NUMERALS[:XLII],
268
+ min: Aro::Mancy::NUMERALS[:I],
269
+ max: Aro::Mancy::NUMERALS[:MMXCVII],
270
+ description: I18n.t(
271
+ "cor.height_description",
272
+ min: Aro::Mancy::NUMERALS[:I],
273
+ max: Aro::Mancy::NUMERALS[:MMXCVII],
274
+ ),
275
+ },
276
+ WIDTH: {
277
+ type: Aos::Cor::TYPES[:INT],
278
+ access: Aos::Cor::DEF_ACCESS[:WRITE],
279
+ value: Aro::Mancy::NUMERALS[:C] + Aro::Mancy::NUMERALS[:XXXVII] - Aro::Mancy::S,
280
+ min: Aro::Mancy::NUMERALS[:I],
281
+ max: Aro::Mancy::NUMERALS[:MMXCVII],
282
+ description: I18n.t(
283
+ "cor.width_description",
284
+ min: Aro::Mancy::NUMERALS[:I],
285
+ max: Aro::Mancy::NUMERALS[:MMXCVII],
286
+ ),
287
+ },
288
+ Z: {
289
+ type: Aos::Cor::TYPES[:INT],
290
+ access: Aos::Cor::DEF_ACCESS[:WRITE],
291
+ value: Aro::Mancy::NUMERALS[:I],
292
+ min: Aro::Mancy::NUMERALS[:I],
293
+ max: Aro::Mancy::NUMERALS[:MMXCVII],
294
+ description: I18n.t(
295
+ "cor.z_description",
296
+ min: Aro::Mancy::NUMERALS[:I],
297
+ max: Aro::Mancy::NUMERALS[:MMXCVII],
298
+ ),
299
+ },
300
+ Z_MAX: {
301
+ type: Aos::Cor::TYPES[:INT],
302
+ access: Aos::Cor::DEF_ACCESS[:WRITE],
303
+ value: Aro::Mancy::NUMERALS[:VII],
304
+ min: Aro::Mancy::NUMERALS[:I],
305
+ max: Aro::Mancy::NUMERALS[:XXII],
306
+ description: I18n.t(
307
+ "cor.z_max_description",
308
+ min: Aro::Mancy::NUMERALS[:I],
309
+ max: Aro::Mancy::NUMERALS[:XXII],
310
+ ),
311
+ },
312
+
313
+ #
314
+ # => ovars
315
+ #
316
+ O: {
317
+ type: Aos::Cor::TYPES[:INT],
318
+ access: Aos::Cor::DEF_ACCESS[:READ],
319
+ value: Aro::Mancy::O,
320
+ description: I18n.t("cor.aro_env.O_description"),
321
+ },
322
+ S: {
323
+ type: Aos::Cor::TYPES[:INT],
324
+ access: Aos::Cor::DEF_ACCESS[:READ],
325
+ value: Aro::Mancy::S,
326
+ description: I18n.t("cor.aro_env.S_description"),
327
+ },
328
+ OS: {
329
+ type: Aos::Cor::TYPES[:INT],
330
+ access: Aos::Cor::DEF_ACCESS[:READ],
331
+ value: Aro::Mancy::OS,
332
+ description: I18n.t("cor.aro_env.OS_description"),
333
+ },
334
+ E: {
335
+ type: Aos::Cor::TYPES[:INT],
336
+ access: Aos::Cor::DEF_ACCESS[:READ],
337
+ value: Aro::Mancy::E,
338
+ description: I18n.t("cor.aro_env.E_description"),
339
+ },
340
+ N: {
341
+ type: Aos::Cor::TYPES[:INT],
342
+ access: Aos::Cor::DEF_ACCESS[:READ],
343
+ value: Aro::Mancy::N,
344
+ description: I18n.t("cor.aro_env.N_description"),
345
+ },
346
+ PS1: {
347
+ type: Aos::Cor::TYPES[:STRING],
348
+ access: Aos::Cor::DEF_ACCESS[:READ],
349
+ value: Aro::Mancy::PS1,
350
+ description: I18n.t("cor.aro_env.PS1_description"),
351
+ },
352
+ NAME_FILE: {
353
+ type: Aos::Cor::TYPES[:STRING],
354
+ access: Aos::Cor::DEF_ACCESS[:READ],
355
+ value: Aro::Mancy::NAME_FILE,
356
+ description: I18n.t("cor.aro_env.NAME_FILE_description"),
357
+ },
358
+ I2097I: {
359
+ type: Aos::Cor::TYPES[:STRING],
360
+ access: Aos::Cor::DEF_ACCESS[:READ],
361
+ value: Aro::Mancy::I2097I,
362
+ description: I18n.t("cor.aro_env.I2097I_description"),
363
+ },
364
+ YES: {
365
+ type: Aos::Cor::TYPES[:STRING],
366
+ access: Aos::Cor::DEF_ACCESS[:READ],
367
+ value: Aro::Mancy::YES,
368
+ description: I18n.t("cor.aro_env.YES_description"),
369
+ },
370
+ ALL: {
371
+ type: Aos::Cor::TYPES[:STRING],
372
+ access: Aos::Cor::DEF_ACCESS[:READ],
373
+ value: Aro::Mancy::ALL,
374
+ description: I18n.t("cor.aro_env.ALL_description"),
375
+ },
376
+ }
377
+
378
+ def load
379
+ self.cor_path = nil
380
+ self.base_lines_def = nil
381
+ Aro::Dom.instance.eg_path = nil
382
+ return if Aos::Cor.get_cor_path.nil?
383
+ unless File.exist?(Aos::Cor.cor_filepath)
384
+ generate_config
385
+ end
386
+
387
+ source_config
388
+ Aro::D.say("running in #{Aos::Cor.ivar(:ENV)} env.")
389
+
390
+ self.display_lines = Aos::Cor.base_lines
391
+ end
392
+
393
+ def self.base_lines(args = nil)
394
+ if self.instance.base_lines_def.nil? || args.present?
395
+ args = [] if args.nil?
396
+ # print Aos::Cor::DEF
397
+ lines = []
398
+ lines << "loaded config at: #{Aos::Os.osify(Aos::Cor.cor_filepath)}"
399
+ lines << "<Aos::Cor::DEF>"
400
+ case args[Aro::Mancy::S]&.to_sym
401
+ when :ivars
402
+ lines += Aos::Cor.ivars_dump
403
+ when :ovars
404
+ lines += Aos::Cor.ovars_dump
405
+ else
406
+ lines += Aos::Cor.ivars_dump
407
+ end
408
+ # print config commands
409
+ lines << ""
410
+ lines << I18n.t("aos.constants.commands")
411
+ lines << ""
412
+ lines += Aos::Vw::Base.lines_for_cmd(Aos::Os::CMDS[:COR])
413
+ lines
414
+
415
+ self.instance.base_lines_def = lines
416
+ end
417
+
418
+ return self.instance.base_lines_def
419
+ end
420
+
421
+ Mutex.new.synchronize do
422
+ def self.get_cor_path
423
+ if self.instance.cor_path.nil?
424
+ Aos::Db.load
425
+ if Aro::Dom.in_arodom?
426
+ Aos::Os.instance.load_you!
427
+ if Aos::Os.instance.you.root? ||
428
+ Aos::Os.instance.you.agodo?
429
+ self.instance.cor_path = Aos::Cor.dom_cor_path
430
+ else
431
+ self.instance.cor_path = Aos::Os.instance.you_flag.home
432
+ end
433
+ elsif Aro::Mancy.in_aro?
434
+ self.instance.cor_path = Aos::Cor.aro_cor_path
435
+ end
436
+ end
437
+
438
+ return self.instance.cor_path
439
+ end
440
+ end
441
+
442
+ def self.aro_cor_path
443
+ File.join(Dir.pwd, Aro::Db.base_aro_dir)
444
+ end
445
+
446
+ def self.dom_cor_path
447
+ File.join(Aro::Dom::dom_root, Aro::Dom.room_path(:cor))
448
+ end
449
+
450
+ def self.cor_filepath
451
+ File.join(
452
+ Aos::Cor.get_cor_path,
453
+ Aos::Cor::COR_FILE.to_s
454
+ )
455
+ end
456
+
457
+ def self.is_test?
458
+ Aos::Cor.ivar(:ENV) == Aos::Cor::ENVS[:TEST].to_s
459
+ end
460
+
461
+ def self.discon
462
+ height = Aos::Cor.ivar(:HEIGHT).to_i
463
+ width = Aos::Cor.ivar(:WIDTH).to_i
464
+ if !Aro::Dom.in_arodom? ||
465
+ Aos::Cor.ivar(:INTERFACE) == Aos::Cor::INTERFACES[:TERMINAL].to_s
466
+ # use console for terminal always
467
+ h_con, w_con = IO.console.winsize
468
+ height = h_con if h_con > 0
469
+ width = w_con if w_con > 0
470
+ end
471
+
472
+ result = {
473
+ HEIGHT: height,
474
+ WIDTH: width,
475
+ DIVIDER: :".".to_s
476
+ }
477
+ # Aro::V.say(result)
478
+
479
+ result
480
+ end
481
+
482
+ def self.is_format_text?
483
+ Aos::Cor.ivar(:FORMAT)&.to_sym == Aos::Cor::FORMATS[:TEXT]
484
+ end
485
+
486
+ def self.process_command(args)
487
+ args = Aos::Os.sanitize_you(args)
488
+ k = Aos::Cor::DEF.keys.filter{|k| k == args[Aro::Mancy::S]&.upcase&.to_sym}&.first
489
+ unless k.nil?
490
+ unless args[Aro::Mancy::OS].nil?
491
+ # config var_name var_value
492
+ Aos::Cor.set_ivar(args[Aro::Mancy::S], args[Aro::Mancy::OS])
493
+ end
494
+
495
+ # basic show var description and value
496
+ self.instance.display_lines = self.instance.lines_var(k, Aos::Cor::DEF[k], ENV[Aos::Cor.ivar_k(k)])
497
+ else
498
+ self.instance.display_lines = Aos::Cor.base_lines(args)
499
+ end
500
+
501
+ if Aro::Mancy.in_aro? && !Aro::Dom.in_arodom?
502
+ Aro::P.say(self.instance.display_lines.join("\n"))
503
+ end
504
+ end
505
+
506
+ # out vars
507
+ def self.ovar(suffix)
508
+ Aos::Cor::DEF[suffix][:value]
509
+ end
510
+ # out vars
511
+ def self.ovar_k(suffix)
512
+ "#{Aos::Cor::ARO_OVA_PREFIX}#{suffix}"
513
+ end
514
+
515
+ # in vars
516
+ def self.ivar(suffix)
517
+ ENV[Aos::Cor.ivar_k(suffix)]
518
+ end
519
+ # in vars
520
+ def self.ivar_k(suffix)
521
+ "#{Aos::Cor::ARO_IVA_PREFIX}#{suffix}"
522
+ end
523
+
524
+ def self.set_ivar(k, new_value)
525
+ k = k.upcase.to_sym
526
+
527
+ current_value = Aos::Cor.ivar(k)
528
+ if k == :DIMENSION &&
529
+ new_value == Aos::Cor::DMS[:DEV_TAROT].to_s &&
530
+ !Aro::T.is_dev_tarot_avail?
531
+ Aro::Dom::P.say("unable to set dimension dev_tarot. device not present.")
532
+ return
533
+ end
534
+
535
+ # ensure the var name is valid
536
+ unless current_value.nil?
537
+ Aro::Dom::P.say("validating #{k} with value #{new_value}")
538
+ if Aos::Cor.instance.valid_var?(new_value, k, Aos::Cor::DEF[k])
539
+ # set ENV value
540
+ ENV[Aos::Cor.ivar_k(k)] = new_value
541
+ Aro::Dom::P.say("#{k} set to #{new_value}")
542
+ Aro::V.say(ENV[Aos::Cor.ivar_k(k)])
543
+
544
+ # flush existing config and regen
545
+ Aos::Cor.instance.generate_config(true)
546
+ Aos::Cor.instance.source_config
547
+ Aro::Db.configure_logger
548
+ Aos::Db.configure_logger
549
+ else
550
+ Aro::Dom::P.say("the ivar value you entered is invalid. ignoring.")
551
+ end
552
+ else
553
+ Aro::Dom::P.say("the ivar name you entered is invalid. ignoring.")
554
+ end
555
+ end
556
+
557
+ def self.ivars_dump
558
+ dump = []
559
+ Aos::Cor::DEF.select{|k, v|
560
+ v[:access] == Aos::Cor::DEF_ACCESS[:WRITE]
561
+ }.each{|k, v|
562
+ dump << "#{Aos::Cor.ivar_k(k).ljust(Aro::Mancy::NUMERALS[:XIV] * Aro::Mancy::OS)}=#{Aos::Cor.ivar(k)}"
563
+ }
564
+
565
+ dump
566
+ end
567
+
568
+ def self.ovars_dump
569
+ dump = []
570
+ Aos::Cor::DEF.select{|k, v|
571
+ v[:access] == Aos::Cor::DEF_ACCESS[:READ]
572
+ }.each{|k, v|
573
+ dump << "#{Aos::Cor.ovar_k(k).ljust(Aro::Mancy::NUMERALS[:XIV] * Aro::Mancy::OS)}=#{Aos::Cor.ovar(k)}"
574
+ }
575
+
576
+ dump
577
+ end
578
+
579
+ def source_config
580
+ Aro::D.say(I18n.t("cor.source", name: Aos::Cor.cor_filepath))
581
+ File.read(Aos::Cor.cor_filepath).split("\n").select{|line|
582
+ line.match?(/export #{Aos::Cor::ARO_IVA_PREFIX}/)
583
+ }.map{|line|
584
+ line.gsub("export ", "").split("=")
585
+ }.each{|kv|
586
+ Aro::V.say("variable to set: #{kv}")
587
+ ENV[kv[0]] = kv[1] # source
588
+ Aro::V.say("value actually set: #{ENV[kv[0]]}")
589
+ }
590
+
591
+ invalid_defs = validate_config
592
+ Aos::Cor.ivars_dump.each{|l| Aro::V.say(l)}
593
+ Aos::Cor.ovars_dump.each{|l| Aro::V.say(l)}
594
+ invalid_defs.each{|k|
595
+ v = Aos::Cor::DEF[k.to_sym]
596
+ if v[:access] == Aos::Cor::DEF_ACCESS[:WRITE]
597
+ ENV[Aos::Cor.ivar_k(k)] = v[:value]
598
+ else
599
+ ENV[Aos::Cor.ovar_k(k)] = v[:value]
600
+ end
601
+ }
602
+ end
603
+
604
+ # from_memory true means write current config to file
605
+ def generate_config(from_memory = false)
606
+ # todo: localize generated config text
607
+ Aro::D.say(I18n.t("cor.generate", name: Aos::Cor.cor_filepath))
608
+
609
+ lines = []
610
+
611
+ # intro
612
+ Aro::Mancy::OS.times do
613
+ lines += lines_div
614
+ end
615
+
616
+ # header
617
+ lines += lines_div
618
+ lines += lines_newline_comment
619
+ lines += lines_config_header
620
+ lines += lines_newline_comment
621
+ lines += lines_div
622
+
623
+ lines += lines_newline_comment_os
624
+
625
+ # def_types
626
+ lines += lines_div
627
+ lines += lines_newline_comment
628
+ lines += lines_def_type_description
629
+ lines += lines_newline_comment
630
+ lines += lines_div
631
+
632
+ lines += lines_newline_comment_os
633
+
634
+ # var section
635
+ lines += lines_div
636
+ lines += lines_newline_comment
637
+ lines += lines_var_section_div
638
+ lines += lines_newline_comment
639
+ lines += lines_div
640
+
641
+ lines += lines_newline_comment_os
642
+
643
+ # vars
644
+ Aos::Cor::DEF.each{|k, v|
645
+ lines += lines_var(k, v, (from_memory ? ENV[Aos::Cor.ivar_k(k)] : nil))
646
+ }
647
+
648
+ lines += lines_newline_comment_os
649
+
650
+ # var section
651
+ lines += lines_div
652
+ lines += lines_newline_comment
653
+ lines += lines_var_section_div
654
+ lines += lines_newline_comment
655
+ lines += lines_div
656
+
657
+ lines += lines_newline_comment_os
658
+ # outro
659
+ Aro::Mancy::OS.times do
660
+ lines += lines_div
661
+ end
662
+ write_config(lines)
663
+ end
664
+
665
+ def write_config(lines)
666
+ to_write = Aos::Cor.cor_filepath
667
+ File.open(to_write, "w") do |file|
668
+ file.write(lines.join("\n"))
669
+ file.write("\n")
670
+ end
671
+
672
+ # unless (to_write == Aos::Cor.aro_cor_path) && Aro::Mancy.in_aro?
673
+ # File.open(Aos::Cor.aro_cor_path, "w") do |file|
674
+ # file.write(lines.join("\n"))
675
+ # file.write("\n")
676
+ # end
677
+ # end
678
+ end
679
+
680
+ def lines_div
681
+ ["".ljust(Aro::Mancy::NUMERALS[:XLII] * Aro::Mancy::OS, "#")]
682
+ end
683
+
684
+ def lines_newline_comment
685
+ ["#"]
686
+ end
687
+
688
+ def lines_newline_comment_os
689
+ lines = []
690
+ Aro::Mancy::OS.times do
691
+ lines += lines_newline_comment
692
+ end
693
+ lines
694
+ end
695
+
696
+ def lines_config_header
697
+ [
698
+ "# #{Aos::Os} cor configuration file generated by #{Aos::Cor.name}."
699
+ ]
700
+ end
701
+
702
+ def lines_var_section_div
703
+ ["# Aos::Cor::DEF"]
704
+ end
705
+
706
+ def lines_def_type_description
707
+ lines = []
708
+ lines << "# Aos::Cor::DEF_TYPES"
709
+ lines << "# describes the possible types of variables."
710
+ Aos::Cor::DEF_TYPES.each{|k, v|
711
+ lines << "# #{k}: #{v[:description]}"
712
+ }
713
+ lines += lines_newline_comment_os
714
+ lines << "# Aos::Cor::DEF"
715
+ lines << "# define and expose an aos cor bash api via ENV variables."
716
+ lines << "# there are two types of cor vars in aos."
717
+ lines << "# 1) in vars (ivars). "
718
+ lines << "# => write variables from this file."
719
+ lines << "# => they are validated and used unless unvalid."
720
+ lines << "# 2) out vars (ovars)."
721
+ lines << "# => read-only variables that aos cor exposes to bash."
722
+ end
723
+
724
+ def lines_var(k, v, mem_v = nil)
725
+ lines = []
726
+ is_ovar = Aos::Cor::DEF[k][:access] == Aos::Cor::DEF_ACCESS[:READ]
727
+ if is_ovar
728
+ var_name = Aos::Cor.ovar_k(k)
729
+ else
730
+ var_name = Aos::Cor.ivar_k(k)
731
+ end
732
+ Aro::V.say("access for #{k} is #{Aos::Cor::DEF[k][:access]}")
733
+ Aro::V.say("using var_name: #{var_name}")
734
+ lines << "# [#{var_name}] (#{is_ovar ? :ovar : :ivar})"
735
+ lines << "# => Aos::Cor::DEF_TYPES: #{v[:type]}"
736
+ case v[:type]
737
+ when Aos::Cor::DEF_TYPES[:BOOL][:name]
738
+ lines << "# => #{I18n.t("cor.type.bool_description")}"
739
+ when Aos::Cor::DEF_TYPES[:INT][:name]
740
+ lines << "# => #{I18n.t("cor.type.int_description")}"
741
+ lines << "# => #{I18n.t("cor.minimum")}: #{v[:min]}"
742
+ lines << "# => #{I18n.t("cor.maximum")}: #{v[:max]}"
743
+ when Aos::Cor::DEF_TYPES[:STRING][:name]
744
+ lines << "# => #{I18n.t("cor.type.string_description")}"
745
+ lines << "# => use \"double quotes\" if there are any spaces."
746
+ when Aos::Cor::DEF_TYPES[:VALUES][:name]
747
+ lines << "# => #{I18n.t("cor.type.values_description")}"
748
+ lines << "# => #{I18n.t("cor.possible_values")}:"
749
+ lines += lines_newline_comment
750
+ v[:possible_values].each{|name, description|
751
+ lines << "# => #{name}"
752
+ lines += lines_newline_comment
753
+ lines << "# =>#{description}"
754
+ lines += lines_newline_comment
755
+ }
756
+ end
757
+ lines += lines_newline_comment_os
758
+ lines << "# => description:"
759
+ lines << "# => #{v[:description]}"
760
+ if is_ovar && Aos::Cor::DEF_TYPES[:STRING][:name] == v[:type]
761
+ lines << "export #{var_name}=\"#{v[:value]}\""
762
+ else
763
+ lines << "export #{var_name}=#{mem_v || v[:value]}"
764
+ end
765
+ lines += lines_newline_comment_os
766
+ lines
767
+ end
768
+
769
+ end
770
+ end