morpheus-cli 5.5.2.1 → 5.5.3
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Dockerfile +1 -1
- data/README.md +57 -4
- data/Rakefile +9 -0
- data/bin/morpheus +4 -4
- data/lib/morpheus/api/api_client.rb +8 -2
- data/lib/morpheus/api/archive_buckets_interface.rb +1 -1
- data/lib/morpheus/api/archive_files_interface.rb +3 -3
- data/lib/morpheus/api/clients_interface.rb +2 -2
- data/lib/morpheus/api/clusters_interface.rb +8 -1
- data/lib/morpheus/api/containers_interface.rb +29 -16
- data/lib/morpheus/api/custom_instance_types_interface.rb +0 -2
- data/lib/morpheus/api/doc_interface.rb +8 -6
- data/lib/morpheus/api/file_copy_request_interface.rb +1 -1
- data/lib/morpheus/api/health_interface.rb +1 -1
- data/lib/morpheus/api/image_builder_interface.rb +3 -3
- data/lib/morpheus/api/instances_interface.rb +25 -0
- data/lib/morpheus/api/logs_interface.rb +2 -4
- data/lib/morpheus/api/monitoring_interface.rb +6 -6
- data/lib/morpheus/api/packages_interface.rb +1 -1
- data/lib/morpheus/api/reports_interface.rb +1 -1
- data/lib/morpheus/api/servers_interface.rb +9 -1
- data/lib/morpheus/api/storage_providers_interface.rb +2 -2
- data/lib/morpheus/api/virtual_images_interface.rb +1 -1
- data/lib/morpheus/api.rb +2 -0
- data/lib/morpheus/benchmarking.rb +1 -1
- data/lib/morpheus/cli/cli_command.rb +69 -36
- data/lib/morpheus/cli/cli_registry.rb +19 -10
- data/lib/morpheus/cli/commands/access_token_command.rb +1 -1
- data/lib/morpheus/cli/commands/apps.rb +1 -1
- data/lib/morpheus/cli/commands/archives_command.rb +25 -33
- data/lib/morpheus/cli/commands/blueprints_command.rb +10 -21
- data/lib/morpheus/cli/commands/boot_scripts_command.rb +2 -2
- data/lib/morpheus/cli/commands/cat_command.rb +1 -1
- data/lib/morpheus/cli/commands/catalog_item_types_command.rb +12 -12
- data/lib/morpheus/cli/commands/clouds.rb +3 -3
- data/lib/morpheus/cli/commands/clusters.rb +154 -3
- data/lib/morpheus/cli/commands/containers_command.rb +398 -253
- data/lib/morpheus/cli/commands/deployments.rb +1 -1
- data/lib/morpheus/cli/commands/deploys.rb +9 -9
- data/lib/morpheus/cli/commands/doc.rb +15 -16
- data/lib/morpheus/cli/commands/execution_request_command.rb +2 -2
- data/lib/morpheus/cli/commands/file_copy_request_command.rb +5 -5
- data/lib/morpheus/cli/commands/groups.rb +2 -2
- data/lib/morpheus/cli/commands/health_command.rb +4 -4
- data/lib/morpheus/cli/commands/hosts.rb +43 -5
- data/lib/morpheus/cli/commands/image_builder_command.rb +1 -1
- data/lib/morpheus/cli/commands/instances.rb +419 -148
- data/lib/morpheus/cli/commands/integrations_command.rb +22 -20
- data/lib/morpheus/cli/commands/key_pairs.rb +2 -2
- data/lib/morpheus/cli/commands/library_container_scripts_command.rb +2 -2
- data/lib/morpheus/cli/commands/library_container_templates_command.rb +2 -2
- data/lib/morpheus/cli/commands/library_instance_types_command.rb +3 -3
- data/lib/morpheus/cli/commands/library_spec_templates_command.rb +2 -2
- data/lib/morpheus/cli/commands/login.rb +1 -1
- data/lib/morpheus/cli/commands/man_command.rb +32 -18
- data/lib/morpheus/cli/commands/packages_command.rb +11 -11
- data/lib/morpheus/cli/commands/plugins.rb +1 -1
- data/lib/morpheus/cli/commands/policies_command.rb +4 -4
- data/lib/morpheus/cli/commands/preseed_scripts_command.rb +2 -2
- data/lib/morpheus/cli/commands/remote.rb +1 -1
- data/lib/morpheus/cli/commands/reports_command.rb +3 -3
- data/lib/morpheus/cli/commands/roles.rb +6 -3
- data/lib/morpheus/cli/commands/security_groups.rb +1 -1
- data/lib/morpheus/cli/commands/shell.rb +40 -62
- data/lib/morpheus/cli/commands/snapshots.rb +3 -5
- data/lib/morpheus/cli/commands/source_command.rb +8 -16
- data/lib/morpheus/cli/commands/storage_providers_command.rb +7 -7
- data/lib/morpheus/cli/commands/tasks.rb +2 -2
- data/lib/morpheus/cli/commands/vdi_pools_command.rb +6 -6
- data/lib/morpheus/cli/commands/view.rb +5 -1
- data/lib/morpheus/cli/commands/whitelabel_settings_command.rb +4 -4
- data/lib/morpheus/cli/commands/whoami.rb +2 -2
- data/lib/morpheus/cli/credentials.rb +30 -8
- data/lib/morpheus/cli/dot_file.rb +8 -15
- data/lib/morpheus/cli/error_handler.rb +16 -0
- data/lib/morpheus/cli/errors.rb +8 -1
- data/lib/morpheus/cli/mixins/print_helper.rb +17 -13
- data/lib/morpheus/cli/mixins/rest_command.rb +18 -18
- data/lib/morpheus/cli/mixins/secondary_rest_command.rb +12 -12
- data/lib/morpheus/cli/option_parser.rb +5 -1
- data/lib/morpheus/cli/option_types.rb +59 -12
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli.rb +26 -16
- data/lib/morpheus/ext/rest_client.rb +3 -2
- data/lib/morpheus/formatters.rb +1 -1
- data/lib/morpheus/logging.rb +4 -4
- data/lib/morpheus/morpkg.rb +4 -4
- data/lib/morpheus/rest_client.rb +2 -2
- data/lib/morpheus/routes.rb +2 -2
- data/lib/morpheus/terminal.rb +65 -16
- data/lib/morpheus.rb +1 -1
- data/morpheus-cli.gemspec +1 -0
- data/test/api/containers_interface_test.rb +68 -0
- data/test/api/doc_interface_test.rb +35 -0
- data/test/api/instances_interface_test.rb +22 -0
- data/test/api/whoami_interface_test.rb +14 -0
- data/test/cli/access_token_test.rb +36 -0
- data/test/cli/auth_test.rb +82 -0
- data/test/cli/cli_test.rb +48 -0
- data/test/cli/containers_test.rb +92 -0
- data/test/cli/doc_test.rb +35 -0
- data/test/cli/help_test.rb +25 -0
- data/test/cli/instances_test.rb +36 -0
- data/test/cli/man_test.rb +14 -0
- data/test/cli/remote_test.rb +89 -0
- data/test/cli/roles_test.rb +34 -0
- data/test/cli/shell_test.rb +81 -0
- data/test/cli/version_test.rb +23 -0
- data/test/cli/view_test.rb +55 -0
- data/test/cli/whoami_test.rb +17 -0
- data/test/morpheus_test.rb +16 -0
- data/test/test_case.rb +338 -0
- data/test/test_config.rb +137 -0
- data/test/test_data_helper.rb +97 -0
- metadata +61 -3
|
@@ -133,10 +133,12 @@ module Morpheus
|
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
# this returns all the options passed in by -O, parsed all nicely into objects.
|
|
136
|
-
def parse_passed_options(options)
|
|
137
|
-
|
|
136
|
+
def parse_passed_options(options, parse_opts={})
|
|
137
|
+
excludes = [parse_opts[:exclude], parse_opts[:excludes]].flatten.compact
|
|
138
|
+
passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) || excludes.include?(k) } : {}
|
|
138
139
|
return passed_options
|
|
139
140
|
end
|
|
141
|
+
|
|
140
142
|
# Appends Array of OptionType definitions to an OptionParser instance
|
|
141
143
|
# This adds an option like --fieldContext.fieldName="VALUE"
|
|
142
144
|
# @param opts [OptionParser]
|
|
@@ -378,35 +380,53 @@ module Morpheus
|
|
|
378
380
|
end
|
|
379
381
|
options[:options] = custom_options
|
|
380
382
|
end
|
|
381
|
-
|
|
383
|
+
# --always-prompt can be used with for update commands where it normally defaults to --no-prompt
|
|
384
|
+
opts.on('--prompt', "Always prompt for input on every option, even those not prompted for by default.") do
|
|
382
385
|
options[:always_prompt] = true
|
|
383
|
-
options[:options] ||= {}
|
|
384
386
|
options[:options][:always_prompt] = true
|
|
385
387
|
end
|
|
386
|
-
opts.on('-N','--no-prompt', "
|
|
388
|
+
opts.on('-N','--no-prompt', "No prompt, skips all input prompting.") do |val|
|
|
387
389
|
options[:no_prompt] = true
|
|
388
|
-
options[:options] ||= {}
|
|
389
|
-
options[:options][:no_prompt] = true
|
|
390
|
-
end
|
|
391
|
-
|
|
392
|
-
when :prompt
|
|
393
|
-
opts.on('-P','--prompt', "Always prompts. Use passed options as the default value.") do |val|
|
|
394
|
-
options[:always_prompt] = true
|
|
395
|
-
options[:options] ||= {}
|
|
396
|
-
options[:options][:always_prompt] = true
|
|
397
|
-
end
|
|
398
|
-
opts.on('-N','--no-prompt', "Skip prompts. Use default values for all optional fields.") do |val|
|
|
399
|
-
options[:no_prompt] = true
|
|
400
|
-
options[:options] ||= {}
|
|
401
390
|
options[:options][:no_prompt] = true
|
|
402
391
|
end
|
|
392
|
+
# opts.on('--skip-prompt x,y,z', String, "Skip prompt, do not prompt for input of the specified options.") do |val|
|
|
393
|
+
# options[:skip_prompt] ||= []
|
|
394
|
+
# options[:skip_prompt] += parse_array(val)
|
|
395
|
+
# options[:options][:skip_prompt] = options[:skip_prompt]
|
|
396
|
+
# end
|
|
397
|
+
# opts.on('--only-prompt x,y,z', String, "Only prompt for input on the specified options.") do |val|
|
|
398
|
+
# options[:only_prompt] ||= []
|
|
399
|
+
# options[:only_prompt] += parse_array(val)
|
|
400
|
+
# options[:options][:only_prompt] = options[:only_prompt]
|
|
401
|
+
# end
|
|
402
|
+
opts.on('--no-options', String, "No options, skips all option parsing so no options are required and no default values are used.") do
|
|
403
|
+
options[:no_options] = true
|
|
404
|
+
options[:options][:no_options] = options[:no_options]
|
|
405
|
+
end
|
|
406
|
+
opts.on('--skip-options x,y,z', String, "Skip parsing of the specified options so that they are not required and their default value is not used.") do |val|
|
|
407
|
+
options[:skip_options] ||= []
|
|
408
|
+
options[:skip_options] += parse_array(val)
|
|
409
|
+
options[:options][:skip_options] = options[:skip_options]
|
|
410
|
+
end
|
|
411
|
+
# opts.on('--only-options x,y,z', String, "Only parse the specified options and skip all others.") do |val|
|
|
412
|
+
# options[:only_options] ||= []
|
|
413
|
+
# options[:only_options] += parse_array(val)
|
|
414
|
+
# options[:options][:only_options] = options[:only_options]
|
|
415
|
+
# end
|
|
416
|
+
|
|
417
|
+
# hide these while incubating
|
|
418
|
+
opts.add_hidden_option('--skip-prompt')
|
|
419
|
+
opts.add_hidden_option('--only-prompt')
|
|
420
|
+
opts.add_hidden_option('--no-options')
|
|
421
|
+
opts.add_hidden_option('--skip-options')
|
|
422
|
+
opts.add_hidden_option('--only-options')
|
|
403
423
|
|
|
404
424
|
when :payload
|
|
405
425
|
opts.on('--payload FILE', String, "Payload from a local JSON or YAML file, skip all prompting") do |val|
|
|
406
426
|
options[:payload_file] = val.to_s
|
|
407
427
|
begin
|
|
408
428
|
payload_file = File.expand_path(options[:payload_file])
|
|
409
|
-
if !File.
|
|
429
|
+
if !File.exist?(payload_file) || !File.file?(payload_file)
|
|
410
430
|
raise ::OptionParser::InvalidOption.new("File not found: #{payload_file}")
|
|
411
431
|
#return false
|
|
412
432
|
end
|
|
@@ -419,10 +439,10 @@ module Morpheus
|
|
|
419
439
|
raise ::OptionParser::InvalidOption.new("Failed to parse payload file: #{payload_file} Error: #{ex.message}")
|
|
420
440
|
end
|
|
421
441
|
end
|
|
422
|
-
opts.on('--payload-dir DIRECTORY', String, "Payload from a local directory containing 1-N JSON or YAML files, skip all prompting") do |val|
|
|
442
|
+
opts.on('--payload-dir DIRECTORY', String, "Payload from a local directory containing 1-N JSON or YAML files, skip all prompting.") do |val|
|
|
423
443
|
options[:payload_dir] = val.to_s
|
|
424
444
|
payload_dir = File.expand_path(options[:payload_dir])
|
|
425
|
-
if !Dir.
|
|
445
|
+
if !Dir.exist?(payload_dir) || !File.directory?(payload_dir)
|
|
426
446
|
raise ::OptionParser::InvalidOption.new("Directory not found: #{payload_dir}")
|
|
427
447
|
end
|
|
428
448
|
payload = {}
|
|
@@ -592,7 +612,7 @@ module Morpheus
|
|
|
592
612
|
end unless excludes.include?(:remote_token)
|
|
593
613
|
opts.on( '--token-file FILE', String, "Token File, read a file containing the access token." ) do |val|
|
|
594
614
|
token_file = File.expand_path(val)
|
|
595
|
-
if !File.
|
|
615
|
+
if !File.exist?(token_file) || !File.file?(token_file)
|
|
596
616
|
raise ::OptionParser::InvalidOption.new("File not found: #{token_file}")
|
|
597
617
|
end
|
|
598
618
|
options[:remote_token] = File.read(token_file).to_s.split("\n").first.strip
|
|
@@ -609,7 +629,7 @@ module Morpheus
|
|
|
609
629
|
end
|
|
610
630
|
opts.on( '--password-file FILE', String, "Password File, read a file containing the password for authentication." ) do |val|
|
|
611
631
|
password_file = File.expand_path(val)
|
|
612
|
-
if !File.
|
|
632
|
+
if !File.exist?(password_file) || !File.file?(password_file)
|
|
613
633
|
raise ::OptionParser::InvalidOption.new("File not found: #{password_file}")
|
|
614
634
|
end
|
|
615
635
|
file_content = File.read(password_file) #.strip
|
|
@@ -914,12 +934,12 @@ module Morpheus
|
|
|
914
934
|
|
|
915
935
|
opts.on('--hidden-help', "Print help that includes all the hidden options, like this one." ) do
|
|
916
936
|
puts opts.full_help_message({show_hidden_options:true})
|
|
917
|
-
exit # return 0 maybe?
|
|
937
|
+
exit 0 # return 0 maybe?
|
|
918
938
|
end
|
|
919
939
|
opts.add_hidden_option('--hidden-help') if opts.is_a?(Morpheus::Cli::OptionParser)
|
|
920
940
|
opts.on('-h', '--help', "Print this help" ) do
|
|
921
941
|
puts opts
|
|
922
|
-
exit # return 0 maybe?
|
|
942
|
+
exit 0 # return 0 maybe?
|
|
923
943
|
end
|
|
924
944
|
|
|
925
945
|
opts
|
|
@@ -1012,9 +1032,9 @@ module Morpheus
|
|
|
1012
1032
|
out << "\n"
|
|
1013
1033
|
}
|
|
1014
1034
|
end
|
|
1015
|
-
if command_description
|
|
1035
|
+
if command_description && !command_description.to_s.strip.empty?
|
|
1016
1036
|
out << "\n"
|
|
1017
|
-
out << "#{command_description}\n"
|
|
1037
|
+
out << "#{command_description.strip}\n"
|
|
1018
1038
|
end
|
|
1019
1039
|
# out << "\n"
|
|
1020
1040
|
out
|
|
@@ -1248,6 +1268,14 @@ module Morpheus
|
|
|
1248
1268
|
true
|
|
1249
1269
|
end
|
|
1250
1270
|
|
|
1271
|
+
def confirm(msg, options)
|
|
1272
|
+
options[:yes] or ::Morpheus::Cli::OptionTypes::confirm(msg, options)
|
|
1273
|
+
end
|
|
1274
|
+
|
|
1275
|
+
def confirm!(msg, options)
|
|
1276
|
+
confirm(msg, options) or raise CommandAborted.new("confirmation declined: #{msg}")
|
|
1277
|
+
end
|
|
1278
|
+
|
|
1251
1279
|
# The default way to build options for the list command
|
|
1252
1280
|
# @param [OptionParser] opts
|
|
1253
1281
|
# @param [Hash] options
|
|
@@ -1449,11 +1477,11 @@ module Morpheus
|
|
|
1449
1477
|
def validate_outfile(outfile, options)
|
|
1450
1478
|
full_filename = File.expand_path(outfile)
|
|
1451
1479
|
outdir = File.dirname(full_filename)
|
|
1452
|
-
if Dir.
|
|
1480
|
+
if Dir.exist?(full_filename)
|
|
1453
1481
|
print_red_alert "[local-file] is invalid. It is the name of an existing directory: #{outfile}"
|
|
1454
1482
|
return false
|
|
1455
1483
|
end
|
|
1456
|
-
if !Dir.
|
|
1484
|
+
if !Dir.exist?(outdir)
|
|
1457
1485
|
if options[:mkdir]
|
|
1458
1486
|
print cyan,"Creating local directory #{outdir}",reset,"\n"
|
|
1459
1487
|
FileUtils.mkdir_p(outdir)
|
|
@@ -1462,7 +1490,7 @@ module Morpheus
|
|
|
1462
1490
|
return false
|
|
1463
1491
|
end
|
|
1464
1492
|
end
|
|
1465
|
-
if File.
|
|
1493
|
+
if File.exist?(full_filename) && !options[:overwrite]
|
|
1466
1494
|
print_red_alert "[local-file] is invalid. File already exists: #{outfile}\nUse -f to overwrite the existing file."
|
|
1467
1495
|
return false
|
|
1468
1496
|
end
|
|
@@ -1753,6 +1781,9 @@ module Morpheus
|
|
|
1753
1781
|
|
|
1754
1782
|
module ClassMethods
|
|
1755
1783
|
|
|
1784
|
+
# attr_writer :command_name, :command_description, :hidden_command, :default_refresh_interval,
|
|
1785
|
+
# :subcommands, :hidden_subcommands, :default_subcommand, :subcommand_aliases, :subcommand_descriptions
|
|
1786
|
+
|
|
1756
1787
|
def prog_name
|
|
1757
1788
|
"morpheus"
|
|
1758
1789
|
end
|
|
@@ -1779,7 +1810,11 @@ module Morpheus
|
|
|
1779
1810
|
# alias :command_name= :set_command_name
|
|
1780
1811
|
|
|
1781
1812
|
def hidden_command
|
|
1782
|
-
|
|
1813
|
+
defined?(@hidden_command) && @hidden_command == true
|
|
1814
|
+
end
|
|
1815
|
+
|
|
1816
|
+
def hidden_subcommands
|
|
1817
|
+
@hidden_subcommands ||= []
|
|
1783
1818
|
end
|
|
1784
1819
|
|
|
1785
1820
|
def set_subcommands_hidden(*cmds)
|
|
@@ -1791,7 +1826,7 @@ module Morpheus
|
|
|
1791
1826
|
end
|
|
1792
1827
|
|
|
1793
1828
|
def command_description
|
|
1794
|
-
@command_description
|
|
1829
|
+
@command_description ||= ""
|
|
1795
1830
|
end
|
|
1796
1831
|
|
|
1797
1832
|
def set_command_description(val)
|
|
@@ -1880,10 +1915,8 @@ module Morpheus
|
|
|
1880
1915
|
|
|
1881
1916
|
def visible_subcommands
|
|
1882
1917
|
cmds = subcommands.clone
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
cmds.delete(hidden_cmd.to_s.gsub('_', '-'))
|
|
1886
|
-
end
|
|
1918
|
+
hidden_subcommands.each do |hidden_cmd|
|
|
1919
|
+
cmds.delete(hidden_cmd.to_s.gsub('_', '-'))
|
|
1887
1920
|
end
|
|
1888
1921
|
cmds
|
|
1889
1922
|
end
|
|
@@ -78,10 +78,17 @@ module Morpheus
|
|
|
78
78
|
|
|
79
79
|
def exec_command(command_name, args)
|
|
80
80
|
#puts "exec_command(#{command_name}, #{args})"
|
|
81
|
+
result = nil
|
|
81
82
|
if has_alias?(command_name)
|
|
82
|
-
exec_alias(command_name, args)
|
|
83
|
+
result = exec_alias(command_name, args)
|
|
83
84
|
elsif has_command?(command_name)
|
|
84
|
-
|
|
85
|
+
begin
|
|
86
|
+
result = instance.get(command_name).new.handle(args)
|
|
87
|
+
rescue SystemExit => e
|
|
88
|
+
result = Morpheus::Cli::ErrorHandler.new(Morpheus::Terminal.instance.stderr).handle_error(e) # lol
|
|
89
|
+
rescue => e
|
|
90
|
+
result = Morpheus::Cli::ErrorHandler.new(Morpheus::Terminal.instance.stderr).handle_error(e) # lol
|
|
91
|
+
end
|
|
85
92
|
else
|
|
86
93
|
# todo: need to just return error instead of raise
|
|
87
94
|
msg = "'#{command_name}' is not a morpheus command."
|
|
@@ -97,8 +104,10 @@ module Morpheus
|
|
|
97
104
|
msg += "\t" + suggestion + "\n"
|
|
98
105
|
end
|
|
99
106
|
end
|
|
100
|
-
raise CommandNotFoundError.new(msg)
|
|
107
|
+
#raise CommandNotFoundError.new(msg)
|
|
108
|
+
result = Morpheus::Cli::ErrorHandler.new(Morpheus::Terminal.instance.stderr).handle_error(CommandNotFoundError.new(msg)) # lol
|
|
101
109
|
end
|
|
110
|
+
return result
|
|
102
111
|
end
|
|
103
112
|
|
|
104
113
|
def exec_alias(alias_name, args)
|
|
@@ -248,17 +257,17 @@ module Morpheus
|
|
|
248
257
|
|
|
249
258
|
# parse any object into a command result [exit_code, error]
|
|
250
259
|
# 0 means success.
|
|
251
|
-
# This treats nil, true, or an object success.
|
|
252
|
-
#
|
|
253
|
-
# @return [Array] exit_code, error. Success returns [0, nil].
|
|
260
|
+
# This treats nil, true, or an object as success ie. [0, nil]
|
|
261
|
+
# and false is treated as an error [1, error]
|
|
262
|
+
# @return [Array] [exit_code, error]. Success returns [0, nil].
|
|
254
263
|
def parse_command_result(cmd_result)
|
|
255
|
-
exit_code,
|
|
264
|
+
exit_code, error = nil, nil
|
|
256
265
|
if cmd_result.is_a?(Array)
|
|
257
266
|
exit_code = cmd_result[0] || 0
|
|
258
|
-
|
|
267
|
+
error = cmd_result[1]
|
|
259
268
|
elsif cmd_result.is_a?(Hash)
|
|
260
269
|
exit_code = cmd_result[:exit_code] || 0
|
|
261
|
-
|
|
270
|
+
error = cmd_result[:error] || cmd_result[:err]
|
|
262
271
|
elsif cmd_result == nil || cmd_result == true
|
|
263
272
|
exit_code = 0
|
|
264
273
|
elsif cmd_result == false
|
|
@@ -279,7 +288,7 @@ module Morpheus
|
|
|
279
288
|
exit_code = 0
|
|
280
289
|
end
|
|
281
290
|
end
|
|
282
|
-
return exit_code,
|
|
291
|
+
return exit_code, error
|
|
283
292
|
end
|
|
284
293
|
|
|
285
294
|
def cached_command_list
|
|
@@ -116,7 +116,7 @@ class Morpheus::Cli::AccessTokenCommand
|
|
|
116
116
|
end
|
|
117
117
|
opts.on( '--token-file FILE', String, "Refresh Token File, read a file containing the refresh token." ) do |val|
|
|
118
118
|
token_file = File.expand_path(val)
|
|
119
|
-
if !File.
|
|
119
|
+
if !File.exist?(token_file) || !File.file?(token_file)
|
|
120
120
|
raise ::OptionParser::InvalidOption.new("File not found: #{token_file}")
|
|
121
121
|
end
|
|
122
122
|
options[:refresh_token] = File.read(token_file).to_s.split("\n").first.strip
|
|
@@ -2260,7 +2260,7 @@ EOT
|
|
|
2260
2260
|
build_option_type_options(opts, options, update_wiki_page_option_types)
|
|
2261
2261
|
opts.on('--file FILE', "File containing the wiki content. This can be used instead of --content") do |filename|
|
|
2262
2262
|
full_filename = File.expand_path(filename)
|
|
2263
|
-
if File.
|
|
2263
|
+
if File.exist?(full_filename)
|
|
2264
2264
|
params['content'] = File.read(full_filename)
|
|
2265
2265
|
else
|
|
2266
2266
|
print_red_alert "File not found: #{full_filename}"
|
|
@@ -383,7 +383,6 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
383
383
|
end
|
|
384
384
|
|
|
385
385
|
def remove_bucket(args)
|
|
386
|
-
full_command_string = "#{command_name} remove #{args.join(' ')}".strip
|
|
387
386
|
options = {}
|
|
388
387
|
query_params = {}
|
|
389
388
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
@@ -414,7 +413,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
414
413
|
end
|
|
415
414
|
@archive_buckets_interface.setopts(options)
|
|
416
415
|
if options[:dry_run]
|
|
417
|
-
print_dry_run @archive_buckets_interface.dry.destroy(archive_bucket['id'], query_params)
|
|
416
|
+
print_dry_run @archive_buckets_interface.dry.destroy(archive_bucket['id'], query_params)
|
|
418
417
|
return 0
|
|
419
418
|
end
|
|
420
419
|
json_response = @archive_buckets_interface.destroy(archive_bucket['id'], query_params)
|
|
@@ -470,7 +469,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
470
469
|
puts_error "#{command_name} missing argument: [local-file]\n#{optparse}"
|
|
471
470
|
return 1
|
|
472
471
|
end
|
|
473
|
-
if !File.
|
|
472
|
+
if !File.exist?(local_file_path)
|
|
474
473
|
print_error Morpheus::Terminal.angry_prompt
|
|
475
474
|
puts_error "#{command_name} bad argument: [local-file]\nFile '#{local_file_path}' was not found.\n#{optparse}"
|
|
476
475
|
return 1
|
|
@@ -595,7 +594,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
595
594
|
else
|
|
596
595
|
|
|
597
596
|
# upload file
|
|
598
|
-
if !File.
|
|
597
|
+
if !File.exist?(local_file_path) && !File.file?(local_file_path)
|
|
599
598
|
print_error Morpheus::Terminal.angry_prompt
|
|
600
599
|
puts_error "#{command_name} bad argument: [local-file]\nFile '#{local_file_path}' was not found.\n#{optparse}"
|
|
601
600
|
return 1
|
|
@@ -886,7 +885,6 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
886
885
|
end
|
|
887
886
|
|
|
888
887
|
def get_file(args)
|
|
889
|
-
full_command_string = "#{command_name} get-file #{args.join(' ')}".strip
|
|
890
888
|
options = {}
|
|
891
889
|
max_links = 10
|
|
892
890
|
max_history = 10
|
|
@@ -929,9 +927,9 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
929
927
|
@archive_files_interface.setopts(options)
|
|
930
928
|
if options[:dry_run]
|
|
931
929
|
if file_id
|
|
932
|
-
print_dry_run @archive_files_interface.dry.get(file_id, params)
|
|
930
|
+
print_dry_run @archive_files_interface.dry.get(file_id, params)
|
|
933
931
|
else
|
|
934
|
-
print_dry_run @archive_buckets_interface.dry.list_files(bucket_id, file_path, params)
|
|
932
|
+
print_dry_run @archive_buckets_interface.dry.list_files(bucket_id, file_path, params)
|
|
935
933
|
end
|
|
936
934
|
return 0
|
|
937
935
|
end
|
|
@@ -1211,7 +1209,6 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1211
1209
|
end
|
|
1212
1210
|
|
|
1213
1211
|
def download_file(args)
|
|
1214
|
-
full_command_string = "#{command_name} download #{args.join(' ')}".strip
|
|
1215
1212
|
options = {}
|
|
1216
1213
|
outfile = nil
|
|
1217
1214
|
do_overwrite = false
|
|
@@ -1256,15 +1253,15 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1256
1253
|
# outfile = File.join(outfile, File.basename(full_file_path))
|
|
1257
1254
|
# end
|
|
1258
1255
|
outfile = File.expand_path(outfile)
|
|
1259
|
-
if Dir.
|
|
1256
|
+
if Dir.exist?(outfile)
|
|
1260
1257
|
outfile = File.join(outfile, File.basename(full_file_path))
|
|
1261
1258
|
end
|
|
1262
|
-
if Dir.
|
|
1259
|
+
if Dir.exist?(outfile)
|
|
1263
1260
|
print_red_alert "[local-file] is invalid. It is the name of an existing directory: #{outfile}"
|
|
1264
1261
|
return 1
|
|
1265
1262
|
end
|
|
1266
1263
|
destination_dir = File.dirname(outfile)
|
|
1267
|
-
if !Dir.
|
|
1264
|
+
if !Dir.exist?(destination_dir)
|
|
1268
1265
|
if do_mkdir
|
|
1269
1266
|
print cyan,"Creating local directory #{destination_dir}",reset,"\n"
|
|
1270
1267
|
FileUtils.mkdir_p(destination_dir)
|
|
@@ -1273,7 +1270,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1273
1270
|
return 1
|
|
1274
1271
|
end
|
|
1275
1272
|
end
|
|
1276
|
-
if File.
|
|
1273
|
+
if File.exist?(outfile)
|
|
1277
1274
|
if do_overwrite
|
|
1278
1275
|
# uhh need to be careful wih the passed filepath here..
|
|
1279
1276
|
# don't delete, just overwrite.
|
|
@@ -1288,11 +1285,10 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1288
1285
|
begin
|
|
1289
1286
|
@archive_files_interface.setopts(options)
|
|
1290
1287
|
if options[:dry_run]
|
|
1291
|
-
# print_dry_run @archive_files_interface.dry.download_file_by_path(full_file_path), full_command_string
|
|
1292
1288
|
if use_public_url
|
|
1293
|
-
print_dry_run @archive_files_interface.dry.download_public_file_by_path_chunked(full_file_path, outfile)
|
|
1289
|
+
print_dry_run @archive_files_interface.dry.download_public_file_by_path_chunked(full_file_path, outfile)
|
|
1294
1290
|
else
|
|
1295
|
-
print_dry_run @archive_files_interface.dry.download_file_by_path_chunked(full_file_path, outfile)
|
|
1291
|
+
print_dry_run @archive_files_interface.dry.download_file_by_path_chunked(full_file_path, outfile)
|
|
1296
1292
|
end
|
|
1297
1293
|
return 0
|
|
1298
1294
|
end
|
|
@@ -1322,7 +1318,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1322
1318
|
print red + "ERROR" + reset + " HTTP #{http_response.code}" + "\n"
|
|
1323
1319
|
end
|
|
1324
1320
|
# F it, just remove a bad result
|
|
1325
|
-
if File.
|
|
1321
|
+
if File.exist?(outfile) && File.file?(outfile)
|
|
1326
1322
|
Morpheus::Logging::DarkPrinter.puts "Deleting bad file download: #{outfile}" if Morpheus::Logging.debug?
|
|
1327
1323
|
File.delete(outfile)
|
|
1328
1324
|
end
|
|
@@ -1348,7 +1344,6 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1348
1344
|
end
|
|
1349
1345
|
|
|
1350
1346
|
def read_file(args)
|
|
1351
|
-
full_command_string = "archives read #{args.join(' ')}".strip
|
|
1352
1347
|
options = {}
|
|
1353
1348
|
outfile = nil
|
|
1354
1349
|
do_overwrite = false
|
|
@@ -1374,7 +1369,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1374
1369
|
full_file_path = "#{bucket_id}/#{file_path}".squeeze('/')
|
|
1375
1370
|
@archive_files_interface.setopts(options)
|
|
1376
1371
|
if options[:dry_run]
|
|
1377
|
-
print_dry_run @archive_files_interface.dry.download_file_by_path(full_file_path)
|
|
1372
|
+
print_dry_run @archive_files_interface.dry.download_file_by_path(full_file_path)
|
|
1378
1373
|
return 1
|
|
1379
1374
|
end
|
|
1380
1375
|
if archive_file['rawSize'].to_i > 1024
|
|
@@ -1497,7 +1492,6 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1497
1492
|
end
|
|
1498
1493
|
|
|
1499
1494
|
def download_file_link(args)
|
|
1500
|
-
full_command_string = "archives download-link #{args.join(' ')}".strip
|
|
1501
1495
|
options = {}
|
|
1502
1496
|
outfile = nil
|
|
1503
1497
|
do_overwrite = false
|
|
@@ -1533,15 +1527,15 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1533
1527
|
# full_file_path = args[0]
|
|
1534
1528
|
outfile = File.expand_path(args[1])
|
|
1535
1529
|
# [local-file] must include the full file name when downloading a link
|
|
1536
|
-
# if Dir.
|
|
1530
|
+
# if Dir.exist?(outfile)
|
|
1537
1531
|
# outfile = File.join(outfile, File.basename(archive_file['name']))
|
|
1538
1532
|
# end
|
|
1539
|
-
if Dir.
|
|
1533
|
+
if Dir.exist?(outfile)
|
|
1540
1534
|
print_red_alert "[local-file] is invalid. It is the name of an existing directory: #{outfile}"
|
|
1541
1535
|
return 1
|
|
1542
1536
|
end
|
|
1543
1537
|
destination_dir = File.dirname(outfile)
|
|
1544
|
-
if !Dir.
|
|
1538
|
+
if !Dir.exist?(destination_dir)
|
|
1545
1539
|
if do_mkdir
|
|
1546
1540
|
print cyan,"Creating local directory #{destination_dir}",reset,"\n"
|
|
1547
1541
|
FileUtils.mkdir_p(destination_dir)
|
|
@@ -1550,7 +1544,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1550
1544
|
return 1
|
|
1551
1545
|
end
|
|
1552
1546
|
end
|
|
1553
|
-
if File.
|
|
1547
|
+
if File.exist?(outfile)
|
|
1554
1548
|
if do_overwrite
|
|
1555
1549
|
# uhh need to be careful wih the passed filepath here..
|
|
1556
1550
|
# don't delete, just overwrite.
|
|
@@ -1566,8 +1560,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1566
1560
|
end
|
|
1567
1561
|
@archive_files_interface.setopts(options)
|
|
1568
1562
|
if options[:dry_run]
|
|
1569
|
-
|
|
1570
|
-
print_dry_run @archive_files_interface.dry.download_file_by_link_chunked(link_key, outfile), full_command_string
|
|
1563
|
+
print_dry_run @archive_files_interface.dry.download_file_by_link_chunked(link_key, outfile)
|
|
1571
1564
|
return 1
|
|
1572
1565
|
end
|
|
1573
1566
|
if !options[:quiet]
|
|
@@ -1591,7 +1584,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1591
1584
|
print red + "ERROR" + reset + " HTTP #{http_response.code}" + "\n"
|
|
1592
1585
|
end
|
|
1593
1586
|
# F it, just remove a bad result
|
|
1594
|
-
if File.
|
|
1587
|
+
if File.exist?(outfile) && File.file?(outfile)
|
|
1595
1588
|
Morpheus::Logging::DarkPrinter.puts "Deleting bad file download: #{outfile}" if Morpheus::Logging.debug?
|
|
1596
1589
|
File.delete(outfile)
|
|
1597
1590
|
end
|
|
@@ -1608,7 +1601,6 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1608
1601
|
end
|
|
1609
1602
|
|
|
1610
1603
|
def download_bucket_zip(args)
|
|
1611
|
-
full_command_string = "#{command_name} download-bucket #{args.join(' ')}".strip
|
|
1612
1604
|
options = {}
|
|
1613
1605
|
outfile = nil
|
|
1614
1606
|
do_overwrite = false
|
|
@@ -1651,10 +1643,10 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1651
1643
|
# outfile = File.join(outfile, archive_bucket['name'].to_s) + ".zip"
|
|
1652
1644
|
# end
|
|
1653
1645
|
outfile = File.expand_path(outfile)
|
|
1654
|
-
if Dir.
|
|
1646
|
+
if Dir.exist?(outfile)
|
|
1655
1647
|
outfile = File.join(outfile, archive_bucket['name'].to_s) + ".zip"
|
|
1656
1648
|
end
|
|
1657
|
-
if Dir.
|
|
1649
|
+
if Dir.exist?(outfile)
|
|
1658
1650
|
print_red_alert "[local-file] is invalid. It is the name of an existing directory: #{outfile}"
|
|
1659
1651
|
return 1
|
|
1660
1652
|
end
|
|
@@ -1663,7 +1655,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1663
1655
|
outfile << ".zip"
|
|
1664
1656
|
end
|
|
1665
1657
|
destination_dir = File.dirname(outfile)
|
|
1666
|
-
if !Dir.
|
|
1658
|
+
if !Dir.exist?(destination_dir)
|
|
1667
1659
|
if do_mkdir
|
|
1668
1660
|
print cyan,"Creating local directory #{destination_dir}",reset,"\n"
|
|
1669
1661
|
FileUtils.mkdir_p(destination_dir)
|
|
@@ -1672,7 +1664,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1672
1664
|
return 1
|
|
1673
1665
|
end
|
|
1674
1666
|
end
|
|
1675
|
-
if File.
|
|
1667
|
+
if File.exist?(outfile)
|
|
1676
1668
|
if do_overwrite
|
|
1677
1669
|
# uhh need to be careful wih the passed filepath here..
|
|
1678
1670
|
# don't delete, just overwrite.
|
|
@@ -1686,7 +1678,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1686
1678
|
end
|
|
1687
1679
|
@archive_buckets_interface.setopts(options)
|
|
1688
1680
|
if options[:dry_run]
|
|
1689
|
-
print_dry_run @archive_buckets_interface.dry.download_bucket_zip_chunked(bucket_id, outfile)
|
|
1681
|
+
print_dry_run @archive_buckets_interface.dry.download_bucket_zip_chunked(bucket_id, outfile)
|
|
1690
1682
|
return 1
|
|
1691
1683
|
end
|
|
1692
1684
|
if !options[:quiet]
|
|
@@ -1707,7 +1699,7 @@ class Morpheus::Cli::ArchivesCommand
|
|
|
1707
1699
|
print red + "ERROR" + reset + " HTTP #{http_response.code}" + "\n"
|
|
1708
1700
|
end
|
|
1709
1701
|
# F it, just remove a bad result
|
|
1710
|
-
if File.
|
|
1702
|
+
if File.exist?(outfile) && File.file?(outfile)
|
|
1711
1703
|
Morpheus::Logging::DarkPrinter.puts "Deleting bad file download: #{outfile}" if Morpheus::Logging.debug?
|
|
1712
1704
|
File.delete(outfile)
|
|
1713
1705
|
end
|