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.
@@ -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
- # options = menu_default_option_values(menu_data).merge input_option_values
31
- # options = (menu_default_option_values(menu_data)).merge(input_option_values).tap_yaml 'options1'
32
- options = menu_default_option_values(menu_data).merge(config).merge(input_option_values) #.tap_yaml 'options2'
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] = lambdas.fetch(procname.to_sym, menu_item[:procname])
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? ? " #{item[:arg_name]}" : ''}"
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
- [item[:description],
96
- item[:default].present? ? "[#{value_for_menu item[:default]}]" : nil].compact.join(' '),
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
- option_parser.load # filename defaults to basename of the program without suffix in a directory ~/.options
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: ->(_) { menu_default_option_values(@menu).to_yaml.tap_puts },
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: ->(value) { value.class.to_s == 'String' ? (value.chomp != '0') : value },
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 { |_|
@@ -7,5 +7,5 @@ module MarkdownExec
7
7
  BIN_NAME = 'mde'
8
8
  GEM_NAME = 'markdown_exec'
9
9
  TAP_DEBUG = 'MDE_DEBUG'
10
- VERSION = '1.3.1'
10
+ VERSION = '1.3.3.1'
11
11
  end