aspera-cli 4.6.0 → 4.7.0

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 (96) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +427 -300
  3. data/bin/ascli +2 -1
  4. data/bin/asession +1 -0
  5. data/docs/test_env.conf +2 -0
  6. data/examples/aoc.rb +4 -3
  7. data/examples/faspex4.rb +21 -19
  8. data/examples/proxy.pac +1 -1
  9. data/examples/transfer.rb +15 -15
  10. data/lib/aspera/aoc.rb +135 -124
  11. data/lib/aspera/ascmd.rb +85 -75
  12. data/lib/aspera/ats_api.rb +11 -10
  13. data/lib/aspera/cli/basic_auth_plugin.rb +13 -14
  14. data/lib/aspera/cli/extended_value.rb +42 -33
  15. data/lib/aspera/cli/formater.rb +138 -111
  16. data/lib/aspera/cli/info.rb +17 -0
  17. data/lib/aspera/cli/listener/line_dump.rb +3 -2
  18. data/lib/aspera/cli/listener/logger.rb +2 -1
  19. data/lib/aspera/cli/listener/progress.rb +16 -18
  20. data/lib/aspera/cli/listener/progress_multi.rb +13 -16
  21. data/lib/aspera/cli/main.rb +122 -130
  22. data/lib/aspera/cli/manager.rb +146 -154
  23. data/lib/aspera/cli/plugin.rb +38 -34
  24. data/lib/aspera/cli/plugins/alee.rb +6 -6
  25. data/lib/aspera/cli/plugins/aoc.rb +273 -276
  26. data/lib/aspera/cli/plugins/ats.rb +82 -76
  27. data/lib/aspera/cli/plugins/bss.rb +14 -16
  28. data/lib/aspera/cli/plugins/config.rb +350 -306
  29. data/lib/aspera/cli/plugins/console.rb +23 -19
  30. data/lib/aspera/cli/plugins/cos.rb +18 -18
  31. data/lib/aspera/cli/plugins/faspex.rb +180 -159
  32. data/lib/aspera/cli/plugins/faspex5.rb +64 -54
  33. data/lib/aspera/cli/plugins/node.rb +147 -140
  34. data/lib/aspera/cli/plugins/orchestrator.rb +68 -66
  35. data/lib/aspera/cli/plugins/preview.rb +92 -96
  36. data/lib/aspera/cli/plugins/server.rb +79 -75
  37. data/lib/aspera/cli/plugins/shares.rb +23 -24
  38. data/lib/aspera/cli/plugins/sync.rb +20 -22
  39. data/lib/aspera/cli/transfer_agent.rb +40 -39
  40. data/lib/aspera/cli/version.rb +2 -1
  41. data/lib/aspera/colors.rb +35 -27
  42. data/lib/aspera/command_line_builder.rb +48 -34
  43. data/lib/aspera/cos_node.rb +29 -21
  44. data/lib/aspera/data_repository.rb +3 -2
  45. data/lib/aspera/environment.rb +50 -45
  46. data/lib/aspera/fasp/agent_base.rb +22 -20
  47. data/lib/aspera/fasp/agent_connect.rb +13 -11
  48. data/lib/aspera/fasp/agent_direct.rb +48 -59
  49. data/lib/aspera/fasp/agent_httpgw.rb +33 -39
  50. data/lib/aspera/fasp/agent_node.rb +15 -13
  51. data/lib/aspera/fasp/agent_trsdk.rb +12 -14
  52. data/lib/aspera/fasp/error.rb +2 -1
  53. data/lib/aspera/fasp/error_info.rb +68 -52
  54. data/lib/aspera/fasp/installation.rb +106 -94
  55. data/lib/aspera/fasp/listener.rb +1 -0
  56. data/lib/aspera/fasp/parameters.rb +83 -92
  57. data/lib/aspera/fasp/parameters.yaml +305 -249
  58. data/lib/aspera/fasp/resume_policy.rb +11 -14
  59. data/lib/aspera/fasp/transfer_spec.rb +26 -0
  60. data/lib/aspera/fasp/uri.rb +22 -21
  61. data/lib/aspera/faspex_gw.rb +55 -90
  62. data/lib/aspera/hash_ext.rb +4 -3
  63. data/lib/aspera/id_generator.rb +8 -7
  64. data/lib/aspera/keychain/encrypted_hash.rb +17 -16
  65. data/lib/aspera/keychain/macos_security.rb +6 -10
  66. data/lib/aspera/log.rb +25 -20
  67. data/lib/aspera/nagios.rb +13 -12
  68. data/lib/aspera/node.rb +30 -22
  69. data/lib/aspera/oauth.rb +175 -226
  70. data/lib/aspera/open_application.rb +4 -3
  71. data/lib/aspera/persistency_action_once.rb +6 -6
  72. data/lib/aspera/persistency_folder.rb +5 -9
  73. data/lib/aspera/preview/file_types.rb +6 -5
  74. data/lib/aspera/preview/generator.rb +25 -24
  75. data/lib/aspera/preview/options.rb +16 -14
  76. data/lib/aspera/preview/utils.rb +98 -98
  77. data/lib/aspera/{proxy_auto_config.erb.js → proxy_auto_config.js} +23 -31
  78. data/lib/aspera/proxy_auto_config.rb +111 -20
  79. data/lib/aspera/rest.rb +115 -113
  80. data/lib/aspera/rest_call_error.rb +2 -2
  81. data/lib/aspera/rest_error_analyzer.rb +23 -25
  82. data/lib/aspera/rest_errors_aspera.rb +15 -14
  83. data/lib/aspera/ssh.rb +12 -10
  84. data/lib/aspera/sync.rb +42 -41
  85. data/lib/aspera/temp_file_manager.rb +18 -14
  86. data/lib/aspera/timer_limiter.rb +2 -1
  87. data/lib/aspera/uri_reader.rb +7 -5
  88. data/lib/aspera/web_auth.rb +79 -76
  89. metadata +64 -21
  90. data/docs/Makefile +0 -65
  91. data/docs/README.erb.md +0 -4424
  92. data/docs/README.md +0 -13
  93. data/docs/diagrams.txt +0 -49
  94. data/docs/doc_tools.rb +0 -58
  95. data/lib/aspera/cli/plugins/shares2.rb +0 -114
  96. data/lib/aspera/fasp/default.rb +0 -17
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require 'aspera/cli/manager'
2
3
  require 'aspera/cli/formater'
3
4
  require 'aspera/cli/plugins/config'
4
5
  require 'aspera/cli/extended_value'
5
6
  require 'aspera/cli/transfer_agent'
6
7
  require 'aspera/cli/version'
8
+ require 'aspera/cli/info'
7
9
  require 'aspera/fasp/error'
8
10
  require 'aspera/open_application'
9
11
  require 'aspera/temp_file_manager'
@@ -11,38 +13,74 @@ require 'aspera/persistency_folder'
11
13
  require 'aspera/log'
12
14
  require 'aspera/rest'
13
15
  require 'aspera/nagios'
16
+ require 'aspera/colors'
14
17
 
15
18
  module Aspera
16
19
  module Cli
17
20
  # The main CLI class
18
21
  class Main
22
+ # prefix to display error messages
23
+ ERROR_FLASH='ERROR:'.bg_red.gray.blink.freeze
24
+ private_constant :ERROR_FLASH
19
25
 
20
- private
21
- # name of application, also used as foldername where config is stored
22
- PROGRAM_NAME = 'ascli'
23
- # name of the containing gem, same as in <gem name>.gemspec
24
- GEM_NAME = 'aspera-cli'
25
- HELP_URL = "http://www.rubydoc.info/gems/#{GEM_NAME}"
26
- GEM_URL = "https://rubygems.org/gems/#{GEM_NAME}"
27
- SRC_URL = 'https://github.com/IBM/aspera-cli'
28
26
  # store transfer result using this key and use result_transfer_multiple
29
27
  STATUS_FIELD = 'status'
30
28
 
31
- private_constant :PROGRAM_NAME,:GEM_NAME,:HELP_URL,:GEM_URL
29
+ class << self
30
+ # expect some list, but nothing to display
31
+ def result_empty; return {type: :empty, data: :nil}; end
32
+
33
+ # nothing expected
34
+ def result_nothing; return {type: :nothing, data: :nil}; end
35
+
36
+ def result_status(status); return {type: :status, data: status}; end
37
+
38
+ def result_success; return result_status('complete'); end
39
+
40
+ # Process statuses of finished transfer sessions
41
+ # raise exception if there is one error
42
+ # else returns an empty status
43
+ def result_transfer(statuses)
44
+ worst=TransferAgent.session_status(statuses)
45
+ raise worst unless worst.eql?(:success)
46
+ return Main.result_nothing
47
+ end
48
+
49
+ # used when one command executes several transfer jobs (each job being possibly multi session)
50
+ # @param status_table [Array] [{STATUS_FIELD=>[status array],...},...]
51
+ # @return a status object suitable as command result
52
+ # each element has a key STATUS_FIELD which contains the result of possibly multiple sessions
53
+ def result_transfer_multiple(status_table)
54
+ global_status=:success
55
+ # transform status array into string and find if there was problem
56
+ status_table.each do |item|
57
+ worst=TransferAgent.session_status(item[STATUS_FIELD])
58
+ global_status=worst unless worst.eql?(:success)
59
+ item[STATUS_FIELD]=item[STATUS_FIELD].map(&:to_s).join(',')
60
+ end
61
+ raise global_status unless global_status.eql?(:success)
62
+ return {type: :object_list,data: status_table}
63
+ end
64
+ end
65
+
66
+ private
67
+
32
68
  # =============================================================
33
69
  # Parameter handlers
34
70
  #
35
- attr_accessor :option_insecure, :option_http_options
71
+ attr_accessor :option_insecure, :option_http_options, :option_cache_tokens
72
+
36
73
  def option_ui; OpenApplication.instance.url_method; end
37
74
 
38
75
  def option_ui=(value); OpenApplication.instance.url_method=value; end
39
76
 
40
77
  # called everytime a new REST HTTP session is opened
41
78
  # @param http [Net::HTTP] the newly created http session object
42
- def set_http_parameters(http)
79
+ def http_parameters=(http)
43
80
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @option_insecure
44
81
  http.set_debug_output($stdout) if @option_rest_debug
45
82
  raise 'http_options expects Hash' unless @option_http_options.is_a?(Hash)
83
+
46
84
  @option_http_options.each do |k,v|
47
85
  method="#{k}=".to_sym
48
86
  # check if accessor is a method of Net::HTTP
@@ -61,14 +99,13 @@ module Aspera
61
99
  early_debug_setup(argv)
62
100
  # compare $0 with expected name
63
101
  current_prog_name=File.basename($PROGRAM_NAME)
64
- unless current_prog_name.eql?(PROGRAM_NAME)
65
- @plugin_env[:formater].display_message(:error,"#{"WARNING".bg_red.blink.gray} Please use '#{PROGRAM_NAME}' instead of '#{current_prog_name}', '#{current_prog_name}' will be removed in a future version")
66
- end
102
+ @plugin_env[:formater].display_message(:error,"#{'WARNING'.bg_red.blink.gray} Please use '#{PROGRAM_NAME}' instead of '#{current_prog_name}'") unless current_prog_name.eql?(PROGRAM_NAME)
67
103
  @option_help=false
68
104
  @bash_completion=false
69
105
  @option_show_config=false
70
106
  @option_insecure=false
71
107
  @option_rest_debug=false
108
+ @option_cache_tokens=true
72
109
  @option_http_options={}
73
110
  # environment provided to plugin for various capabilities
74
111
  @plugin_env={}
@@ -77,47 +114,57 @@ module Aspera
77
114
  # formatter adds options
78
115
  @plugin_env[:formater]=Formater.new(@plugin_env[:options])
79
116
  Rest.user_agent=PROGRAM_NAME
80
- Rest.session_cb=lambda {|http| set_http_parameters(http)}
117
+ Rest.session_cb=lambda{|http|self.http_parameters=http}
81
118
  # declare and parse global options
82
119
  init_global_options()
83
120
  # the Config plugin adds the @preset parser, so declare before TransferAgent which may use it
84
- @plugin_env[:config]=Plugins::Config.new(@plugin_env,PROGRAM_NAME,HELP_URL,Aspera::Cli::VERSION,app_main_folder)
121
+ @plugin_env[:config]=Plugins::Config.new(@plugin_env, gem: GEM_NAME, name: PROGRAM_NAME, help: DOC_URL, version: Aspera::Cli::VERSION)
85
122
  # the TransferAgent plugin may use the @preset parser
86
123
  @plugin_env[:transfer]=TransferAgent.new(@plugin_env[:options],@plugin_env[:config])
87
124
  # data persistency
88
125
  @plugin_env[:persistency]=PersistencyFolder.new(File.join(@plugin_env[:config].main_folder,'persist_store'))
89
126
  Log.log.debug('plugin env created'.red)
90
- Oauth.persist_mgr=@plugin_env[:persistency]
127
+ Oauth.persist_mgr=@plugin_env[:persistency] if @option_cache_tokens
91
128
  Fasp::Parameters.file_list_folder=File.join(@plugin_env[:config].main_folder,'filelists')
92
129
  Aspera::RestErrorAnalyzer.instance.log_file=File.join(@plugin_env[:config].main_folder,'rest_exceptions.log')
93
130
  # register aspera REST call error handlers
94
- Aspera::RestErrorsAspera.registerHandlers
131
+ Aspera::RestErrorsAspera.register_handlers
95
132
  # set banner when all environment is created so that additional extended value modifiers are known, e.g. @preset
96
133
  @opt_mgr.parser.banner=app_banner
97
134
  end
98
135
 
99
136
  def app_banner
100
- banner = "NAME\n\t#{PROGRAM_NAME} -- a command line tool for Aspera Applications (v#{Aspera::Cli::VERSION})\n\n"
101
- banner << "SYNOPSIS\n"
102
- banner << "\t#{PROGRAM_NAME} COMMANDS [OPTIONS] [ARGS]\n"
103
- banner << "\nDESCRIPTION\n"
104
- banner << "\tUse Aspera application to perform operations on command line.\n"
105
- banner << "\tDocumentation and examples: #{GEM_URL}\n"
106
- banner << "\texecute: #{PROGRAM_NAME} conf doc\n"
107
- banner << "\tor visit: #{HELP_URL}\n"
108
- banner << "\tsource repo: #{SRC_URL}\n"
109
- banner << "\nENVIRONMENT VARIABLES\n"
110
- banner << "\t#{conf_dir_env_var} config folder, default: $HOME/#{Plugins::Config::ASPERA_HOME_FOLDER_NAME}/#{PROGRAM_NAME}\n"
111
- banner << "\tany option can be set as an environment variable, refer to the manual\n"
112
- banner << "\nCOMMANDS\n"
113
- banner << "\tTo list first level commands, execute: #{PROGRAM_NAME}\n"
114
- banner << "\tNote that commands can be written shortened (provided it is unique).\n"
115
- banner << "\nOPTIONS\n"
116
- banner << "\tOptions begin with a '-' (minus), and value is provided on command line.\n"
117
- banner << "\tSpecial values are supported beginning with special prefix @pfx:, where pfx is one of:\n\t#{ExtendedValue.instance.modifiers.map{|m|m.to_s}.join(', ')}\n"
118
- banner << "\tDates format is 'DD-MM-YY HH:MM:SS', or 'now' or '-<num>h'\n\n"
119
- banner << "ARGS\n"
120
- banner << "\tSome commands require mandatory arguments, e.g. a path.\n"
137
+ return <<~END_OF_BANNER
138
+ NAME
139
+ \t#{PROGRAM_NAME} -- a command line tool for Aspera Applications (v#{Aspera::Cli::VERSION})
140
+
141
+ SYNOPSIS
142
+ \t#{PROGRAM_NAME} COMMANDS [OPTIONS] [ARGS]
143
+
144
+ DESCRIPTION
145
+ \tUse Aspera application to perform operations on command line.
146
+ \tDocumentation and examples: #{GEM_URL}
147
+ \texecute: #{PROGRAM_NAME} conf doc
148
+ \tor visit: #{DOC_URL}
149
+ \tsource repo: #{SRC_URL}
150
+
151
+ ENVIRONMENT VARIABLES
152
+ \t#{@plugin_env[:config].conf_dir_env_var} config folder, default: $HOME/#{Plugins::Config::ASPERA_HOME_FOLDER_NAME}/#{PROGRAM_NAME}
153
+ \tAny option can be set as an environment variable, refer to the manual
154
+
155
+ COMMANDS
156
+ \tTo list first level commands, execute: #{PROGRAM_NAME}
157
+ \tNote that commands can be written shortened (provided it is unique).
158
+
159
+ OPTIONS
160
+ \tOptions begin with a '-' (minus), and value is provided on command line.
161
+ \tSpecial values are supported beginning with special prefix @pfx:, where pfx is one of:
162
+ \t#{ExtendedValue.instance.modifiers.map(&:to_s).join(', ')}
163
+ \tDates format is 'DD-MM-YY HH:MM:SS', or 'now' or '-<num>h'
164
+
165
+ ARGS
166
+ \tSome commands require mandatory arguments, e.g. a path.
167
+ END_OF_BANNER
121
168
  end
122
169
 
123
170
  # define header for manual
@@ -135,7 +182,8 @@ module Aspera
135
182
  @opt_mgr.set_obj_attr(:insecure,self,:option_insecure,:no)
136
183
  @opt_mgr.set_obj_attr(:ui,self,:option_ui)
137
184
  @opt_mgr.set_obj_attr(:http_options,self,:option_http_options)
138
- @opt_mgr.set_obj_attr(:log_passwords,Log.instance,:log_passwords)
185
+ @opt_mgr.set_obj_attr(:log_secrets,Log.instance,:log_secrets)
186
+ @opt_mgr.set_obj_attr(:cache_tokens,self,:option_cache_tokens)
139
187
  @opt_mgr.add_opt_list(:ui,OpenApplication.user_interfaces,'method to start browser')
140
188
  @opt_mgr.add_opt_list(:log_level,Log.levels,'Log level')
141
189
  @opt_mgr.add_opt_list(:logger,Log.logtypes,'log method')
@@ -144,9 +192,10 @@ module Aspera
144
192
  @opt_mgr.add_opt_simple(:http_options,'options for http socket (extended value)')
145
193
  @opt_mgr.add_opt_boolean(:insecure,'do not validate HTTPS certificate')
146
194
  @opt_mgr.add_opt_boolean(:once_only,'process only new items (some commands)')
147
- @opt_mgr.add_opt_boolean(:log_passwords,'show passwords in logs')
195
+ @opt_mgr.add_opt_boolean(:log_secrets,'show passwords in logs')
196
+ @opt_mgr.add_opt_boolean(:cache_tokens,'save and reuse Oauth tokens')
148
197
  @opt_mgr.set_option(:ui,OpenApplication.default_gui_mode)
149
- @opt_mgr.set_option(:once_only,:false)
198
+ @opt_mgr.set_option(:once_only,false)
150
199
  # parse declared options
151
200
  @opt_mgr.parse_options!
152
201
  end
@@ -175,16 +224,6 @@ module Aspera
175
224
  Process.exit(0)
176
225
  end
177
226
 
178
- # expect some list, but nothing to display
179
- def self.result_empty; return {:type => :empty, :data => :nil }; end
180
-
181
- # nothing expected
182
- def self.result_nothing; return {:type => :nothing, :data => :nil }; end
183
-
184
- def self.result_status(status); return {:type => :status, :data => status }; end
185
-
186
- def self.result_success; return result_status('complete'); end
187
-
188
227
  def exit_with_usage(all_plugins)
189
228
  Log.log.debug('exit_with_usage'.bg_red)
190
229
  # display main plugin options
@@ -208,67 +247,21 @@ module Aspera
208
247
 
209
248
  protected
210
249
 
211
- # env var name to override the app's main folder
212
- # default main folder is $HOME/<vendor main app folder>/<program name>
213
- def conf_dir_env_var
214
- return "#{PROGRAM_NAME}_home".upcase
215
- end
216
-
217
- def app_main_folder
218
- # find out application main folder
219
- app_folder=ENV[conf_dir_env_var]
220
- # if env var undefined or empty
221
- if app_folder.nil? or app_folder.empty?
222
- user_home_folder=Dir.home
223
- raise CliError,"Home folder does not exist: #{user_home_folder}. Check your user environment or use #{conf_dir_env_var}." unless Dir.exist?(user_home_folder)
224
- app_folder=File.join(user_home_folder,Plugins::Config::ASPERA_HOME_FOLDER_NAME,PROGRAM_NAME)
225
- end
226
- return app_folder
227
- end
228
-
229
250
  # early debug for parser
230
251
  # Note: does not accept shortcuts
231
252
  def early_debug_setup(argv)
232
253
  Log.instance.program_name=PROGRAM_NAME
233
254
  argv.each do |arg|
234
255
  case arg
235
- when '--'
236
- return
237
- when /^--log-level=(.*)/
238
- Log.instance.level = $1.to_sym
239
- when /^--logger=(.*)/
240
- Log.instance.logger_type=$1.to_sym
256
+ when '--' then break
257
+ when /^--log-level=(.*)/ then Log.instance.level = Regexp.last_match(1).to_sym
258
+ when /^--logger=(.*)/ then Log.instance.logger_type=Regexp.last_match(1).to_sym
241
259
  end
242
260
  end
243
261
  end
244
262
 
245
263
  public
246
264
 
247
- # Process statuses of finished transfer sessions
248
- # raise exception if there is one error
249
- # else returns an empty status
250
- def self.result_transfer(statuses)
251
- worst=TransferAgent.session_status(statuses)
252
- raise worst unless worst.eql?(:success)
253
- return Main.result_nothing
254
- end
255
-
256
- # used when one command executes several transfer jobs (each job being possibly multi session)
257
- # @param status_table [Array] [{STATUS_FIELD=>[status array],...},...]
258
- # @return a status object suitable as command result
259
- # each element has a key STATUS_FIELD which contains the result of possibly multiple sessions
260
- def self.result_transfer_multiple(status_table)
261
- global_status=:success
262
- # transform status array into string and find if there was problem
263
- status_table.each do |item|
264
- worst=TransferAgent.session_status(item[STATUS_FIELD])
265
- global_status=worst unless worst.eql?(:success)
266
- item[STATUS_FIELD]=item[STATUS_FIELD].map{|i|i.to_s}.join(',')
267
- end
268
- raise global_status unless global_status.eql?(:success)
269
- return {:type=>:object_list,:data=>status_table}
270
- end
271
-
272
265
  # this is the main function called by initial script just after constructor
273
266
  def process_command_line
274
267
  Log.log.debug('process_command_line')
@@ -280,16 +273,17 @@ module Aspera
280
273
  # find plugins, shall be after parse! ?
281
274
  @plugin_env[:config].add_plugins_from_lookup_folders
282
275
  # help requested without command ? (plugins must be known here)
283
- exit_with_usage(true) if @option_help and @opt_mgr.command_or_arg_empty?
276
+ exit_with_usage(true) if @option_help && @opt_mgr.command_or_arg_empty?
284
277
  generate_bash_completion if @bash_completion
285
278
  @plugin_env[:config].periodic_check_newer_gem_version
286
- if @option_show_config and @opt_mgr.command_or_arg_empty?
287
- command_sym=Plugins::Config::CONF_PLUGIN_SYM
279
+ command_sym=
280
+ if @option_show_config && @opt_mgr.command_or_arg_empty?
281
+ Plugins::Config::CONF_PLUGIN_SYM
288
282
  else
289
- command_sym=@opt_mgr.get_next_command(@plugin_env[:config].plugins.keys.dup.unshift(:help))
283
+ @opt_mgr.get_next_command(@plugin_env[:config].plugins.keys.dup.unshift(:help))
290
284
  end
291
285
  # command will not be executed, but we need manual
292
- @opt_mgr.fail_on_missing_mandatory=false if @option_help
286
+ @opt_mgr.fail_on_missing_mandatory=false if @option_help || @option_show_config
293
287
  # main plugin is not dynamically instanciated
294
288
  case command_sym
295
289
  when :help
@@ -305,8 +299,8 @@ module Aspera
305
299
  # help requested for current plugin
306
300
  exit_with_usage(false) if @option_help
307
301
  if @option_show_config
308
- @plugin_env[:formater].display_results({:type=>:single_object,:data=>@opt_mgr.declared_options(false)})
309
- Process.exit(0)
302
+ @plugin_env[:formater].display_results({type: :single_object,data: @opt_mgr.declared_options(only_defined: true)})
303
+ execute_command=false
310
304
  end
311
305
  # locking for single execution (only after "per plugin" option, in case lock port is there)
312
306
  lock_port=@opt_mgr.get_option(:lock_port,:optional)
@@ -315,7 +309,7 @@ module Aspera
315
309
  # no need to close later, will be freed on process exit. must save in member else it is garbage collected
316
310
  Log.log.debug("Opening lock port #{lock_port.to_i}")
317
311
  @tcp_server=TCPServer.new('127.0.0.1',lock_port.to_i)
318
- rescue => e
312
+ rescue StandardError => e
319
313
  execute_command=false
320
314
  Log.log.warn("Another instance is already running (#{e.message}).")
321
315
  end
@@ -324,42 +318,40 @@ module Aspera
324
318
  @plugin_env[:formater].display_results(command_plugin.execute_action) if execute_command
325
319
  # finish
326
320
  @plugin_env[:transfer].shutdown
327
- rescue CliBadArgument => e; exception_info=[e,'Argument',:usage]
328
- rescue CliNoSuchId => e; exception_info=[e,'Identifier']
329
- rescue CliError => e; exception_info=[e,'Tool',:usage]
330
- rescue Fasp::Error => e; exception_info=[e,'FASP(ascp)']
331
- rescue Aspera::RestCallError => e; exception_info=[e,'Rest']
332
- rescue SocketError => e; exception_info=[e,'Network']
333
- rescue StandardError => e; exception_info=[e,'Other',:debug]
334
- rescue Interrupt => e; exception_info=[e,'Interruption',:debug]
321
+ rescue CliBadArgument => e; exception_info={e: e,t: 'Argument',usage: true}
322
+ rescue CliNoSuchId => e; exception_info={e: e,t: 'Identifier'}
323
+ rescue CliError => e; exception_info={e: e,t: 'Tool',usage: true}
324
+ rescue Fasp::Error => e; exception_info={e: e,t: 'FASP(ascp)'}
325
+ rescue Aspera::RestCallError => e; exception_info={e: e,t: 'Rest'}
326
+ rescue SocketError => e; exception_info={e: e,t: 'Network'}
327
+ rescue StandardError => e; exception_info={e: e,t: 'Other',debug: true}
328
+ rescue Interrupt => e; exception_info={e: e,t: 'Interruption',debug: true}
335
329
  end
336
330
  # cleanup file list files
337
331
  TempFileManager.instance.cleanup
338
332
  # 1- processing of error condition
339
333
  unless exception_info.nil?
340
- @plugin_env[:formater].display_message(:error,"#{'ERROR:'.bg_red.gray.blink} #{exception_info[1]}: #{exception_info[0].message}")
341
- @plugin_env[:formater].display_message(:error,'Use option -h to get help.') if exception_info[2].eql?(:usage)
342
- if exception_info.first.is_a?(Fasp::Error) and exception_info.first.message.eql?('Remote host is not who we expected')
334
+ @plugin_env[:formater].display_message(:error,"#{ERROR_FLASH} #{exception_info[:t]}: #{exception_info[:e].message}")
335
+ @plugin_env[:formater].display_message(:error,'Use option -h to get help.') if exception_info[:usage]
336
+ if exception_info[:e].is_a?(Fasp::Error) && exception_info[:e].message.eql?('Remote host is not who we expected')
343
337
  @plugin_env[:formater].display_message(:error,"For this specific error, refer to:\n#{SRC_URL}#error-remote-host-is-not-who-we-expected\nAdd this to arguments:\n--ts=@json:'{\"sshfp\":null}'")
344
338
  end
345
339
  end
346
340
  # 2- processing of command not processed (due to exception or bad command line)
347
- if execute_command
341
+ if execute_command || @option_show_config
348
342
  @opt_mgr.final_errors.each do |msg|
349
- @plugin_env[:formater].display_message(:error,"#{'ERROR:'.bg_red.gray.blink} Argument: #{msg}")
343
+ @plugin_env[:formater].display_message(:error,"#{ERROR_FLASH} Argument: #{msg}")
350
344
  # add code as exception if there is not already an error
351
- exception_info=[Exception.new(msg),'UnusedArg'] if exception_info.nil?
345
+ exception_info={e: Exception.new(msg),t: 'UnusedArg'} if exception_info.nil?
352
346
  end
353
347
  end
354
348
  # 3- in case of error, fail the process status
355
349
  unless exception_info.nil?
356
- if Log.instance.level.eql?(:debug)
357
- # will force to show stack trace
358
- raise exception_info[0]
359
- else
360
- @plugin_env[:formater].display_message(:error,'Use --log-level=debug to get more details.') if exception_info[2].eql?(:debug)
361
- Process.exit(1)
362
- end
350
+ # show stack trace in debug mode
351
+ raise exception_info[:e] if Log.instance.level.eql?(:debug)
352
+ # else give hint and exit
353
+ @plugin_env[:formater].display_message(:error,'Use --log-level=debug to get more details.') if exception_info[:debug]
354
+ Process.exit(1)
363
355
  end
364
356
  return nil
365
357
  end # process_command_line