aspera-cli 4.0.0.pre1

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 (88) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +3592 -0
  3. data/bin/ascli +7 -0
  4. data/bin/asession +89 -0
  5. data/docs/Makefile +59 -0
  6. data/docs/README.erb.md +3012 -0
  7. data/docs/README.md +13 -0
  8. data/docs/diagrams.txt +49 -0
  9. data/docs/secrets.make +38 -0
  10. data/docs/test_env.conf +117 -0
  11. data/docs/transfer_spec.html +99 -0
  12. data/examples/aoc.rb +17 -0
  13. data/examples/proxy.pac +60 -0
  14. data/examples/transfer.rb +115 -0
  15. data/lib/aspera/api_detector.rb +60 -0
  16. data/lib/aspera/ascmd.rb +151 -0
  17. data/lib/aspera/ats_api.rb +43 -0
  18. data/lib/aspera/cli/basic_auth_plugin.rb +38 -0
  19. data/lib/aspera/cli/extended_value.rb +88 -0
  20. data/lib/aspera/cli/formater.rb +238 -0
  21. data/lib/aspera/cli/listener/line_dump.rb +17 -0
  22. data/lib/aspera/cli/listener/logger.rb +20 -0
  23. data/lib/aspera/cli/listener/progress.rb +52 -0
  24. data/lib/aspera/cli/listener/progress_multi.rb +91 -0
  25. data/lib/aspera/cli/main.rb +304 -0
  26. data/lib/aspera/cli/manager.rb +440 -0
  27. data/lib/aspera/cli/plugin.rb +90 -0
  28. data/lib/aspera/cli/plugins/alee.rb +24 -0
  29. data/lib/aspera/cli/plugins/ats.rb +231 -0
  30. data/lib/aspera/cli/plugins/bss.rb +71 -0
  31. data/lib/aspera/cli/plugins/config.rb +806 -0
  32. data/lib/aspera/cli/plugins/console.rb +62 -0
  33. data/lib/aspera/cli/plugins/cos.rb +106 -0
  34. data/lib/aspera/cli/plugins/faspex.rb +377 -0
  35. data/lib/aspera/cli/plugins/faspex5.rb +93 -0
  36. data/lib/aspera/cli/plugins/node.rb +438 -0
  37. data/lib/aspera/cli/plugins/oncloud.rb +937 -0
  38. data/lib/aspera/cli/plugins/orchestrator.rb +169 -0
  39. data/lib/aspera/cli/plugins/preview.rb +464 -0
  40. data/lib/aspera/cli/plugins/server.rb +216 -0
  41. data/lib/aspera/cli/plugins/shares.rb +63 -0
  42. data/lib/aspera/cli/plugins/shares2.rb +114 -0
  43. data/lib/aspera/cli/plugins/sync.rb +65 -0
  44. data/lib/aspera/cli/plugins/xnode.rb +115 -0
  45. data/lib/aspera/cli/transfer_agent.rb +251 -0
  46. data/lib/aspera/cli/version.rb +5 -0
  47. data/lib/aspera/colors.rb +39 -0
  48. data/lib/aspera/command_line_builder.rb +137 -0
  49. data/lib/aspera/fasp/aoc.rb +24 -0
  50. data/lib/aspera/fasp/connect.rb +99 -0
  51. data/lib/aspera/fasp/error.rb +21 -0
  52. data/lib/aspera/fasp/error_info.rb +60 -0
  53. data/lib/aspera/fasp/http_gw.rb +81 -0
  54. data/lib/aspera/fasp/installation.rb +240 -0
  55. data/lib/aspera/fasp/listener.rb +11 -0
  56. data/lib/aspera/fasp/local.rb +377 -0
  57. data/lib/aspera/fasp/manager.rb +69 -0
  58. data/lib/aspera/fasp/node.rb +88 -0
  59. data/lib/aspera/fasp/parameters.rb +235 -0
  60. data/lib/aspera/fasp/resume_policy.rb +76 -0
  61. data/lib/aspera/fasp/uri.rb +51 -0
  62. data/lib/aspera/faspex_gw.rb +196 -0
  63. data/lib/aspera/hash_ext.rb +28 -0
  64. data/lib/aspera/log.rb +80 -0
  65. data/lib/aspera/nagios.rb +71 -0
  66. data/lib/aspera/node.rb +14 -0
  67. data/lib/aspera/oauth.rb +319 -0
  68. data/lib/aspera/on_cloud.rb +421 -0
  69. data/lib/aspera/open_application.rb +72 -0
  70. data/lib/aspera/persistency_action_once.rb +42 -0
  71. data/lib/aspera/persistency_folder.rb +91 -0
  72. data/lib/aspera/preview/file_types.rb +300 -0
  73. data/lib/aspera/preview/generator.rb +258 -0
  74. data/lib/aspera/preview/image_error.png +0 -0
  75. data/lib/aspera/preview/options.rb +35 -0
  76. data/lib/aspera/preview/utils.rb +131 -0
  77. data/lib/aspera/preview/video_error.png +0 -0
  78. data/lib/aspera/proxy_auto_config.erb.js +287 -0
  79. data/lib/aspera/proxy_auto_config.rb +34 -0
  80. data/lib/aspera/rest.rb +296 -0
  81. data/lib/aspera/rest_call_error.rb +13 -0
  82. data/lib/aspera/rest_error_analyzer.rb +98 -0
  83. data/lib/aspera/rest_errors_aspera.rb +58 -0
  84. data/lib/aspera/ssh.rb +53 -0
  85. data/lib/aspera/sync.rb +82 -0
  86. data/lib/aspera/temp_file_manager.rb +37 -0
  87. data/lib/aspera/uri_reader.rb +25 -0
  88. metadata +288 -0
@@ -0,0 +1,17 @@
1
+ require 'aspera/fasp/listener'
2
+ require 'json'
3
+
4
+ module Aspera
5
+ module Cli
6
+ module Listener
7
+ # listener for FASP transfers (debug)
8
+ # FASP event listener display management events as JSON
9
+ class LineDump < Fasp::Listener
10
+ def event_enhanced(data)
11
+ STDOUT.puts(JSON.generate(data))
12
+ STDOUT.flush
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ require 'aspera/fasp/listener'
2
+ require 'aspera/log'
3
+
4
+ module Aspera
5
+ module Cli
6
+ module Listener
7
+ # listener for FASP transfers (debug)
8
+ class Logger < Fasp::Listener
9
+ def event_struct(data)
10
+ Log.log.debug(data.to_s)
11
+ Log.log.error("#{data['Description']}") if data['Type'].eql?('FILEERROR')
12
+ end
13
+
14
+ def event_enhanced(data)
15
+ Log.log.debug(JSON.generate(data))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,52 @@
1
+ require 'aspera/fasp/listener'
2
+ require 'ruby-progressbar'
3
+
4
+ module Aspera
5
+ module Cli
6
+ module Listener
7
+ # a listener to FASP event that displays a progress bar
8
+ class Progress < Fasp::Listener
9
+ def initialize
10
+ @progress=nil
11
+ @cumulative=0
12
+ end
13
+
14
+ BYTE_PER_MEGABIT=1024*1024/8
15
+
16
+ def event_struct(data)
17
+ case data['Type']
18
+ when 'NOTIFICATION'
19
+ if data.has_key?('PreTransferBytes') then
20
+ @progress=ProgressBar.create(
21
+ :format => '%a %B %p%% %r Mbps %e',
22
+ :rate_scale => lambda{|rate|rate/BYTE_PER_MEGABIT},
23
+ :title => 'progress',
24
+ :total => data['PreTransferBytes'].to_i)
25
+ end
26
+ when 'STOP'
27
+ # stop event when one file is completed
28
+ @cumulative=@cumulative+data['Size'].to_i
29
+ when 'STATS'
30
+ if !@progress.nil? then
31
+ if data.has_key?('Bytescont')
32
+ @progress.progress=@cumulative+data['Bytescont'].to_i
33
+ else
34
+ @progress.progress=data['TransferBytes'].to_i
35
+ end
36
+ else
37
+ puts '.'
38
+ end
39
+ when 'DONE'
40
+ if !@progress.nil? then
41
+ @progress.progress=@progress.total
42
+ @progress=nil
43
+ else
44
+ # terminate progress by going to next line
45
+ puts "\n"
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,91 @@
1
+ require 'aspera/fasp/listener'
2
+ require 'aspera/fasp/manager'
3
+ require 'ruby-progressbar'
4
+
5
+ module Aspera
6
+ module Cli
7
+ module Listener
8
+ # a listener to FASP event that displays a progress bar
9
+ class ProgressMulti < Fasp::Listener
10
+ def initialize
11
+ @progress_bar=nil
12
+ @sessions={}
13
+ end
14
+
15
+ def reset
16
+ @progress_bar=nil
17
+ @sessions={}
18
+ end
19
+
20
+ BYTE_PER_MEGABIT=1024*1024/8
21
+
22
+ def update_total
23
+ begin
24
+ @progress_bar.total=@sessions.values.inject(0){|m,s|m+=s[:job_size].to_i;m;}
25
+ rescue
26
+ nil
27
+ end
28
+ end
29
+
30
+ def update_progress
31
+ begin
32
+ @progress_bar.progress=@sessions.values.inject(0){|m,s|m+=s[:current].to_i;m;}
33
+ rescue
34
+ nil
35
+ end
36
+ end
37
+
38
+ def event_enhanced(data)
39
+ if @progress_bar.nil?
40
+ @progress_bar=ProgressBar.create(
41
+ :format => '%t %a %B %p%% %r Mbps %e',
42
+ :rate_scale => lambda{|rate|rate/BYTE_PER_MEGABIT},
43
+ :title => '',
44
+ :total => nil)
45
+ end
46
+ if !data.has_key?(Fasp::Manager::LISTENER_SESSION_ID_S)
47
+ Log.log.error("Internal error: no #{Fasp::Manager::LISTENER_SESSION_ID_S} in event: #{data}")
48
+ return
49
+ end
50
+ newtitle=@sessions.length < 2 ? '' : "multi=#{@sessions.length}"
51
+ @progress_bar.title=newtitle unless @progress_bar.title.eql?(newtitle)
52
+ session=@sessions[data[Fasp::Manager::LISTENER_SESSION_ID_S]]||={
53
+ cumulative: 0,
54
+ job_size: 0,
55
+ current: 0
56
+ }
57
+ case data['type']
58
+ when 'INIT' # connection to ascp (get id)
59
+ when 'SESSION' # session information
60
+ when 'NOTIFICATION' # sent from remote
61
+ if data.has_key?('pre_transfer_bytes') then
62
+ session[:job_size]=data['pre_transfer_bytes']
63
+ update_total
64
+ end
65
+ when 'STATS' # during transfer
66
+ if !@progress_bar.total.nil? then
67
+ if data.has_key?('bytescont')
68
+ session[:current]=session[:cumulative]+data['bytescont'].to_i
69
+ update_progress
70
+ else
71
+ session[:current]=data['transfer_bytes'].to_i
72
+ update_progress
73
+ end
74
+ else
75
+ @progress_bar.increment
76
+ end
77
+ when 'STOP'
78
+ # stop event when one file is completed
79
+ session[:cumulative]=session[:cumulative]+data['size'].to_i
80
+ when 'DONE' # end of session
81
+ @sessions.delete(data[Fasp::Manager::LISTENER_SESSION_ID_S])
82
+ update_progress
83
+ update_total
84
+ else
85
+ Log.log.debug("ignore: #{data['type']}")
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,304 @@
1
+ require 'aspera/cli/manager'
2
+ require 'aspera/cli/formater'
3
+ require 'aspera/cli/plugins/config'
4
+ require 'aspera/cli/extended_value'
5
+ require 'aspera/cli/transfer_agent'
6
+ require 'aspera/cli/version'
7
+ require 'aspera/open_application'
8
+ require 'aspera/temp_file_manager'
9
+ require 'aspera/persistency_folder'
10
+ require 'aspera/log'
11
+ require 'aspera/rest'
12
+ require 'aspera/nagios'
13
+
14
+ module Aspera
15
+ module Cli
16
+ # The main CLI class
17
+ class Main
18
+
19
+ attr_reader :plugin_env
20
+ private
21
+ # name of application, also foldername where config is stored
22
+ PROGRAM_NAME = 'ascli'
23
+ GEM_NAME = 'aspera-cli'
24
+ # Container module of current class : Aspera::Cli
25
+ CLI_MODULE=Module.nesting[1].to_s
26
+ # Path to Plugin classes: Aspera::Cli::Plugins
27
+ PLUGINS_MODULE=CLI_MODULE+'::Plugins'
28
+ VERBOSE_LEVELS=[:normal,:minimal,:quiet]
29
+
30
+ private_constant :PROGRAM_NAME,:GEM_NAME,:CLI_MODULE,:PLUGINS_MODULE,:VERBOSE_LEVELS
31
+
32
+ # find the root folder of gem where this class is
33
+ def self.gem_root
34
+ File.expand_path(CLI_MODULE.to_s.gsub('::','/').gsub(%r([^/]+),'..'),File.dirname(__FILE__))
35
+ end
36
+
37
+ # =============================================================
38
+ # Parameter handlers
39
+ #
40
+
41
+ def option_insecure; Rest.insecure ; end
42
+
43
+ def option_insecure=(value); Rest.insecure = value; end
44
+
45
+ def option_ui; OpenApplication.instance.url_method; end
46
+
47
+ def option_ui=(value); OpenApplication.instance.url_method=value; end
48
+
49
+ # minimum initialization
50
+ def initialize(argv)
51
+ # first thing : manage debug level (allows debugging or option parser)
52
+ early_debug_setup(argv)
53
+ current_prog_name=File.basename($PROGRAM_NAME)
54
+ unless current_prog_name.eql?(PROGRAM_NAME)
55
+ @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")
56
+ end
57
+ # overriding parameters on transfer spec
58
+ @option_help=false
59
+ @bash_completion=false
60
+ @option_show_config=false
61
+ @plugin_env={}
62
+ @help_url='http://www.rubydoc.info/gems/'+GEM_NAME
63
+ @gem_url='https://rubygems.org/gems/'+GEM_NAME
64
+ # give command line arguments to option manager (no parsing)
65
+ @plugin_env[:options]=@opt_mgr=Manager.new(self.program_name,argv,app_banner())
66
+ @plugin_env[:formater]=Formater.new(@plugin_env[:options])
67
+ Rest.user_agent=self.program_name
68
+ # must override help methods before parser called (in other constructors)
69
+ init_global_options()
70
+ # the Config plugin adds the @preset parser
71
+ @plugin_env[:config]=Plugins::Config.new(@plugin_env,self.program_name,@help_url,Aspera::Cli::VERSION)
72
+ # the TransferAgent plugin may use the @preset parser
73
+ @plugin_env[:transfer]=TransferAgent.new(@plugin_env)
74
+ Log.log.debug('created plugin env'.red)
75
+ # set application folder for modules
76
+ @plugin_env[:persistency]=PersistencyFolder.new(File.join(@plugin_env[:config].main_folder,'persist_store'))
77
+ Oauth.persist_mgr=@plugin_env[:persistency]
78
+ Fasp::Parameters.file_list_folder=File.join(@plugin_env[:config].main_folder,'filelists')
79
+ # register aspera REST call error handlers
80
+ Aspera::RestErrorsAspera.registerHandlers
81
+ end
82
+
83
+ def app_banner
84
+ banner = "NAME\n\t#{self.program_name} -- a command line tool for Aspera Applications (v#{Aspera::Cli::VERSION})\n\n"
85
+ banner << "SYNOPSIS\n"
86
+ banner << "\t#{self.program_name} COMMANDS [OPTIONS] [ARGS]\n"
87
+ banner << "\n"
88
+ banner << "DESCRIPTION\n"
89
+ banner << "\tUse Aspera application to perform operations on command line.\n"
90
+ banner << "\tDocumentation and examples: #{@gem_url}\n"
91
+ banner << "\texecute: #{self.program_name} conf doc\n"
92
+ banner << "\tor visit: #{@help_url}\n"
93
+ banner << "\n"
94
+ banner << "COMMANDS\n"
95
+ banner << "\tTo list first level commands, execute: #{self.program_name}\n"
96
+ banner << "\tNote that commands can be written shortened (provided it is unique).\n"
97
+ banner << "\n"
98
+ banner << "OPTIONS\n"
99
+ banner << "\tOptions begin with a '-' (minus), and value is provided on command line.\n"
100
+ banner << "\tSpecial values are supported beginning with special prefix, like: #{ExtendedValue.instance.modifiers.map{|m|"@#{m}:"}.join(' ')}.\n"
101
+ banner << "\tDates format is 'DD-MM-YY HH:MM:SS', or 'now' or '-<num>h'\n\n"
102
+ banner << "ARGS\n"
103
+ banner << "\tSome commands require mandatory arguments, e.g. a path.\n"
104
+ end
105
+
106
+ # define header for manual
107
+ def init_global_options
108
+ Log.log.debug("init_global_options")
109
+ @opt_mgr.add_opt_switch(:help,"-h","Show this message.") { @option_help=true }
110
+ @opt_mgr.add_opt_switch(:bash_comp,"generate bash completion for command") { @bash_completion=true }
111
+ @opt_mgr.add_opt_switch(:show_config, "Display parameters used for the provided action.") { @option_show_config=true }
112
+ @opt_mgr.add_opt_switch(:rest_debug,"-r","more debug for HTTP calls") { Rest.debug=true }
113
+ @opt_mgr.add_opt_switch(:version,'-v','display version') { @plugin_env[:formater].display_message(:data,Aspera::Cli::VERSION);Process.exit(0) }
114
+ @opt_mgr.add_opt_switch(:warnings,'-w','check for language warnings') { $VERBOSE=true }
115
+ # handler must be set before declaration
116
+ @opt_mgr.set_obj_attr(:log_level,Log.instance,:level)
117
+ @opt_mgr.set_obj_attr(:logger,Log.instance,:logger_type)
118
+ @opt_mgr.set_obj_attr(:insecure,self,:option_insecure,:no)
119
+ @opt_mgr.set_obj_attr(:ui,self,:option_ui)
120
+ @opt_mgr.add_opt_list(:ui,OpenApplication.user_interfaces,'method to start browser')
121
+ @opt_mgr.add_opt_list(:log_level,Log.levels,"Log level")
122
+ @opt_mgr.add_opt_list(:logger,Log.logtypes,"log method")
123
+ @opt_mgr.add_opt_simple(:lock_port,"prevent dual execution of a command, e.g. in cron")
124
+ @opt_mgr.add_opt_simple(:query,"additional filter for API calls (extended value) (some commands)")
125
+ @opt_mgr.add_opt_boolean(:insecure,"do not validate HTTPS certificate")
126
+ @opt_mgr.add_opt_boolean(:once_only,"process only new items (some commands)")
127
+ @opt_mgr.set_option(:ui,OpenApplication.default_gui_mode)
128
+ @opt_mgr.set_option(:once_only,:false)
129
+ # parse declared options
130
+ @opt_mgr.parse_options!
131
+ end
132
+
133
+ # @return the plugin instance, based on name
134
+ # also loads the plugin options, and default values from conf file
135
+ # @param plugin_name_sym : symbol for plugin name
136
+ def get_plugin_instance_with_options(plugin_name_sym,env=nil)
137
+ env||=@plugin_env
138
+ Log.log.debug("get_plugin_instance_with_options(#{plugin_name_sym})")
139
+ require @plugin_env[:config].plugins[plugin_name_sym][:require_stanza]
140
+ # load default params only if no param already loaded before plugin instanciation
141
+ env[:config].add_plugin_default_preset(plugin_name_sym)
142
+ command_plugin=Object::const_get(PLUGINS_MODULE+'::'+plugin_name_sym.to_s.capitalize).new(env)
143
+ Log.log.debug("got #{command_plugin.class}")
144
+ # TODO: check that ancestor is Plugin?
145
+ return command_plugin
146
+ end
147
+
148
+ def generate_bash_completion
149
+ if @opt_mgr.get_next_argument("",:multiple,:optional).nil?
150
+ @plugin_env[:config].plugins.keys.each{|p|puts p.to_s}
151
+ else
152
+ Log.log.warn("only first level completion so far")
153
+ end
154
+ Process.exit(0)
155
+ end
156
+
157
+ # expect some list, but nothing to display
158
+ def self.result_empty; return {:type => :empty, :data => :nil }; end
159
+
160
+ # nothing expected
161
+ def self.result_nothing; return {:type => :nothing, :data => :nil }; end
162
+
163
+ def self.result_status(status); return {:type => :status, :data => status }; end
164
+
165
+ def self.result_success; return result_status('complete'); end
166
+
167
+ def exit_with_usage(all_plugins)
168
+ Log.log.debug("exit_with_usage".bg_red)
169
+ # display main plugin options
170
+ @plugin_env[:formater].display_message(:error,@opt_mgr.parser)
171
+ if all_plugins
172
+ # list plugins that have a "require" field, i.e. all but main plugin
173
+ @plugin_env[:config].plugins.keys.each do |plugin_name_sym|
174
+ next if plugin_name_sym.eql?(Plugins::Config::CONF_PLUGIN_SYM)
175
+ # override main option parser with a brand new, to avoid having global options
176
+ plugin_env=@plugin_env.clone
177
+ plugin_env[:man_only]=true
178
+ plugin_env[:options]=Manager.new(self.program_name,[],'')
179
+ get_plugin_instance_with_options(plugin_name_sym,plugin_env)
180
+ # display generated help for plugin options
181
+ @plugin_env[:formater].display_message(:error,plugin_env[:options].parser.to_s)
182
+ end
183
+ end
184
+ Process.exit(0)
185
+ end
186
+
187
+ protected
188
+
189
+ # early debug for parser
190
+ # Note: does not accept shortcuts
191
+ def early_debug_setup(argv)
192
+ Log.instance.program_name=self.program_name
193
+ argv.each do |arg|
194
+ case arg
195
+ when '--'
196
+ return
197
+ when /^--log-level=(.*)/
198
+ Log.instance.level = $1.to_sym
199
+ when /^--logger=(.*)/
200
+ Log.instance.logger_type=$1.to_sym
201
+ end
202
+ end
203
+ end
204
+
205
+ public
206
+
207
+ # Process statuses of finished transfer sessions
208
+ # raise exception if there is one error
209
+ # else returns an empty status
210
+ def self.result_transfer(statuses)
211
+ worst=TransferAgent.session_status(statuses)
212
+ raise worst unless worst.eql?(:success)
213
+ return Main.result_nothing
214
+ end
215
+
216
+ def options;@opt_mgr;end
217
+
218
+ def program_name;PROGRAM_NAME;end
219
+
220
+ # this is the main function called by initial script just after constructor
221
+ def process_command_line
222
+ Log.log.debug('process_command_line')
223
+ exception_info=nil
224
+ begin
225
+ # find plugins, shall be after parse! ?
226
+ @plugin_env[:config].add_plugins_from_lookup_folders
227
+ # help requested without command ? (plugins must be known here)
228
+ exit_with_usage(true) if @option_help and @opt_mgr.command_or_arg_empty?
229
+ generate_bash_completion if @bash_completion
230
+ # load global default options and process
231
+ @plugin_env[:config].add_plugin_default_preset(Plugins::Config::CONF_GLOBAL_SYM)
232
+ @opt_mgr.parse_options!
233
+ # dual execution locking
234
+ lock_port=@opt_mgr.get_option(:lock_port,:optional)
235
+ if !lock_port.nil?
236
+ begin
237
+ # no need to close later, will be freed on process exit. must save in member else it is garbage collected
238
+ @tcp_server=TCPServer.new('127.0.0.1',lock_port.to_i)
239
+ rescue => e
240
+ raise CliError,"Another instance is already running (lock port=#{lock_port})."
241
+ end
242
+ end
243
+ if @option_show_config and @opt_mgr.command_or_arg_empty?
244
+ command_sym=Plugins::Config::CONF_PLUGIN_SYM
245
+ else
246
+ command_sym=@opt_mgr.get_next_command(@plugin_env[:config].plugins.keys.dup.unshift(:help))
247
+ end
248
+ # main plugin is not dynamically instanciated
249
+ case command_sym
250
+ when :help
251
+ exit_with_usage(true)
252
+ when Plugins::Config::CONF_PLUGIN_SYM
253
+ command_plugin=@plugin_env[:config]
254
+ else
255
+ # get plugin, set options, etc
256
+ command_plugin=get_plugin_instance_with_options(command_sym)
257
+ # parse plugin specific options
258
+ @opt_mgr.parse_options!
259
+ end
260
+ # help requested for current plugin
261
+ exit_with_usage(false) if @option_help
262
+ if @option_show_config
263
+ @plugin_env[:formater].display_results({:type=>:single_object,:data=>@opt_mgr.declared_options(false)})
264
+ Process.exit(0)
265
+ end
266
+ # execute and display
267
+ @plugin_env[:formater].display_results(command_plugin.execute_action)
268
+ # finish
269
+ @plugin_env[:transfer].shutdown
270
+ rescue CliBadArgument => e; exception_info=[e,'Argument',:usage]
271
+ rescue CliNoSuchId => e; exception_info=[e,'Identifier']
272
+ rescue CliError => e; exception_info=[e,'Tool',:usage]
273
+ rescue Fasp::Error => e; exception_info=[e,"FASP(ascp]"]
274
+ rescue Aspera::RestCallError => e; exception_info=[e,"Rest"]
275
+ rescue SocketError => e; exception_info=[e,"Network"]
276
+ rescue StandardError => e; exception_info=[e,"Other",:debug]
277
+ rescue Interrupt => e; exception_info=[e,"Interruption",:debug]
278
+ end
279
+ # cleanup file list files
280
+ TempFileManager.instance.cleanup
281
+ # 1- processing of error condition
282
+ unless exception_info.nil?
283
+ @plugin_env[:formater].display_message(:error,"ERROR:".bg_red.gray.blink+" "+exception_info[1]+": "+exception_info[0].message)
284
+ @plugin_env[:formater].display_message(:error,"Use '-h' option to get help.") if exception_info[2].eql?(:usage)
285
+ end
286
+ # 2- processing of command not processed (due to exception or bad command line)
287
+ @opt_mgr.final_errors.each do |msg|
288
+ @plugin_env[:formater].display_message(:error,"ERROR:".bg_red.gray.blink+" Argument: "+msg)
289
+ end
290
+ # 3- in case of error, fail the process status
291
+ unless exception_info.nil?
292
+ if Log.instance.level.eql?(:debug)
293
+ # will force to show stack trace
294
+ raise exception_info[0]
295
+ else
296
+ @plugin_env[:formater].display_message(:error,"Use '--log-level=debug' to get more details.") if exception_info[2].eql?(:debug)
297
+ Process.exit(1)
298
+ end
299
+ end
300
+ return nil
301
+ end # process_command_line
302
+ end # Main
303
+ end # Cli
304
+ end # Aspera