aspera-cli 4.10.0 → 4.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/BUGS.md +19 -0
  4. data/CHANGELOG.md +528 -0
  5. data/CONTRIBUTING.md +143 -0
  6. data/README.md +977 -589
  7. data/bin/ascli +4 -4
  8. data/bin/asession +12 -12
  9. data/docs/test_env.conf +29 -19
  10. data/examples/aoc.rb +6 -6
  11. data/examples/dascli +18 -16
  12. data/examples/faspex4.rb +15 -15
  13. data/examples/node.rb +12 -12
  14. data/examples/proxy.pac +2 -2
  15. data/examples/server.rb +12 -12
  16. data/lib/aspera/aoc.rb +344 -272
  17. data/lib/aspera/ascmd.rb +56 -54
  18. data/lib/aspera/ats_api.rb +4 -4
  19. data/lib/aspera/cli/basic_auth_plugin.rb +15 -12
  20. data/lib/aspera/cli/extended_value.rb +9 -9
  21. data/lib/aspera/cli/{formater.rb → formatter.rb} +69 -69
  22. data/lib/aspera/cli/listener/line_dump.rb +1 -1
  23. data/lib/aspera/cli/listener/logger.rb +1 -1
  24. data/lib/aspera/cli/listener/progress.rb +5 -6
  25. data/lib/aspera/cli/listener/progress_multi.rb +16 -21
  26. data/lib/aspera/cli/main.rb +72 -73
  27. data/lib/aspera/cli/manager.rb +112 -112
  28. data/lib/aspera/cli/plugin.rb +68 -48
  29. data/lib/aspera/cli/plugins/alee.rb +4 -4
  30. data/lib/aspera/cli/plugins/aoc.rb +322 -720
  31. data/lib/aspera/cli/plugins/ats.rb +50 -52
  32. data/lib/aspera/cli/plugins/bss.rb +10 -10
  33. data/lib/aspera/cli/plugins/config.rb +514 -410
  34. data/lib/aspera/cli/plugins/console.rb +12 -12
  35. data/lib/aspera/cli/plugins/cos.rb +18 -20
  36. data/lib/aspera/cli/plugins/faspex.rb +134 -136
  37. data/lib/aspera/cli/plugins/faspex5.rb +235 -70
  38. data/lib/aspera/cli/plugins/node.rb +378 -309
  39. data/lib/aspera/cli/plugins/orchestrator.rb +52 -49
  40. data/lib/aspera/cli/plugins/preview.rb +129 -120
  41. data/lib/aspera/cli/plugins/server.rb +137 -83
  42. data/lib/aspera/cli/plugins/shares.rb +77 -52
  43. data/lib/aspera/cli/plugins/sync.rb +13 -33
  44. data/lib/aspera/cli/transfer_agent.rb +61 -61
  45. data/lib/aspera/cli/version.rb +2 -1
  46. data/lib/aspera/colors.rb +3 -3
  47. data/lib/aspera/command_line_builder.rb +78 -74
  48. data/lib/aspera/cos_node.rb +31 -29
  49. data/lib/aspera/data_repository.rb +1 -1
  50. data/lib/aspera/environment.rb +30 -28
  51. data/lib/aspera/fasp/agent_base.rb +17 -15
  52. data/lib/aspera/fasp/agent_connect.rb +34 -32
  53. data/lib/aspera/fasp/agent_direct.rb +70 -73
  54. data/lib/aspera/fasp/agent_httpgw.rb +79 -74
  55. data/lib/aspera/fasp/agent_node.rb +26 -26
  56. data/lib/aspera/fasp/agent_trsdk.rb +20 -20
  57. data/lib/aspera/fasp/error.rb +3 -2
  58. data/lib/aspera/fasp/error_info.rb +11 -8
  59. data/lib/aspera/fasp/installation.rb +80 -80
  60. data/lib/aspera/fasp/listener.rb +2 -2
  61. data/lib/aspera/fasp/parameters.rb +103 -92
  62. data/lib/aspera/fasp/parameters.yaml +313 -214
  63. data/lib/aspera/fasp/resume_policy.rb +10 -10
  64. data/lib/aspera/fasp/transfer_spec.rb +22 -2
  65. data/lib/aspera/fasp/uri.rb +7 -7
  66. data/lib/aspera/faspex_gw.rb +80 -159
  67. data/lib/aspera/faspex_postproc.rb +77 -0
  68. data/lib/aspera/hash_ext.rb +3 -3
  69. data/lib/aspera/id_generator.rb +5 -5
  70. data/lib/aspera/keychain/encrypted_hash.rb +23 -28
  71. data/lib/aspera/keychain/macos_security.rb +21 -20
  72. data/lib/aspera/log.rb +13 -13
  73. data/lib/aspera/nagios.rb +24 -23
  74. data/lib/aspera/node.rb +217 -38
  75. data/lib/aspera/oauth.rb +78 -74
  76. data/lib/aspera/open_application.rb +19 -11
  77. data/lib/aspera/persistency_action_once.rb +4 -4
  78. data/lib/aspera/persistency_folder.rb +13 -13
  79. data/lib/aspera/preview/file_types.rb +8 -8
  80. data/lib/aspera/preview/generator.rb +67 -67
  81. data/lib/aspera/preview/utils.rb +27 -27
  82. data/lib/aspera/proxy_auto_config.js +63 -63
  83. data/lib/aspera/proxy_auto_config.rb +19 -19
  84. data/lib/aspera/rest.rb +65 -67
  85. data/lib/aspera/rest_call_error.rb +2 -1
  86. data/lib/aspera/rest_error_analyzer.rb +22 -21
  87. data/lib/aspera/rest_errors_aspera.rb +16 -16
  88. data/lib/aspera/secret_hider.rb +17 -14
  89. data/lib/aspera/ssh.rb +15 -14
  90. data/lib/aspera/sync.rb +177 -62
  91. data/lib/aspera/temp_file_manager.rb +2 -2
  92. data/lib/aspera/uri_reader.rb +4 -4
  93. data/lib/aspera/web_auth.rb +13 -64
  94. data/lib/aspera/web_server_simple.rb +76 -0
  95. data.tar.gz.sig +0 -0
  96. metadata +11 -6
  97. metadata.gz.sig +0 -0
@@ -12,10 +12,10 @@ module Aspera
12
12
  class CliError < StandardError; end
13
13
 
14
14
  # raised when an unexpected argument is provided
15
- class CliBadArgument < CliError; end
15
+ class CliBadArgument < Aspera::Cli::CliError; end
16
16
 
17
- class CliNoSuchId < CliError
18
- def initialize(res_type,res_id)
17
+ class CliNoSuchId < Aspera::Cli::CliError
18
+ def initialize(res_type, res_id)
19
19
  msg = "No such #{res_type} identifier: #{res_id}"
20
20
  super(msg)
21
21
  end
@@ -23,9 +23,9 @@ module Aspera
23
23
 
24
24
  # option is retrieved from another object using accessor
25
25
  class AttrAccessor
26
- #attr_accessor :object
27
- #attr_accessor :attr_symb
28
- def initialize(object,attr_symb)
26
+ # attr_accessor :object
27
+ # attr_accessor :attr_symb
28
+ def initialize(object, attr_symb)
29
29
  @object = object
30
30
  @attr_symb = attr_symb
31
31
  end
@@ -35,7 +35,7 @@ module Aspera
35
35
  end
36
36
 
37
37
  def value=(val)
38
- @object.send("#{@attr_symb}=",val)
38
+ @object.send("#{@attr_symb}=", val)
39
39
  end
40
40
  end
41
41
 
@@ -45,16 +45,16 @@ module Aspera
45
45
  class Manager
46
46
  # boolean options are set to true/false from the following values
47
47
  BOOLEAN_SIMPLE = %i[no yes].freeze
48
- FALSE_VALUES = [BOOLEAN_SIMPLE.first,false].freeze
49
- TRUE_VALUES = [BOOLEAN_SIMPLE.last,true].freeze
50
- BOOLEAN_VALUES = [TRUE_VALUES,FALSE_VALUES].flatten.freeze
48
+ FALSE_VALUES = [BOOLEAN_SIMPLE.first, false].freeze
49
+ TRUE_VALUES = [BOOLEAN_SIMPLE.last, true].freeze
50
+ BOOLEAN_VALUES = [TRUE_VALUES, FALSE_VALUES].flatten.freeze
51
51
 
52
52
  # option name separator on command line
53
53
  OPTION_SEP_LINE = '-'
54
54
  # option name separator in code (symbol)
55
55
  OPTION_SEP_NAME = '_'
56
56
 
57
- private_constant :FALSE_VALUES,:TRUE_VALUES,:BOOLEAN_VALUES,:OPTION_SEP_LINE,:OPTION_SEP_NAME
57
+ private_constant :FALSE_VALUES, :TRUE_VALUES, :BOOLEAN_VALUES, :OPTION_SEP_LINE, :OPTION_SEP_NAME
58
58
 
59
59
  class << self
60
60
  def enum_to_bool(enum)
@@ -67,19 +67,19 @@ module Aspera
67
67
  end
68
68
 
69
69
  # find shortened string value in allowed symbol list
70
- def get_from_list(shortval,descr,allowed_values)
70
+ def get_from_list(shortval, descr, allowed_values)
71
71
  # we accept shortcuts
72
72
  matching_exact = allowed_values.select{|i| i.to_s.eql?(shortval)}
73
73
  return matching_exact.first if matching_exact.length == 1
74
74
  matching = allowed_values.select{|i| i.to_s.start_with?(shortval)}
75
- raise CliBadArgument,bad_arg_message_multi("unknown value for #{descr}: #{shortval}",allowed_values) if matching.empty?
76
- raise CliBadArgument,bad_arg_message_multi("ambigous shortcut for #{descr}: #{shortval}",matching) unless matching.length.eql?(1)
75
+ raise CliBadArgument, bad_arg_message_multi("unknown value for #{descr}: #{shortval}", allowed_values) if matching.empty?
76
+ raise CliBadArgument, bad_arg_message_multi("ambiguous shortcut for #{descr}: #{shortval}", matching) unless matching.length.eql?(1)
77
77
  return enum_to_bool(matching.first) if allowed_values.eql?(BOOLEAN_VALUES)
78
78
  return matching.first
79
79
  end
80
80
 
81
- def bad_arg_message_multi(error_msg,choices)
82
- return [error_msg,'Use:',choices.map{|c|"- #{c}"}.sort].flatten.join("\n")
81
+ def bad_arg_message_multi(error_msg, choices)
82
+ return [error_msg, 'Use:'].concat(choices.map{|c|"- #{c}"}.sort).join("\n")
83
83
  end
84
84
  end
85
85
 
@@ -87,7 +87,7 @@ module Aspera
87
87
  attr_accessor :ask_missing_mandatory, :ask_missing_optional
88
88
  attr_writer :fail_on_missing_mandatory
89
89
 
90
- def initialize(program_name,argv: nil)
90
+ def initialize(program_name, argv: nil)
91
91
  # command line values not starting with '-'
92
92
  @unprocessed_cmd_line_arguments = []
93
93
  # command line values starting with '-'
@@ -104,30 +104,30 @@ module Aspera
104
104
  # those must be set before parse, parse consumes those defined only
105
105
  @unprocessed_defaults = []
106
106
  @unprocessed_env = []
107
- # Note: was initially inherited but it is prefered to have specific methods
107
+ # NOTE: was initially inherited but it is preferred to have specific methods
108
108
  @parser = OptionParser.new
109
109
  @parser.program_name = program_name
110
- # options can also be provided by env vars : --param-name -> ASLMCLI_PARAM_NAME
110
+ # options can also be provided by env vars : --param-name -> ASCLI_PARAM_NAME
111
111
  env_prefix = program_name.upcase + OPTION_SEP_NAME
112
- ENV.each do |k,v|
112
+ ENV.each do |k, v|
113
113
  if k.start_with?(env_prefix)
114
- @unprocessed_env.push([k[env_prefix.length..-1].downcase.to_sym,v])
114
+ @unprocessed_env.push([k[env_prefix.length..-1].downcase.to_sym, v])
115
115
  end
116
116
  end
117
- Log.log.debug("env=#{@unprocessed_env}".red)
117
+ Log.log.debug{"env=#{@unprocessed_env}".red}
118
118
  @unprocessed_cmd_line_options = []
119
119
  @unprocessed_cmd_line_arguments = []
120
120
  # argv is nil when help is generated for every plugin
121
121
  unless argv.nil?
122
122
  @parser.separator('')
123
123
  @parser.separator('OPTIONS: global')
124
- set_obj_attr(:interactive,self,:ask_missing_mandatory)
125
- set_obj_attr(:ask_options,self,:ask_missing_optional)
126
- add_opt_boolean(:interactive,'use interactive input of missing params')
127
- add_opt_boolean(:ask_options,'ask even optional options')
124
+ set_obj_attr(:interactive, self, :ask_missing_mandatory)
125
+ set_obj_attr(:ask_options, self, :ask_missing_optional)
126
+ add_opt_boolean(:interactive, 'use interactive input of missing params')
127
+ add_opt_boolean(:ask_options, 'ask even optional options')
128
128
  parse_options!
129
129
  process_options = true
130
- while !argv.empty?
130
+ until argv.empty?
131
131
  value = argv.shift
132
132
  if process_options && value.start_with?('-')
133
133
  if value.eql?('--')
@@ -141,10 +141,10 @@ module Aspera
141
141
  end
142
142
  end
143
143
  @initial_cli_options = @unprocessed_cmd_line_options.dup
144
- Log.log.debug("add_cmd_line_options:commands/args=#{@unprocessed_cmd_line_arguments},options=#{@unprocessed_cmd_line_options}".red)
144
+ Log.log.debug{"add_cmd_line_options:commands/args=#{@unprocessed_cmd_line_arguments},options=#{@unprocessed_cmd_line_options}".red}
145
145
  end
146
146
 
147
- def get_next_command(command_list); return get_next_argument('command',expected: command_list); end
147
+ def get_next_command(command_list); return get_next_argument('command', expected: command_list); end
148
148
 
149
149
  # @param expected is
150
150
  # - Array of allowed value (single value)
@@ -153,10 +153,10 @@ module Aspera
153
153
  # @param mandatory true/false
154
154
  # @param type expected class for result
155
155
  # @return value, list or nil
156
- def get_next_argument(descr,expected: :single,mandatory: true, type: nil)
156
+ def get_next_argument(descr, expected: :single, mandatory: true, type: nil)
157
157
  unless type.nil?
158
158
  raise 'internal: type must be a Class' unless type.is_a?(Class)
159
- descr="#{descr} (#{type})"
159
+ descr = "#{descr} (#{type})"
160
160
  end
161
161
  result = nil
162
162
  if !@unprocessed_cmd_line_arguments.empty?
@@ -171,22 +171,22 @@ module Aspera
171
171
  result = result.first
172
172
  end
173
173
  else
174
- result = self.class.get_from_list(@unprocessed_cmd_line_arguments.shift,descr,expected)
174
+ result = self.class.get_from_list(@unprocessed_cmd_line_arguments.shift, descr, expected)
175
175
  end
176
176
  elsif mandatory
177
177
  # no value provided
178
- result = get_interactive(:argument,descr,expected: expected)
178
+ result = get_interactive(:argument, descr, expected: expected)
179
179
  end
180
- Log.log.debug("#{descr}=#{result}")
180
+ Log.log.debug{"#{descr}=#{result}"}
181
181
  raise "argument shall be #{type.name}" unless type.nil? || result.is_a?(type)
182
182
  return result
183
183
  end
184
184
 
185
185
  # declare option of type :accessor, or :value
186
- def declare_option(option_symbol,type)
187
- Log.log.debug("declare_option: #{option_symbol}: #{type}: skip=#{@declared_options.has_key?(option_symbol)}".green)
188
- if @declared_options.has_key?(option_symbol)
189
- raise "INTERNAL ERROR: option #{option_symbol} already declared. only accessor can be redeclared and ignored" \
186
+ def declare_option(option_symbol, type)
187
+ Log.log.debug{"declare_option: #{option_symbol}: #{type}: skip=#{@declared_options.key?(option_symbol)}".green}
188
+ if @declared_options.key?(option_symbol)
189
+ raise "INTERNAL ERROR: option #{option_symbol} already declared. only accessor can be re-declared and ignored" \
190
190
  unless @declared_options[option_symbol][:type].eql?(:accessor)
191
191
  return
192
192
  end
@@ -196,23 +196,23 @@ module Aspera
196
196
  end
197
197
 
198
198
  # define option with handler
199
- def set_obj_attr(option_symbol,object,attr_symb,default_value=nil)
200
- Log.log.debug("set attr obj #{option_symbol} (#{object},#{attr_symb})")
201
- declare_option(option_symbol,:accessor)
202
- @declared_options[option_symbol][:accessor] = AttrAccessor.new(object,attr_symb)
203
- set_option(option_symbol,default_value,'default obj attr') if !default_value.nil?
199
+ def set_obj_attr(option_symbol, object, attr_symb, default_value=nil)
200
+ Log.log.debug{"set attr obj #{option_symbol} (#{object},#{attr_symb})"}
201
+ declare_option(option_symbol, :accessor)
202
+ @declared_options[option_symbol][:accessor] = AttrAccessor.new(object, attr_symb)
203
+ set_option(option_symbol, default_value, 'default obj attr') if !default_value.nil?
204
204
  end
205
205
 
206
206
  # set an option value by name, either store value or call handler
207
- def set_option(option_symbol,value,where='default')
208
- if !@declared_options.has_key?(option_symbol)
209
- Log.log.debug("set unknown option: #{option_symbol}")
207
+ def set_option(option_symbol, value, where='default')
208
+ if !@declared_options.key?(option_symbol)
209
+ Log.log.debug{"set unknown option: #{option_symbol}"}
210
210
  raise 'ERROR: cannot set undeclared option'
211
- #declare_option(option_symbol)
211
+ # declare_option(option_symbol)
212
212
  end
213
213
  value = ExtendedValue.instance.evaluate(value)
214
214
  value = Manager.enum_to_bool(value) if @declared_options[option_symbol][:values].eql?(BOOLEAN_VALUES)
215
- Log.log.debug("(#{@declared_options[option_symbol][:type]}/#{where}) set #{option_symbol}=#{value}")
215
+ Log.log.debug{"(#{@declared_options[option_symbol][:type]}/#{where}) set #{option_symbol}=#{value}"}
216
216
  case @declared_options[option_symbol][:type]
217
217
  when :accessor
218
218
  @declared_options[option_symbol][:accessor].value = value
@@ -226,9 +226,9 @@ module Aspera
226
226
  # get an option value by name
227
227
  # either return value or call handler, can return nil
228
228
  # ask interactively if requested/required
229
- def get_option(option_symbol,is_type: :optional)
229
+ def get_option(option_symbol, is_type: :optional)
230
230
  result = nil
231
- if @declared_options.has_key?(option_symbol)
231
+ if @declared_options.key?(option_symbol)
232
232
  case @declared_options[option_symbol][:type]
233
233
  when :accessor
234
234
  result = @declared_options[option_symbol][:accessor].value
@@ -237,41 +237,41 @@ module Aspera
237
237
  else
238
238
  raise 'unknown type'
239
239
  end
240
- Log.log.debug("(#{@declared_options[option_symbol][:type]}) get #{option_symbol}=#{result}")
240
+ Log.log.debug{"(#{@declared_options[option_symbol][:type]}) get #{option_symbol}=#{result}"}
241
241
  end
242
242
  # do not fail for manual generation if option mandatory but not set
243
243
  result = '' if result.nil? && is_type.eql?(:mandatory) && !@fail_on_missing_mandatory
244
- #Log.log.debug("interactive=#{@ask_missing_mandatory}")
244
+ # Log.log.debug{"interactive=#{@ask_missing_mandatory}"}
245
245
  if result.nil?
246
246
  if !@ask_missing_mandatory
247
- raise CliBadArgument,"Missing mandatory option: #{option_symbol}" if is_type.eql?(:mandatory)
247
+ raise CliBadArgument, "Missing mandatory option: #{option_symbol}" if is_type.eql?(:mandatory)
248
248
  elsif @ask_missing_optional || is_type.eql?(:mandatory)
249
249
  # ask_missing_mandatory
250
250
  expected = :single
251
- #print "please enter: #{option_symbol.to_s}"
252
- if @declared_options.has_key?(option_symbol) && @declared_options[option_symbol].has_key?(:values)
251
+ # print "please enter: #{option_symbol.to_s}"
252
+ if @declared_options.key?(option_symbol) && @declared_options[option_symbol].key?(:values)
253
253
  expected = @declared_options[option_symbol][:values]
254
254
  end
255
- result = get_interactive(:option,option_symbol.to_s,expected: expected)
256
- set_option(option_symbol,result,'interactive')
255
+ result = get_interactive(:option, option_symbol.to_s, expected: expected)
256
+ set_option(option_symbol, result, 'interactive')
257
257
  end
258
258
  end
259
259
  return result
260
260
  end
261
261
 
262
262
  # param must be hash
263
- def add_option_preset(preset_hash,op: :push)
264
- Log.log.debug("add_option_preset=#{preset_hash}")
263
+ def add_option_preset(preset_hash, op: :push)
264
+ Log.log.debug{"add_option_preset=#{preset_hash}"}
265
265
  raise "internal error: setting default with no hash: #{preset_hash.class}" if !preset_hash.is_a?(Hash)
266
266
  # incremental override
267
- preset_hash.each{|k,v|@unprocessed_defaults.send(op,[k.to_sym,v])}
267
+ preset_hash.each{|k, v|@unprocessed_defaults.send(op, [k.to_sym, v])}
268
268
  end
269
269
 
270
270
  # define an option with restricted values
271
- def add_opt_list(option_symbol,values,help,*on_args)
272
- declare_option(option_symbol,:value)
273
- Log.log.debug("add_opt_list #{option_symbol}")
274
- on_args.unshift(symbol_to_option(option_symbol,'ENUM'))
271
+ def add_opt_list(option_symbol, values, help, *on_args)
272
+ declare_option(option_symbol, :value)
273
+ Log.log.debug{"add_opt_list #{option_symbol}"}
274
+ on_args.unshift(symbol_to_option(option_symbol, 'ENUM'))
275
275
  # this option value must be a symbol
276
276
  @declared_options[option_symbol][:values] = values
277
277
  value = get_option(option_symbol)
@@ -281,47 +281,47 @@ module Aspera
281
281
  end
282
282
  on_args.push(values)
283
283
  on_args.push("#{help}: #{help_values}")
284
- Log.log.debug("on_args=#{on_args}")
285
- @parser.on(*on_args){|v|set_option(option_symbol,self.class.get_from_list(v.to_s,help,values),'cmdline')}
284
+ Log.log.debug{"on_args=#{on_args}"}
285
+ @parser.on(*on_args){|v|set_option(option_symbol, self.class.get_from_list(v.to_s, help, values), 'cmdline')}
286
286
  end
287
287
 
288
- def add_opt_boolean(option_symbol,help,*on_args)
289
- add_opt_list(option_symbol,BOOLEAN_VALUES,help,*on_args)
288
+ def add_opt_boolean(option_symbol, help, *on_args)
289
+ add_opt_list(option_symbol, BOOLEAN_VALUES, help, *on_args)
290
290
  # if default was defined for obj, it may still be enum (yes/no) instead of boolean
291
- default_value=get_option(option_symbol)
292
- set_option(option_symbol,default_value,'opt boolean') unless default_value.nil?
291
+ default_value = get_option(option_symbol)
292
+ set_option(option_symbol, default_value, 'opt boolean') unless default_value.nil?
293
293
  end
294
294
 
295
295
  # define an option with open values
296
- def add_opt_simple(option_symbol,*on_args)
297
- declare_option(option_symbol,:value)
298
- Log.log.debug("add_opt_simple #{option_symbol}")
299
- on_args.unshift(symbol_to_option(option_symbol,'VALUE'))
300
- Log.log.debug("on_args=#{on_args}")
301
- @parser.on(*on_args) { |v| set_option(option_symbol,v,'cmdline') }
296
+ def add_opt_simple(option_symbol, *on_args)
297
+ declare_option(option_symbol, :value)
298
+ Log.log.debug{"add_opt_simple #{option_symbol}"}
299
+ on_args.unshift(symbol_to_option(option_symbol, 'VALUE'))
300
+ Log.log.debug{"on_args=#{on_args}"}
301
+ @parser.on(*on_args) { |v| set_option(option_symbol, v, 'cmdline') }
302
302
  end
303
303
 
304
304
  # define an option with date format
305
- def add_opt_date(option_symbol,*on_args)
306
- declare_option(option_symbol,:value)
307
- Log.log.debug("add_opt_date #{option_symbol}")
308
- on_args.unshift(symbol_to_option(option_symbol,'DATE'))
309
- Log.log.debug("on_args=#{on_args}")
305
+ def add_opt_date(option_symbol, *on_args)
306
+ declare_option(option_symbol, :value)
307
+ Log.log.debug{"add_opt_date #{option_symbol}"}
308
+ on_args.unshift(symbol_to_option(option_symbol, 'DATE'))
309
+ Log.log.debug{"on_args=#{on_args}"}
310
310
  @parser.on(*on_args) do |v|
311
311
  case v
312
- when 'now' then set_option(option_symbol,Manager.time_to_string(Time.now),'cmdline')
313
- when /^-([0-9]+)h/ then set_option(option_symbol,Manager.time_to_string(Time.now - (3600 * Regexp.last_match(1).to_i)),'cmdline')
314
- else set_option(option_symbol,v,'cmdline')
312
+ when 'now' then set_option(option_symbol, Manager.time_to_string(Time.now), 'cmdline')
313
+ when /^-([0-9]+)h/ then set_option(option_symbol, Manager.time_to_string(Time.now - (Regexp.last_match(1).to_i * 3600)), 'cmdline')
314
+ else set_option(option_symbol, v, 'cmdline')
315
315
  end
316
316
  end
317
317
  end
318
318
 
319
319
  # define an option without value
320
- def add_opt_switch(option_symbol,*on_args,&block)
321
- Log.log.debug("add_opt_on #{option_symbol}")
322
- on_args.unshift(symbol_to_option(option_symbol,nil))
323
- Log.log.debug("on_args=#{on_args}")
324
- @parser.on(*on_args,&block)
320
+ def add_opt_switch(option_symbol, *on_args, &block)
321
+ Log.log.debug{"add_opt_on #{option_symbol}"}
322
+ on_args.unshift(symbol_to_option(option_symbol, nil))
323
+ Log.log.debug{"on_args=#{on_args}"}
324
+ @parser.on(*on_args, &block)
325
325
  end
326
326
 
327
327
  # check if there were unprocessed values to generate error
@@ -347,13 +347,13 @@ module Aspera
347
347
  when /^--([^=]+)=(.*)$/
348
348
  name = Regexp.last_match(1)
349
349
  value = Regexp.last_match(2)
350
- name.gsub!(OPTION_SEP_LINE,OPTION_SEP_NAME)
350
+ name.gsub!(OPTION_SEP_LINE, OPTION_SEP_NAME)
351
351
  value = ExtendedValue.instance.evaluate(value)
352
- Log.log.debug("option #{name}=#{value}")
352
+ Log.log.debug{"option #{name}=#{value}"}
353
353
  result[name] = value
354
354
  @unprocessed_cmd_line_options.delete(optionval) if remove_from_remaining
355
355
  else
356
- raise CliBadArgument,"wrong option format: #{optionval}"
356
+ raise CliBadArgument, "wrong option format: #{optionval}"
357
357
  end
358
358
  end
359
359
  return result
@@ -362,7 +362,7 @@ module Aspera
362
362
  # return options as taken from config file and command line just before command execution
363
363
  def declared_options(only_defined: false)
364
364
  result = {}
365
- @declared_options.keys.each do |option_symb|
365
+ @declared_options.each_key do |option_symb|
366
366
  v = get_option(option_symb)
367
367
  result[option_symb.to_s] = v unless only_defined && v.nil?
368
368
  end
@@ -373,8 +373,8 @@ module Aspera
373
373
  def parse_options!
374
374
  Log.log.debug('parse_options!'.red)
375
375
  # first conf file, then env var
376
- apply_options_preset(@unprocessed_defaults,'file')
377
- apply_options_preset(@unprocessed_env,'env')
376
+ apply_options_preset(@unprocessed_defaults, 'file')
377
+ apply_options_preset(@unprocessed_env, 'env')
378
378
  # command line override
379
379
  unknown_options = []
380
380
  begin
@@ -383,28 +383,28 @@ module Aspera
383
383
  @parser.parse!(@unprocessed_cmd_line_options)
384
384
  Log.log.debug('After parse'.red)
385
385
  rescue OptionParser::InvalidOption => e
386
- Log.log.debug("InvalidOption #{e}".red)
386
+ Log.log.debug{"InvalidOption #{e}".red}
387
387
  # save for later processing
388
388
  unknown_options.push(e.args.first)
389
389
  retry
390
390
  end
391
- Log.log.debug("remains: #{unknown_options}")
391
+ Log.log.debug{"remains: #{unknown_options}"}
392
392
  # set unprocessed options for next time
393
393
  @unprocessed_cmd_line_options = unknown_options
394
394
  end
395
395
 
396
396
  private
397
397
 
398
- def prompt_user_input(prompt,sensitive)
398
+ def prompt_user_input(prompt, sensitive)
399
399
  return $stdin.getpass("#{prompt}> ") if sensitive
400
400
  print("#{prompt}> ")
401
401
  return $stdin.gets.chomp
402
402
  end
403
403
 
404
- def get_interactive(type,descr,expected: :single)
404
+ def get_interactive(type, descr, expected: :single)
405
405
  if !@ask_missing_mandatory
406
- raise CliBadArgument,self.class.bad_arg_message_multi("missing: #{descr}",expected) if expected.is_a?(Array)
407
- raise CliBadArgument,"missing argument (#{expected}): #{descr}"
406
+ raise CliBadArgument, self.class.bad_arg_message_multi("missing: #{descr}", expected) if expected.is_a?(Array)
407
+ raise CliBadArgument, "missing argument (#{expected}): #{descr}"
408
408
  end
409
409
  result = nil
410
410
  sensitive = type.eql?(:option) && @declared_options[descr.to_sym][:sensitive]
@@ -415,21 +415,21 @@ module Aspera
415
415
  result = []
416
416
  puts(' (one per line, end with empty line)')
417
417
  loop do
418
- entry = prompt_user_input(default_prompt,sensitive)
418
+ entry = prompt_user_input(default_prompt, sensitive)
419
419
  break if entry.empty?
420
420
  result.push(ExtendedValue.instance.evaluate(entry))
421
421
  end
422
422
  when :single
423
- result = ExtendedValue.instance.evaluate(prompt_user_input(default_prompt,sensitive))
423
+ result = ExtendedValue.instance.evaluate(prompt_user_input(default_prompt, sensitive))
424
424
  else # one fixed
425
- result = self.class.get_from_list(prompt_user_input("#{expected.join(' ')}\n#{default_prompt}",sensitive),descr,expected)
425
+ result = self.class.get_from_list(prompt_user_input("#{expected.join(' ')}\n#{default_prompt}", sensitive), descr, expected)
426
426
  end
427
427
  return result
428
428
  end
429
429
 
430
430
  # generate command line option from option symbol
431
- def symbol_to_option(symbol,opt_val)
432
- result = '--' + symbol.to_s.gsub(OPTION_SEP_NAME,OPTION_SEP_LINE)
431
+ def symbol_to_option(symbol, opt_val)
432
+ result = '--' + symbol.to_s.gsub(OPTION_SEP_NAME, OPTION_SEP_LINE)
433
433
  result = result + '=' + opt_val unless opt_val.nil?
434
434
  return result
435
435
  end
@@ -438,16 +438,16 @@ module Aspera
438
438
  $stdout.isatty ? value.to_s.red.bold : "[#{value}]"
439
439
  end
440
440
 
441
- def apply_options_preset(preset,where)
441
+ def apply_options_preset(preset, where)
442
442
  unprocessed = []
443
443
  preset.each do |pair|
444
- k,v = *pair
445
- if @declared_options.has_key?(k)
444
+ k, v = *pair
445
+ if @declared_options.key?(k)
446
446
  # constrained parameters as string are revert to symbol
447
- if @declared_options[k].has_key?(:values) && v.is_a?(String)
448
- v = self.class.get_from_list(v,k.to_s + " in #{where}",@declared_options[k][:values])
447
+ if @declared_options[k].key?(:values) && v.is_a?(String)
448
+ v = self.class.get_from_list(v, k.to_s + " in #{where}", @declared_options[k][:values])
449
449
  end
450
- set_option(k,v,where)
450
+ set_option(k, v, where)
451
451
  else
452
452
  unprocessed.push(pair)
453
453
  end