markdown_exec 1.3.1 → 1.3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +21 -4
- data/CHANGELOG.md +45 -1
- data/Gemfile +8 -5
- data/Gemfile.lock +125 -29
- data/README.md +5 -80
- data/Rakefile +108 -24
- data/bin/tab_completion.sh +2 -2
- data/lib/cached_nested_file_reader.rb +115 -0
- data/lib/colorize.rb +4 -0
- data/lib/env.rb +8 -3
- data/lib/env_opts.rb +242 -0
- data/lib/environment_opt_parse.rb +28 -19
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +593 -281
- data/lib/menu.yml +70 -4
- data/lib/object_present.rb +44 -1
- data/lib/rspec_helpers.rb +10 -0
- data/lib/tap.rb +81 -17
- metadata +5 -3
- data/lib/globfiles.rb +0 -40
@@ -7,6 +7,8 @@ require 'yaml'
|
|
7
7
|
|
8
8
|
require_relative 'object_present'
|
9
9
|
|
10
|
+
# add Hash.sym_keys
|
11
|
+
#
|
10
12
|
class Hash
|
11
13
|
unless defined?(sym_keys)
|
12
14
|
def sym_keys
|
@@ -18,6 +20,8 @@ class Hash
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
23
|
+
# parse application configuration from command-line options and environment variables
|
24
|
+
#
|
21
25
|
class EnvironmentOptParse
|
22
26
|
attr_reader :options, :remainder
|
23
27
|
|
@@ -27,18 +31,9 @@ class EnvironmentOptParse
|
|
27
31
|
def menu_all(menu_data, lambdas, config)
|
28
32
|
config.tap_yaml 'config'
|
29
33
|
input_option_values, remainder, = menu_parse(add_proc(menu_data, lambdas))
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# options = menu_data.map do |menu_item|
|
34
|
-
# menu_item.tap_inspect 'menu_item'
|
35
|
-
# mion = menu_item[:opt_name]&.to_sym.tap_inspect 'mion'
|
36
|
-
# omion = config[mion].tap_inspect 'omion'
|
37
|
-
# unless omion.nil?
|
38
|
-
# menu_item[:default] = omion
|
39
|
-
# end
|
40
|
-
# menu_item
|
41
|
-
# end,
|
34
|
+
options = menu_default_option_values(menu_data)
|
35
|
+
.merge(config)
|
36
|
+
.merge(input_option_values)
|
42
37
|
|
43
38
|
[options, remainder]
|
44
39
|
end
|
@@ -49,7 +44,8 @@ class EnvironmentOptParse
|
|
49
44
|
procname = menu_item[:procname]
|
50
45
|
next if procname.nil?
|
51
46
|
|
52
|
-
menu_item[:proccode] =
|
47
|
+
menu_item[:proccode] =
|
48
|
+
lambdas.fetch(procname.to_sym, menu_item[:procname])
|
53
49
|
end.tap_yaml
|
54
50
|
end
|
55
51
|
|
@@ -85,15 +81,21 @@ class EnvironmentOptParse
|
|
85
81
|
mmoo = [
|
86
82
|
# long name
|
87
83
|
if item[:long_name].present?
|
88
|
-
"--#{item[:long_name]}#{item[:arg_name].present?
|
84
|
+
# if "--#{item[:long_name]}#{item[:arg_name]".present?
|
85
|
+
# " #{item[:arg_name]}"
|
86
|
+
# else
|
87
|
+
# "''}"
|
88
|
+
# end
|
89
89
|
end,
|
90
90
|
|
91
91
|
# short name
|
92
92
|
item[:short_name].present? ? "-#{item[:short_name]}" : nil,
|
93
93
|
|
94
94
|
# description and default
|
95
|
-
[
|
96
|
-
|
95
|
+
[
|
96
|
+
item[:description],
|
97
|
+
item[:default].present? ? "[#{value_for_menu item[:default]}]" : nil
|
98
|
+
].compact.join(' '),
|
97
99
|
|
98
100
|
# apply proccode, if present, to value
|
99
101
|
# save value to options hash if option is named
|
@@ -118,7 +120,10 @@ class EnvironmentOptParse
|
|
118
120
|
menu_option_append opts, options, item
|
119
121
|
end
|
120
122
|
end
|
121
|
-
|
123
|
+
|
124
|
+
# filename defaults to basename of the program
|
125
|
+
# without suffix in a directory ~/.options
|
126
|
+
option_parser.load
|
122
127
|
option_parser.environment # env defaults to the basename of the program.
|
123
128
|
remainder = option_parser.parse!
|
124
129
|
|
@@ -180,12 +185,16 @@ class EnvironmentOptParse
|
|
180
185
|
# lambda { |v| options.tap_puts 'eop_l' }
|
181
186
|
# }).call(@options),
|
182
187
|
|
183
|
-
stdout_defaults:
|
188
|
+
stdout_defaults: lambda { |_|
|
189
|
+
menu_default_option_values(@menu).to_yaml.tap_puts
|
190
|
+
},
|
184
191
|
stdout_help: lambda { |_|
|
185
192
|
menu_help(@menu).tap_puts
|
186
193
|
exit
|
187
194
|
},
|
188
|
-
val_as_bool:
|
195
|
+
val_as_bool: lambda { |value|
|
196
|
+
value.class.to_s == 'String' ? (value.chomp != '0') : value
|
197
|
+
},
|
189
198
|
val_as_int: ->(value) { value.to_i },
|
190
199
|
val_as_str: ->(value) { value.to_s },
|
191
200
|
version: lambda { |_|
|