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