morpheus-cli 4.2.19 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/lib/morpheus/api/api_client.rb +26 -0
- data/lib/morpheus/api/billing_interface.rb +34 -0
- data/lib/morpheus/api/catalog_item_types_interface.rb +9 -0
- data/lib/morpheus/api/deploy_interface.rb +1 -1
- data/lib/morpheus/api/deployments_interface.rb +20 -1
- data/lib/morpheus/api/forgot_password_interface.rb +17 -0
- data/lib/morpheus/api/instances_interface.rb +7 -0
- data/lib/morpheus/api/rest_interface.rb +0 -6
- data/lib/morpheus/api/roles_interface.rb +14 -0
- data/lib/morpheus/api/search_interface.rb +13 -0
- data/lib/morpheus/api/servers_interface.rb +7 -0
- data/lib/morpheus/api/usage_interface.rb +18 -0
- data/lib/morpheus/cli.rb +6 -3
- data/lib/morpheus/cli/apps.rb +3 -4
- data/lib/morpheus/cli/backup_jobs_command.rb +3 -0
- data/lib/morpheus/cli/backups_command.rb +3 -0
- data/lib/morpheus/cli/budgets_command.rb +4 -4
- data/lib/morpheus/cli/catalog_command.rb +507 -0
- data/lib/morpheus/cli/cli_command.rb +45 -20
- data/lib/morpheus/cli/cloud_resource_pools_command.rb +16 -0
- data/lib/morpheus/cli/commands/standard/curl_command.rb +26 -12
- data/lib/morpheus/cli/commands/standard/history_command.rb +3 -1
- data/lib/morpheus/cli/commands/standard/man_command.rb +74 -40
- data/lib/morpheus/cli/commands/standard/source_command.rb +1 -1
- data/lib/morpheus/cli/commands/standard/update_command.rb +76 -0
- data/lib/morpheus/cli/containers_command.rb +14 -0
- data/lib/morpheus/cli/deploy.rb +199 -90
- data/lib/morpheus/cli/deployments.rb +342 -29
- data/lib/morpheus/cli/deploys.rb +206 -41
- data/lib/morpheus/cli/error_handler.rb +7 -0
- data/lib/morpheus/cli/forgot_password.rb +133 -0
- data/lib/morpheus/cli/health_command.rb +2 -2
- data/lib/morpheus/cli/hosts.rb +193 -28
- data/lib/morpheus/cli/instances.rb +102 -33
- data/lib/morpheus/cli/invoices_command.rb +33 -16
- data/lib/morpheus/cli/jobs_command.rb +28 -6
- data/lib/morpheus/cli/library_instance_types_command.rb +17 -3
- data/lib/morpheus/cli/library_option_lists_command.rb +14 -6
- data/lib/morpheus/cli/logs_command.rb +9 -6
- data/lib/morpheus/cli/mixins/accounts_helper.rb +7 -6
- data/lib/morpheus/cli/mixins/backups_helper.rb +2 -4
- data/lib/morpheus/cli/mixins/catalog_helper.rb +66 -0
- data/lib/morpheus/cli/mixins/deployments_helper.rb +31 -3
- data/lib/morpheus/cli/mixins/option_source_helper.rb +1 -1
- data/lib/morpheus/cli/mixins/print_helper.rb +46 -21
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +24 -4
- data/lib/morpheus/cli/network_pools_command.rb +14 -6
- data/lib/morpheus/cli/option_types.rb +266 -17
- data/lib/morpheus/cli/ping.rb +0 -1
- data/lib/morpheus/cli/provisioning_licenses_command.rb +2 -2
- data/lib/morpheus/cli/remote.rb +35 -12
- data/lib/morpheus/cli/reports_command.rb +99 -30
- data/lib/morpheus/cli/roles.rb +305 -3
- data/lib/morpheus/cli/search_command.rb +182 -0
- data/lib/morpheus/cli/service_plans_command.rb +2 -2
- data/lib/morpheus/cli/setup.rb +1 -1
- data/lib/morpheus/cli/shell.rb +33 -11
- data/lib/morpheus/cli/storage_providers_command.rb +40 -56
- data/lib/morpheus/cli/tasks.rb +20 -21
- data/lib/morpheus/cli/tenants_command.rb +1 -1
- data/lib/morpheus/cli/usage_command.rb +203 -0
- data/lib/morpheus/cli/user_settings_command.rb +1 -0
- data/lib/morpheus/cli/users.rb +12 -1
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/virtual_images.rb +280 -199
- data/lib/morpheus/cli/whoami.rb +6 -6
- data/lib/morpheus/cli/workflows.rb +34 -41
- data/lib/morpheus/formatters.rb +48 -5
- data/lib/morpheus/terminal.rb +6 -2
- metadata +13 -2
@@ -194,7 +194,7 @@ module Morpheus
|
|
194
194
|
if option_type['placeHolder']
|
195
195
|
value_label = option_type['placeHolder']
|
196
196
|
elsif option_type['type'] == 'checkbox'
|
197
|
-
value_label = 'on|off' # or.. true|false
|
197
|
+
value_label = '[on|off]' # or.. true|false
|
198
198
|
elsif option_type['type'] == 'number'
|
199
199
|
value_label = 'NUMBER'
|
200
200
|
elsif option_type['type'] == 'multiSelect'
|
@@ -204,12 +204,16 @@ module Morpheus
|
|
204
204
|
# elsif option['type'] == 'select'
|
205
205
|
end
|
206
206
|
opts.on("--#{full_field_name} #{value_label}", String, description) do |val|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
207
|
+
if option_type['type'] == 'checkbox'
|
208
|
+
val = (val.to_s != 'false' && val.to_s != 'off')
|
209
|
+
else
|
210
|
+
# attempt to parse JSON, this allows blank arrays for multiSelect like --tenants []
|
211
|
+
if (val.to_s[0] == '{' && val.to_s[-1] == '}') || (val.to_s[0] == '[' && val.to_s[-1] == ']')
|
212
|
+
begin
|
213
|
+
val = JSON.parse(val)
|
214
|
+
rescue
|
215
|
+
Morpheus::Logging::DarkPrinter.puts "Failed to parse option value '#{val}' as JSON" if Morpheus::Logging.debug?
|
216
|
+
end
|
213
217
|
end
|
214
218
|
end
|
215
219
|
cur_namespace = custom_options
|
@@ -305,6 +309,15 @@ module Morpheus
|
|
305
309
|
opts.add_hidden_option('-a, --account') if opts.is_a?(Morpheus::Cli::OptionParser)
|
306
310
|
opts.add_hidden_option('-A, --account-id') if opts.is_a?(Morpheus::Cli::OptionParser)
|
307
311
|
|
312
|
+
when :details
|
313
|
+
opts.on('-a', '--all', "Show all details." ) do
|
314
|
+
options[:details] = true
|
315
|
+
end
|
316
|
+
opts.on('--details', '--details', "Show more details" ) do
|
317
|
+
options[:details] = true
|
318
|
+
end
|
319
|
+
opts.add_hidden_option('--details')
|
320
|
+
|
308
321
|
when :options
|
309
322
|
options[:options] ||= {}
|
310
323
|
opts.on( '-O', '--option OPTION', "Option in the format -O field=\"value\"" ) do |option|
|
@@ -489,13 +502,17 @@ module Morpheus
|
|
489
502
|
|
490
503
|
when :query, :query_filters
|
491
504
|
# arbitrary query parameters in the format -Q "category=web&phrase=nginx"
|
505
|
+
# or pass it many times like -Q foo=bar -Q hello=world
|
492
506
|
opts.on( '-Q', '--query PARAMS', "Query parameters. PARAMS format is 'foo=bar&category=web'" ) do |val|
|
493
|
-
options[:query_filters_raw]
|
494
|
-
|
495
|
-
|
507
|
+
if options[:query_filters_raw] && !options[:query_filters_raw].empty?
|
508
|
+
options[:query_filters_raw] += ("&" + val)
|
509
|
+
else
|
510
|
+
options[:query_filters_raw] = val
|
511
|
+
end
|
512
|
+
options[:query_filters] ||= {}
|
496
513
|
val.split('&').each do |filter|
|
497
514
|
k, v = filter.split('=')
|
498
|
-
# allow
|
515
|
+
# allow woot:true instead of woot=true
|
499
516
|
if (k.include?(":") && v == nil)
|
500
517
|
k, v = k.split(":")
|
501
518
|
end
|
@@ -594,13 +611,13 @@ module Morpheus
|
|
594
611
|
end
|
595
612
|
# opts.add_hidden_option('-H') if opts.is_a?(Morpheus::Cli::OptionParser)
|
596
613
|
# opts.add_hidden_option('--header') if opts.is_a?(Morpheus::Cli::OptionParser)
|
597
|
-
opts.add_hidden_option('--
|
614
|
+
opts.add_hidden_option('-H, --header') if opts.is_a?(Morpheus::Cli::OptionParser)
|
598
615
|
|
599
616
|
#when :timeout
|
600
617
|
opts.on( '--timeout SECONDS', "Timeout for api requests. Default is typically 30 seconds." ) do |val|
|
601
618
|
options[:timeout] = val ? val.to_f : nil
|
602
619
|
end
|
603
|
-
|
620
|
+
opts.add_hidden_option('--timeout') if opts.is_a?(Morpheus::Cli::OptionParser)
|
604
621
|
|
605
622
|
when :auto_confirm
|
606
623
|
opts.on( '-y', '--yes', "Auto Confirm" ) do
|
@@ -707,7 +724,7 @@ module Morpheus
|
|
707
724
|
|
708
725
|
|
709
726
|
when :dry_run
|
710
|
-
opts.on('-d','--dry-run', "Dry Run, print the API request instead of executing it") do
|
727
|
+
opts.on('-d','--dry-run', "Dry Run, print the API request instead of executing it.") do
|
711
728
|
# todo: this should print after parsing obv..
|
712
729
|
# need a hook after parse! or a standard_handle(options) { ... } paradigm
|
713
730
|
# either that or hook it up in every command somehow, maybe a hook on connect()
|
@@ -719,7 +736,7 @@ module Morpheus
|
|
719
736
|
end
|
720
737
|
options[:dry_run] = true
|
721
738
|
end
|
722
|
-
opts.on(nil,'--curl', "
|
739
|
+
opts.on(nil,'--curl', "Curl, print the API request as a curl command instead of executing it.") do
|
723
740
|
# print once and dont munge json
|
724
741
|
if !options[:dry_run] && !options[:json]
|
725
742
|
puts "#{cyan}#{bold}#{dark}DRY RUN#{reset}"
|
@@ -822,6 +839,10 @@ module Morpheus
|
|
822
839
|
opts
|
823
840
|
end
|
824
841
|
|
842
|
+
def prog_name
|
843
|
+
self.class.prog_name
|
844
|
+
end
|
845
|
+
|
825
846
|
def command_name
|
826
847
|
self.class.command_name
|
827
848
|
end
|
@@ -862,14 +883,14 @@ module Morpheus
|
|
862
883
|
|
863
884
|
def usage
|
864
885
|
if !subcommands.empty?
|
865
|
-
"Usage:
|
886
|
+
"Usage: #{prog_name} #{command_name} [command] [options]"
|
866
887
|
else
|
867
|
-
"Usage:
|
888
|
+
"Usage: #{prog_name} #{command_name} [options]"
|
868
889
|
end
|
869
890
|
end
|
870
891
|
|
871
892
|
def my_help_command
|
872
|
-
"
|
893
|
+
"#{prog_name} #{command_name} --help"
|
873
894
|
end
|
874
895
|
|
875
896
|
def subcommand_usage(*extra)
|
@@ -880,7 +901,7 @@ module Morpheus
|
|
880
901
|
extra.shift
|
881
902
|
end
|
882
903
|
#extra = ["[options]"] if extra.empty?
|
883
|
-
"Usage:
|
904
|
+
"Usage: #{prog_name} #{command_name} #{subcommand_name} #{extra.join(' ')}".squeeze(' ').strip
|
884
905
|
end
|
885
906
|
|
886
907
|
# a string to describe the usage of your command
|
@@ -931,7 +952,7 @@ module Morpheus
|
|
931
952
|
end
|
932
953
|
cmd_method = subcommands[subcommand_name]
|
933
954
|
if !cmd_method
|
934
|
-
error_msg = "'#{command_name} #{subcommand_name}' is not a
|
955
|
+
error_msg = "'#{command_name} #{subcommand_name}' is not a #{prog_name} command.\n#{full_command_usage}"
|
935
956
|
raise CommandNotFoundError.new(error_msg)
|
936
957
|
end
|
937
958
|
self.send(cmd_method, args[1..-1])
|
@@ -1287,6 +1308,10 @@ module Morpheus
|
|
1287
1308
|
|
1288
1309
|
module ClassMethods
|
1289
1310
|
|
1311
|
+
def prog_name
|
1312
|
+
"morpheus"
|
1313
|
+
end
|
1314
|
+
|
1290
1315
|
def set_command_name(cmd_name)
|
1291
1316
|
@command_name = cmd_name
|
1292
1317
|
Morpheus::Cli::CliRegistry.add(self, self.command_name)
|
@@ -326,6 +326,9 @@ class Morpheus::Cli::CloudResourcePoolsCommand
|
|
326
326
|
opts.on('--active [on|off]', String, "Can be used to disable a resource pool") do |val|
|
327
327
|
options['active'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
328
328
|
end
|
329
|
+
opts.on('--default-pool [on|off]', String, "Set resource pool as the default") do |val|
|
330
|
+
options['defaultPool'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
331
|
+
end
|
329
332
|
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
330
333
|
opts.footer = "Update a resource pool." + "\n" +
|
331
334
|
"[cloud] is required. This is the name or id of the cloud."
|
@@ -437,6 +440,11 @@ class Morpheus::Cli::CloudResourcePoolsCommand
|
|
437
440
|
else
|
438
441
|
payload['resourcePool']['active'] = true
|
439
442
|
end
|
443
|
+
|
444
|
+
# Default
|
445
|
+
if options['defaultPool'] != nil
|
446
|
+
payload['resourcePool']['defaultPool'] = options['defaultPool']
|
447
|
+
end
|
440
448
|
|
441
449
|
# Visibility
|
442
450
|
if options['visibility'] != nil
|
@@ -552,6 +560,9 @@ class Morpheus::Cli::CloudResourcePoolsCommand
|
|
552
560
|
opts.on('--active [on|off]', String, "Can be used to disable a resource pool") do |val|
|
553
561
|
options['active'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
554
562
|
end
|
563
|
+
opts.on('--default-pool [on|off]', String, "Set resource pool as the default") do |val|
|
564
|
+
options['defaultPool'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
565
|
+
end
|
555
566
|
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
556
567
|
opts.footer = "Update a resource pool." + "\n" +
|
557
568
|
"[cloud] is required. This is the name or id of the cloud." + "\n"
|
@@ -641,6 +652,11 @@ class Morpheus::Cli::CloudResourcePoolsCommand
|
|
641
652
|
if options['active'] != nil
|
642
653
|
payload['resourcePool']['active'] = options['active']
|
643
654
|
end
|
655
|
+
|
656
|
+
# Default
|
657
|
+
if options['defaultPool'] != nil
|
658
|
+
payload['resourcePool']['defaultPool'] = options['defaultPool']
|
659
|
+
end
|
644
660
|
|
645
661
|
# Visibility
|
646
662
|
if options['visibility'] != nil
|
@@ -9,15 +9,20 @@ class Morpheus::Cli::CurlCommand
|
|
9
9
|
set_command_hidden
|
10
10
|
|
11
11
|
def handle(args)
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
# support syntax for arbitrary curl args after " -- "
|
13
|
+
# eg. curl /api/instances -- -ksv
|
14
|
+
split_index = args.index("--")
|
15
|
+
curl_args = []
|
16
|
+
if split_index
|
17
|
+
if args.length > (split_index + 1)
|
18
|
+
curl_args = args[(split_index + 1)..-1]
|
19
|
+
end
|
20
|
+
args = args[0..(split_index - 1)]
|
21
|
+
end
|
15
22
|
curl_method = nil
|
16
23
|
curl_data = nil
|
17
24
|
curl_verbsose = false
|
18
25
|
show_progress = false
|
19
|
-
# puts "args is : #{args}"
|
20
|
-
# puts "curl_args is : #{curl_args}"
|
21
26
|
options = {}
|
22
27
|
optparse = Morpheus::Cli::OptionParser.new do|opts|
|
23
28
|
opts.banner = "Usage: morpheus curl [path] -- [*args]"
|
@@ -36,7 +41,7 @@ class Morpheus::Cli::CurlCommand
|
|
36
41
|
opts.on( '--progress', '--progress', "Display progress output by excluding the -s option." ) do
|
37
42
|
show_progress = true
|
38
43
|
end
|
39
|
-
build_common_options(opts, options, [:dry_run, :remote])
|
44
|
+
build_common_options(opts, options, [:dry_run, :json, :remote])
|
40
45
|
opts.add_hidden_option('--curl')
|
41
46
|
#opts.add_hidden_option('--scrub')
|
42
47
|
opts.footer = <<-EOT
|
@@ -98,16 +103,27 @@ EOT
|
|
98
103
|
end
|
99
104
|
curl_cmd << " \"#{url}\""
|
100
105
|
if @access_token
|
101
|
-
|
106
|
+
if !(options[:headers] && options[:headers]['Authorization'])
|
107
|
+
curl_cmd << " -H \"Authorization: Bearer #{@access_token}\""
|
108
|
+
end
|
102
109
|
end
|
103
110
|
if curl_data
|
104
111
|
#todo: curl_data.gsub("'","\\'")
|
105
112
|
curl_cmd << " --data '#{curl_data}'"
|
113
|
+
if api_path !~ /^\/?oauth/
|
114
|
+
if !(options[:headers] && options[:headers]['Content-Type'])
|
115
|
+
curl_cmd << " -H \"Content-Type: application/json\""
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
if options[:headers]
|
120
|
+
options[:headers].each do |k,v|
|
121
|
+
curl_cmd << " -H \"#{k}: #{v}\""
|
122
|
+
end
|
106
123
|
end
|
107
124
|
if !curl_args.empty?
|
108
125
|
curl_cmd << " " + curl_args.join(' ')
|
109
126
|
end
|
110
|
-
|
111
127
|
# Morpheus::Logging::DarkPrinter.puts "#{curl_cmd}" if Morpheus::Logging.debug?
|
112
128
|
curl_cmd_str = options[:scrub] ? Morpheus::Logging.scrub_message(curl_cmd) : curl_cmd
|
113
129
|
|
@@ -124,16 +140,14 @@ EOT
|
|
124
140
|
print reset
|
125
141
|
# print result
|
126
142
|
curl_output = `#{curl_cmd}`
|
127
|
-
if options[:pretty]
|
143
|
+
if options[:pretty] || options[:json]
|
128
144
|
output_lines = curl_output.split("\n")
|
129
145
|
last_line = output_lines.pop
|
130
146
|
if output_lines.size > 0
|
131
147
|
puts output_lines.join("\n")
|
132
148
|
end
|
133
149
|
begin
|
134
|
-
|
135
|
-
json_string = JSON.pretty_generate(json_data)
|
136
|
-
puts json_string
|
150
|
+
puts as_json(JSON.parse(last_line), options)
|
137
151
|
rescue => ex
|
138
152
|
Morpheus::Logging::DarkPrinter.puts "failed to parse curl result as JSON data Error: #{ex.message}" if Morpheus::Logging.debug?
|
139
153
|
puts last_line
|
@@ -6,7 +6,9 @@ require 'morpheus/cli/cli_command'
|
|
6
6
|
class Morpheus::Cli::HistoryCommand
|
7
7
|
include Morpheus::Cli::CliCommand
|
8
8
|
set_command_name :'history'
|
9
|
-
|
9
|
+
set_command_description "View morpheus shell command history"
|
10
|
+
# hidden for now because it is a shell command, shouldnt just be shell command though
|
11
|
+
set_command_hidden
|
10
12
|
|
11
13
|
# todo: support all the other :list options too, not just max
|
12
14
|
# AND start logging every terminal command, not just shell...
|
@@ -9,7 +9,7 @@ class Morpheus::Cli::ManCommand
|
|
9
9
|
|
10
10
|
# this should be read only anyway...
|
11
11
|
@@default_editor = "less" # ENV['EDITOR']
|
12
|
-
|
12
|
+
|
13
13
|
def handle(args)
|
14
14
|
options = {}
|
15
15
|
regenerate = false
|
@@ -28,6 +28,12 @@ class Morpheus::Cli::ManCommand
|
|
28
28
|
opts.on('-g','--generate', "Regenerate the manual file") do
|
29
29
|
regenerate = true
|
30
30
|
end
|
31
|
+
opts.on('-o','--out FILE', "Write manual file to a custom location") do |val|
|
32
|
+
options[:outfile] = val
|
33
|
+
end
|
34
|
+
opts.on('--overwrite', '--overwrite', "Overwrite output file if it already exists.") do |val|
|
35
|
+
options[:overwrite] = true
|
36
|
+
end
|
31
37
|
opts.on('-q','--quiet', "Do not open manual, for use with the -g option.") do
|
32
38
|
options[:quiet] = true
|
33
39
|
end
|
@@ -47,7 +53,8 @@ class Morpheus::Cli::ManCommand
|
|
47
53
|
end
|
48
54
|
opts.footer = <<-EOT
|
49
55
|
Open the morpheus manual located at #{Morpheus::Cli::ManCommand.man_file_path}
|
50
|
-
The -g
|
56
|
+
The -g option can be used to regenerate the file.
|
57
|
+
The --out FILE option be used to write the manual file to a custom location.
|
51
58
|
EOT
|
52
59
|
end
|
53
60
|
optparse.parse!(args)
|
@@ -65,18 +72,35 @@ EOT
|
|
65
72
|
end
|
66
73
|
|
67
74
|
fn = Morpheus::Cli::ManCommand.man_file_path
|
75
|
+
if options[:outfile]
|
76
|
+
regenerate = true
|
77
|
+
fn = File.expand_path(options[:outfile])
|
78
|
+
if File.directory?(fn)
|
79
|
+
# if you give me a directory, could still work and use the default filename
|
80
|
+
# fn = File.join(fn, "CLI-Manual-#{Morpheus::Cli::VERSION}.md")
|
81
|
+
# raise_command_error "outfile is invalid. It is the name of an existing directory: #{fn}"
|
82
|
+
print_error "#{red}Output file '#{fn}' is invalid.#{reset}\n"
|
83
|
+
print_error "#{red}It is the name of an existing directory.#{reset}\n"
|
84
|
+
return 1
|
85
|
+
end
|
86
|
+
if File.exists?(fn) && options[:overwrite] != true
|
87
|
+
print_error "#{red}Output file '#{fn}' already exists.#{reset}\n"
|
88
|
+
print_error "#{red}Use --overwrite to overwrite the existing file.#{reset}\n"
|
89
|
+
return 1
|
90
|
+
end
|
91
|
+
end
|
92
|
+
exit_code, err = 0, nil
|
68
93
|
if regenerate || !File.exists?(fn)
|
69
94
|
#Morpheus::Logging::DarkPrinter.puts "generating manual #{fn} ..." if Morpheus::Logging.debug? && !options[:quiet]
|
70
|
-
Morpheus::Cli::ManCommand.generate_manual(options)
|
95
|
+
exit_code, err = Morpheus::Cli::ManCommand.generate_manual(options)
|
71
96
|
end
|
72
97
|
|
73
98
|
if options[:quiet]
|
74
|
-
return
|
99
|
+
return exit_code, err
|
75
100
|
end
|
76
101
|
|
77
102
|
Morpheus::Logging::DarkPrinter.puts "opening manual file #{fn}" if Morpheus::Logging.debug? && !options[:quiet]
|
78
103
|
|
79
|
-
|
80
104
|
if open_as_link # not used atm
|
81
105
|
link = "file://#{fn}"
|
82
106
|
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
@@ -138,6 +162,14 @@ EOT
|
|
138
162
|
# todo: use pandoc or something else to convert the CLI-Manual.md to a man page
|
139
163
|
# and install it, so the os command `man morpheus` will work too.
|
140
164
|
fn = man_file_path()
|
165
|
+
if options[:outfile]
|
166
|
+
fn = File.expand_path(options[:outfile])
|
167
|
+
if File.exists?(fn) && options[:overwrite] != true
|
168
|
+
print_error "#{red}Output file '#{options[:outfile]}' already exists.#{reset}\n"
|
169
|
+
print_error "#{red}Use --overwrite to overwrite the existing file.#{reset}\n"
|
170
|
+
return 1, "output file already exists"
|
171
|
+
end
|
172
|
+
end
|
141
173
|
if !Dir.exists?(File.dirname(fn))
|
142
174
|
FileUtils.mkdir_p(File.dirname(fn))
|
143
175
|
end
|
@@ -153,7 +185,7 @@ EOT
|
|
153
185
|
begin
|
154
186
|
|
155
187
|
manpage.print <<-ENDTEXT
|
156
|
-
|
188
|
+
#{prog_name} v#{Morpheus::Cli::VERSION}
|
157
189
|
|
158
190
|
## NAME
|
159
191
|
|
@@ -170,17 +202,17 @@ morpheus v#{Morpheus::Cli::VERSION}
|
|
170
202
|
This is a command line interface for managing a Morpheus Appliance.
|
171
203
|
All communication with the remote appliance is done via the Morpheus API.
|
172
204
|
|
173
|
-
|
205
|
+
Use the command `#{prog_name} remote add` to connect to your Morpheus appliance.
|
174
206
|
|
175
207
|
To learn more, visit https://github.com/gomorpheus/morpheus-cli/wiki/Getting-Started
|
176
208
|
|
177
|
-
To learn more about the Morpheus Appliance, visit https://www.morpheusdata.com
|
209
|
+
To learn more about the Morpheus Appliance, visit https://www.morpheusdata.com
|
178
210
|
|
179
211
|
To learn more about the Morpheus API, visit https://apidocs.morpheusdata.com
|
180
212
|
|
181
213
|
## GLOBAL OPTIONS
|
182
214
|
|
183
|
-
|
215
|
+
There are several global options available.
|
184
216
|
|
185
217
|
-v, --version Print the version.
|
186
218
|
--noprofile Do not read and execute the personal initialization script .morpheus_profile
|
@@ -190,30 +222,42 @@ morpheus v#{Morpheus::Cli::VERSION}
|
|
190
222
|
|
191
223
|
## COMMON OPTIONS
|
192
224
|
|
193
|
-
There are
|
225
|
+
There are many common options that are supported by a most commands.
|
194
226
|
|
195
227
|
-O, --option OPTION Option value in the format -O var="value" (deprecated soon in favor of first class options)
|
196
228
|
-N, --no-prompt Skip prompts. Use default values for all optional fields.
|
229
|
+
--payload FILE Payload from a local JSON or YAML file, skip all prompting
|
230
|
+
--payload-dir DIRECTORY Payload from a local directory containing 1-N JSON or YAML files, skip all prompting
|
231
|
+
--payload-json JSON Payload JSON, skip all prompting
|
232
|
+
--payload-yaml YAML Payload YAML, skip all prompting
|
197
233
|
-j, --json JSON Output
|
198
234
|
-d, --dry-run Dry Run, print the API request instead of executing it
|
199
|
-
|
200
|
-
|
201
|
-
-
|
202
|
-
|
235
|
+
--curl Dry Run to output API request as a curl command.
|
236
|
+
--scrub Mask secrets in output, such as the Authorization header. For use with --curl and --dry-run.
|
237
|
+
-r, --remote REMOTE Remote name. The current remote is used by default.
|
238
|
+
--remote-url URL Remote url. This allows adhoc requests instead of using a configured remote.
|
239
|
+
-T, --token TOKEN Access token for authentication with --remote. Saved credentials are used by default.
|
240
|
+
-U, --username USERNAME Username for authentication.
|
241
|
+
-P, --password PASSWORD Password for authentication.
|
242
|
+
-I, --insecure Allow insecure HTTPS communication. i.e. bad SSL certificate.
|
243
|
+
-H, --header HEADER Additional HTTP header to include with requests.
|
244
|
+
--timeout SECONDS Timeout for api requests. Default is typically 30 seconds.
|
245
|
+
-y, --yes Auto Confirm
|
246
|
+
-q, --quiet No Output, do not print to stdout
|
203
247
|
|
204
248
|
## MORPHEUS COMMANDS
|
205
249
|
|
206
|
-
|
207
|
-
|
250
|
+
The morpheus executable is divided into commands.
|
251
|
+
Each morpheus command may have 0-N sub-commands that it supports.
|
208
252
|
Commands generally map to the functionality provided in the Morpheus UI.
|
209
253
|
|
210
254
|
You can get help for any morpheus command by using the -h option.
|
211
255
|
|
212
|
-
The available commands and their options are
|
256
|
+
The available commands and their options are documented below.
|
213
257
|
ENDTEXT
|
214
258
|
|
215
259
|
terminal = Morpheus::Terminal.new($stdin, manpage)
|
216
|
-
Morpheus::Logging::DarkPrinter.puts "appending command help
|
260
|
+
Morpheus::Logging::DarkPrinter.puts "appending command help `#{prog_name} --help`" if Morpheus::Logging.debug? && !options[:quiet]
|
217
261
|
|
218
262
|
manpage.print "\n"
|
219
263
|
manpage.print "## morpheus\n"
|
@@ -226,7 +270,7 @@ ENDTEXT
|
|
226
270
|
Morpheus::Cli::CliRegistry.all.keys.sort.each do |cmd|
|
227
271
|
cmd_klass = Morpheus::Cli::CliRegistry.instance.get(cmd)
|
228
272
|
cmd_instance = cmd_klass.new
|
229
|
-
Morpheus::Logging::DarkPrinter.puts "appending command help
|
273
|
+
Morpheus::Logging::DarkPrinter.puts "appending command help `#{prog_name} #{cmd} --help`" if Morpheus::Logging.debug? && !options[:quiet]
|
230
274
|
#help_cmd = "morpheus #{cmd} --help"
|
231
275
|
#help_output = `#{help_cmd}`
|
232
276
|
manpage.print "\n"
|
@@ -243,7 +287,7 @@ ENDTEXT
|
|
243
287
|
subcommands = cmd_klass.visible_subcommands
|
244
288
|
if subcommands && subcommands.size > 0
|
245
289
|
subcommands.sort.each do |subcommand, subcommand_method|
|
246
|
-
Morpheus::Logging::DarkPrinter.puts "appending command help
|
290
|
+
Morpheus::Logging::DarkPrinter.puts "appending command help `#{prog_name} #{cmd} #{subcommand} --help`" if Morpheus::Logging.debug? && !options[:quiet]
|
247
291
|
manpage.print "\n"
|
248
292
|
manpage.print "#### morpheus #{cmd} #{subcommand}\n"
|
249
293
|
manpage.print "\n"
|
@@ -289,7 +333,7 @@ morpheus> remote list
|
|
289
333
|
Morpheus Appliances
|
290
334
|
==================
|
291
335
|
|
292
|
-
You have no appliances configured. See the
|
336
|
+
You have no appliances configured. See the `#{prog_name} remote add` command.
|
293
337
|
|
294
338
|
```
|
295
339
|
|
@@ -319,11 +363,10 @@ The `appliances` YAML file contains a list of known appliances, keyed by name.
|
|
319
363
|
Example:
|
320
364
|
```yaml
|
321
365
|
:qa:
|
322
|
-
:host: https://qa.
|
366
|
+
:host: https://qa.mymorpheus.com
|
323
367
|
:active: true
|
324
368
|
:production:
|
325
|
-
:host: https://
|
326
|
-
:active: false
|
369
|
+
:host: https://mymorpheus.com
|
327
370
|
```
|
328
371
|
|
329
372
|
### credentials file
|
@@ -349,7 +392,7 @@ This may be inhibited by using the `--noprofile` option.
|
|
349
392
|
|
350
393
|
### .morpheusrc file
|
351
394
|
|
352
|
-
When started as an interactive shell with the
|
395
|
+
When started as an interactive shell with the `#{prog_name} shell` command,
|
353
396
|
Morpheus reads and executes `$MORPHEUS_CLI_HOME/.morpheusrc` (if it exists). This may be inhibited by using the `--norc` option.
|
354
397
|
|
355
398
|
An example startup script might look like this:
|
@@ -357,20 +400,11 @@ An example startup script might look like this:
|
|
357
400
|
```
|
358
401
|
# .morpheusrc
|
359
402
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
# greeting
|
367
|
-
echo "Welcome back human, have fun!"
|
368
|
-
|
369
|
-
# print current user information
|
370
|
-
whoami
|
371
|
-
|
372
|
-
# print the list of instances in our cloud
|
373
|
-
our-instances
|
403
|
+
set-prompt "%cyan%username%reset@%magenta%remote %cyanmorpheus> %reset"
|
404
|
+
version
|
405
|
+
remote current
|
406
|
+
echo "Welcome back %username"
|
407
|
+
echo
|
374
408
|
|
375
409
|
```
|
376
410
|
|
@@ -383,7 +417,7 @@ ENDTEXT
|
|
383
417
|
terminal = Morpheus::Terminal.new()
|
384
418
|
end
|
385
419
|
|
386
|
-
return
|
420
|
+
return 0, nil
|
387
421
|
end
|
388
422
|
|
389
423
|
end
|