MuranoCLI 2.2.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.agignore +3 -0
  3. data/.gitignore +18 -1
  4. data/.rubocop.yml +222 -0
  5. data/.trustme.sh +185 -0
  6. data/.trustme.vim +24 -0
  7. data/Gemfile +23 -4
  8. data/LICENSE.txt +1 -1
  9. data/MuranoCLI.gemspec +43 -8
  10. data/README.markdown +9 -11
  11. data/Rakefile +187 -143
  12. data/TODO.taskpaper +2 -2
  13. data/bin/murano +51 -52
  14. data/docs/basic_example.rst +436 -0
  15. data/docs/completions/murano_completion-bash +3484 -0
  16. data/docs/demo.md +32 -32
  17. data/docs/develop.rst +391 -0
  18. data/lib/MrMurano.rb +21 -7
  19. data/lib/MrMurano/Account.rb +159 -174
  20. data/lib/MrMurano/Business.rb +381 -0
  21. data/lib/MrMurano/Config-Migrate.rb +32 -26
  22. data/lib/MrMurano/Config.rb +407 -128
  23. data/lib/MrMurano/Content.rb +191 -0
  24. data/lib/MrMurano/Gateway.rb +489 -0
  25. data/lib/MrMurano/Keystore.rb +48 -0
  26. data/lib/MrMurano/Passwords.rb +103 -0
  27. data/lib/MrMurano/ProjectFile.rb +121 -79
  28. data/lib/MrMurano/ReCommander.rb +114 -10
  29. data/lib/MrMurano/Setting.rb +90 -0
  30. data/lib/MrMurano/Solution-ServiceConfig.rb +89 -45
  31. data/lib/MrMurano/Solution-Services.rb +461 -166
  32. data/lib/MrMurano/Solution-Users.rb +70 -31
  33. data/lib/MrMurano/Solution.rb +372 -13
  34. data/lib/MrMurano/SolutionId.rb +73 -0
  35. data/lib/MrMurano/SyncRoot.rb +137 -0
  36. data/lib/MrMurano/SyncUpDown.rb +594 -284
  37. data/lib/MrMurano/Webservice-Cors.rb +71 -0
  38. data/lib/MrMurano/Webservice-Endpoint.rb +234 -0
  39. data/lib/MrMurano/Webservice-File.rb +193 -0
  40. data/lib/MrMurano/Webservice.rb +51 -0
  41. data/lib/MrMurano/commands.rb +18 -15
  42. data/lib/MrMurano/commands/business.rb +300 -6
  43. data/lib/MrMurano/commands/completion-bash.erb +166 -0
  44. data/lib/MrMurano/commands/{zshcomplete.erb → completion-zsh.erb} +0 -0
  45. data/lib/MrMurano/commands/completion.rb +76 -39
  46. data/lib/MrMurano/commands/config.rb +108 -44
  47. data/lib/MrMurano/commands/content.rb +115 -72
  48. data/lib/MrMurano/commands/cors.rb +29 -14
  49. data/lib/MrMurano/commands/devices.rb +286 -0
  50. data/lib/MrMurano/commands/domain.rb +52 -12
  51. data/lib/MrMurano/commands/gb.rb +24 -9
  52. data/lib/MrMurano/commands/globals.rb +64 -0
  53. data/lib/MrMurano/commands/init.rb +377 -155
  54. data/lib/MrMurano/commands/keystore.rb +92 -82
  55. data/lib/MrMurano/commands/link.rb +300 -0
  56. data/lib/MrMurano/commands/login.rb +74 -11
  57. data/lib/MrMurano/commands/logs.rb +63 -32
  58. data/lib/MrMurano/commands/mock.rb +57 -29
  59. data/lib/MrMurano/commands/password.rb +57 -39
  60. data/lib/MrMurano/commands/postgresql.rb +127 -94
  61. data/lib/MrMurano/commands/settings.rb +203 -0
  62. data/lib/MrMurano/commands/show.rb +79 -38
  63. data/lib/MrMurano/commands/solution.rb +423 -5
  64. data/lib/MrMurano/commands/solution_picker.rb +547 -0
  65. data/lib/MrMurano/commands/status.rb +195 -61
  66. data/lib/MrMurano/commands/sync.rb +78 -39
  67. data/lib/MrMurano/commands/timeseries.rb +71 -55
  68. data/lib/MrMurano/commands/tsdb.rb +113 -87
  69. data/lib/MrMurano/commands/usage.rb +57 -15
  70. data/lib/MrMurano/hash.rb +100 -10
  71. data/lib/MrMurano/http.rb +187 -43
  72. data/lib/MrMurano/makePretty.rb +16 -14
  73. data/lib/MrMurano/optparse.rb +2178 -0
  74. data/lib/MrMurano/progress.rb +138 -0
  75. data/lib/MrMurano/schema/resource-v1.0.0.yaml +32 -0
  76. data/lib/MrMurano/template/projectFile.murano.erb +16 -13
  77. data/lib/MrMurano/verbosing.rb +166 -29
  78. data/lib/MrMurano/version.rb +30 -1
  79. data/spec/Account-Passwords_spec.rb +21 -4
  80. data/spec/Account_spec.rb +69 -146
  81. data/spec/Business_spec.rb +290 -0
  82. data/spec/ConfigFile_spec.rb +1 -0
  83. data/spec/ConfigMigrate_spec.rb +12 -8
  84. data/spec/Config_spec.rb +40 -34
  85. data/spec/Content_spec.rb +363 -0
  86. data/spec/GatewayBase_spec.rb +54 -0
  87. data/spec/GatewayDevice_spec.rb +321 -0
  88. data/spec/GatewayResource_spec.rb +266 -0
  89. data/spec/GatewaySettings_spec.rb +120 -0
  90. data/spec/Http_spec.rb +18 -8
  91. data/spec/Mock_spec.rb +2 -2
  92. data/spec/ProjectFile_spec.rb +25 -14
  93. data/spec/Setting_spec.rb +110 -0
  94. data/spec/Solution-ServiceConfig_spec.rb +44 -5
  95. data/spec/Solution-ServiceEventHandler_spec.rb +23 -14
  96. data/spec/Solution-ServiceModules_spec.rb +47 -37
  97. data/spec/Solution-UsersRoles_spec.rb +10 -8
  98. data/spec/Solution_spec.rb +17 -8
  99. data/spec/SyncRoot_spec.rb +46 -20
  100. data/spec/SyncUpDown_spec.rb +437 -201
  101. data/spec/Verbosing_spec.rb +12 -4
  102. data/spec/{Solution-Cors_spec.rb → Webservice-Cors_spec.rb} +23 -20
  103. data/spec/{Solution-Endpoint_spec.rb → Webservice-Endpoint_spec.rb} +43 -41
  104. data/spec/{Solution-File_spec.rb → Webservice-File_spec.rb} +44 -33
  105. data/spec/Webservice-Setting_spec.rb +89 -0
  106. data/spec/_workspace.rb +4 -4
  107. data/spec/cmd_business_spec.rb +9 -4
  108. data/spec/cmd_common.rb +44 -1
  109. data/spec/cmd_content_spec.rb +43 -17
  110. data/spec/cmd_cors_spec.rb +4 -4
  111. data/spec/cmd_device_spec.rb +61 -16
  112. data/spec/cmd_domain_spec.rb +29 -6
  113. data/spec/cmd_init_spec.rb +281 -126
  114. data/spec/cmd_keystore_spec.rb +3 -3
  115. data/spec/cmd_link_spec.rb +98 -0
  116. data/spec/cmd_password_spec.rb +1 -1
  117. data/spec/cmd_setting_application_spec.rb +260 -0
  118. data/spec/cmd_setting_product_spec.rb +220 -0
  119. data/spec/cmd_status_spec.rb +223 -114
  120. data/spec/cmd_syncdown_spec.rb +115 -35
  121. data/spec/cmd_syncup_spec.rb +68 -15
  122. data/spec/cmd_usage_spec.rb +35 -8
  123. data/spec/fixtures/dumped_config +6 -4
  124. data/spec/fixtures/gateway_resource_files/resources.notyaml +12 -0
  125. data/spec/fixtures/gateway_resource_files/resources.yaml +13 -0
  126. data/spec/fixtures/gateway_resource_files/resources_invalid.yaml +13 -0
  127. data/spec/fixtures/mrmuranorc_deleted_bob +0 -2
  128. data/spec/fixtures/product_spec_files/lightbulb.yaml +20 -13
  129. data/spec/fixtures/{syncable_content → syncable_conflict}/services/devdata.lua +1 -1
  130. data/spec/fixtures/{syncable_content → syncable_conflict}/services/timers.lua +0 -0
  131. data/spec/spec_helper.rb +5 -0
  132. metadata +262 -171
  133. data/bin/mr +0 -8
  134. data/lib/MrMurano/Product-1P-Device.rb +0 -145
  135. data/lib/MrMurano/Product-Resources.rb +0 -205
  136. data/lib/MrMurano/Product.rb +0 -358
  137. data/lib/MrMurano/Solution-Cors.rb +0 -47
  138. data/lib/MrMurano/Solution-Endpoint.rb +0 -191
  139. data/lib/MrMurano/Solution-File.rb +0 -166
  140. data/lib/MrMurano/commands/assign.rb +0 -57
  141. data/lib/MrMurano/commands/businessList.rb +0 -45
  142. data/lib/MrMurano/commands/product.rb +0 -14
  143. data/lib/MrMurano/commands/productCreate.rb +0 -39
  144. data/lib/MrMurano/commands/productDelete.rb +0 -33
  145. data/lib/MrMurano/commands/productDevice.rb +0 -87
  146. data/lib/MrMurano/commands/productDeviceIdCmds.rb +0 -89
  147. data/lib/MrMurano/commands/productList.rb +0 -45
  148. data/lib/MrMurano/commands/productWrite.rb +0 -27
  149. data/lib/MrMurano/commands/solutionCreate.rb +0 -41
  150. data/lib/MrMurano/commands/solutionDelete.rb +0 -34
  151. data/lib/MrMurano/commands/solutionList.rb +0 -45
  152. data/spec/ProductBase_spec.rb +0 -113
  153. data/spec/ProductContent_spec.rb +0 -162
  154. data/spec/ProductResources_spec.rb +0 -329
  155. data/spec/Product_1P_Device_spec.rb +0 -202
  156. data/spec/Product_1P_RPC_spec.rb +0 -175
  157. data/spec/Product_spec.rb +0 -153
  158. data/spec/Solution-ServiceDevice_spec.rb +0 -176
  159. data/spec/cmd_assign_spec.rb +0 -51
@@ -1,20 +1,83 @@
1
+ # Last Modified: 2017.08.16 /coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright © 2016-2017 Exosite LLC.
5
+ # License: MIT. See LICENSE.txt.
6
+ # vim:tw=0:ts=2:sw=2:et:ai
7
+
1
8
  require 'MrMurano/Account'
9
+ require 'MrMurano/Config'
10
+ require 'MrMurano/ReCommander'
2
11
 
3
12
  command 'login' do |c|
4
- c.syntax = %{murano login}
5
- c.summary = %{Log into Murano}
6
- c.description = %{Log into Murano
13
+ c.syntax = %(murano login)
14
+ c.summary = %(Log into Murano)
15
+ c.description = %(
16
+ Log into Murano.
7
17
 
8
- If you are having trouble logging in, try deleting the saved password first.
9
- `murano password delete <username>`
10
- }
11
- c.option '--show-token', %{Shows the API token}
18
+ If you are having trouble logging in, try deleting the saved password first:
19
+
20
+ murano password delete <username>
21
+ ).strip
22
+ c.option '--show-token', %(Shows the API token)
23
+ c.project_not_required = true
24
+ c.prompt_if_logged_off = true
12
25
 
13
26
  c.action do |args, options|
14
- acc = MrMurano::Account.new
15
- ret = acc.token
16
- say ret if options.show_token
27
+ c.verify_arg_count!(args)
28
+ tok = MrMurano::Account.instance.token
29
+ say tok if options.show_token
30
+ end
31
+ end
32
+
33
+ command 'logout' do |c|
34
+ c.syntax = %(murano logout)
35
+ c.summary = %(Log out of Murano)
36
+ c.description = %(
37
+ Log out of Murano.
38
+
39
+ This command will unset the user.name in the user config, and
40
+ it will remove that user's password from the password file.
41
+
42
+ Essentially, this command is the same as:
43
+
44
+ murano password delete <username>
45
+ murano config --unset --user user.name
46
+ ).strip
47
+ c.project_not_required = true
48
+
49
+ c.action do |args, _options|
50
+ c.verify_arg_count!(args)
51
+
52
+ net_host = verify_set('net.host')
53
+ user_name = verify_set('user.name')
54
+ if net_host && user_name
55
+ psd = MrMurano::Passwords.new
56
+ psd.load
57
+ psd.remove(net_host, user_name)
58
+ psd.save
59
+ end
60
+
61
+ user_net_host = $cfg.get('net.host', :user)
62
+ user_net_host = $cfg.get('net.host', :defaults) if user_net_host.nil?
63
+ user_user_name = $cfg.get('user.name', :user)
64
+ if (user_net_host == net_host) && (user_user_name == user_name)
65
+ # Only clear user name from the user config if the net.host
66
+ # or user.name did not come from a different config, like the
67
+ # --project config.
68
+ $cfg.set('user.name', nil, :user)
69
+ $cfg.set('business.id', nil, :user)
70
+ $cfg.set('business.name', nil, :user)
71
+ end
72
+ end
73
+
74
+ def verify_set(cfg_key)
75
+ cfg_val = $cfg.get(cfg_key)
76
+ if cfg_val.to_s.empty?
77
+ cfg_val = nil
78
+ MrMurano::Verbose.warning("No config key ‘#{cfg_key}’: no password to delete")
79
+ end
80
+ cfg_val
17
81
  end
18
82
  end
19
83
 
20
- # vim: set ai et sw=2 ts=2 :
@@ -1,42 +1,69 @@
1
- require 'MrMurano/Solution'
1
+ # Last Modified: 2017.08.16 /coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright © 2016-2017 Exosite LLC.
5
+ # License: MIT. See LICENSE.txt.
6
+ # vim:tw=0:ts=2:sw=2:et:ai
7
+
2
8
  require 'MrMurano/makePretty'
9
+ require 'MrMurano/ReCommander'
10
+ require 'MrMurano/Solution'
3
11
 
4
12
  command :logs do |c|
5
- c.syntax = %{murano logs [options]}
6
- c.description = %{Get the logs for a solution}
7
- c.option '-f','--follow', %{Follow logs from server}
8
- c.option('--[no-]color', %{Toggle colorizing of logs}) {
9
- Rainbow.enabled = false
10
- }
11
- c.option '--[no-]pretty', %{Reformat JSON blobs in logs.}
12
- c.option '--[no-]localtime', %{Adjust Timestamps to be in local time}
13
- c.option '--raw', %{Don't do any formating of the log data}
13
+ c.syntax = %(murano logs [--options])
14
+ c.summary = %(Get the logs for a solution)
15
+ c.description = %(
16
+ Get the logs for a solution.
17
+ ).strip
18
+
19
+ # Add flag: --type [application|product].
20
+ cmd_add_solntype_pickers(c, exclude_all: true)
14
21
 
15
- c.action do |args,options|
16
- options.default :pretty=>true, :localtime=>true, :raw => false
22
+ c.option '-f', '--follow', %(Follow logs from server)
23
+ c.option '--[no-]pretty', %(Reformat JSON blobs in logs.)
24
+ c.option '--[no-]localtime', %(Adjust Timestamps to be in local time)
25
+ c.option '--raw', %(Don't do any formating of the log data)
26
+ # FIXME/2017-06-23: It'd be nice to allow :all
27
+ # But then we'd have to interleave output somehow with --follow,
28
+ # maybe using separate threads?
17
29
 
18
- sol = MrMurano::Solution.new
30
+ c.action do |args, options|
31
+ c.verify_arg_count!(args)
32
+ options.default(pretty: true, localtime: true, raw: false, type: :application)
33
+ cmd_defaults_solntype_pickers(options, :application)
19
34
 
20
- if options.follow then
21
- # open a lasting connection and continueally feed makePretty()
35
+ if options.type == :application
36
+ sol = MrMurano::Application.new
37
+ elsif options.type == :product
38
+ sol = MrMurano::Product.new
39
+ else
40
+ MrMurano::Verbose.error "Unknown --type specified: #{options.type}"
41
+ exit 1
42
+ end
43
+
44
+ if options.follow
45
+ # Open a lasting connection and continually feed makePretty().
22
46
  begin
23
47
  sol.get('/logs?polling=true') do |request, http|
24
- request["Accept-Encoding"] = "None"
48
+ request['Accept-Encoding'] = 'None'
25
49
  http.request(request) do |response|
26
- remainder=''
50
+ remainder = ''
27
51
  response.read_body do |chunk|
28
52
  chunk = remainder + chunk unless remainder.empty?
29
53
 
30
- # for all complete JSON blobs, make them pretty.
54
+ # For all complete JSON blobs, make them pretty.
31
55
  chunk.gsub!(/\{(?>[^}{]+|\g<0>)*\}/m) do |m|
32
- if options.raw then
56
+ if options.raw
33
57
  puts m
34
58
  else
35
59
  begin
36
- js = JSON.parse(m, {:allow_nan=>true,
37
- :symbolize_names => true,
38
- :create_additions=>false})
39
- puts MrMurano::Pretties::makePretty(js, options)
60
+ js = JSON.parse(
61
+ m,
62
+ allow_nan: true,
63
+ symbolize_names: true,
64
+ create_additions: false,
65
+ )
66
+ puts MrMurano::Pretties.makePretty(js, options)
40
67
  rescue
41
68
  sol.error '=== JSON parse error, showing raw instead ==='
42
69
  puts m
@@ -45,34 +72,38 @@ command :logs do |c|
45
72
  '' #remove (we're kinda abusing gsub here.)
46
73
  end
47
74
 
48
- # is there an incomplete one?
49
- if chunk.match(/(\{.*$)/m) then
50
- remainder = $1
75
+ # Is there an incomplete one?
76
+ chunk.match(/(\{.*$)/m) do |mat|
77
+ remainder = mat[1]
51
78
  end
52
-
53
79
  end
54
80
  end
55
81
  end
82
+ # rubocop:disable Lint/HandleExceptions: Do not suppress exceptions.
56
83
  rescue Interrupt => _
57
84
  end
58
85
 
59
86
  else
60
87
  ret = sol.get('/logs')
61
88
 
62
- if ret.kind_of?(Hash) and ret.has_key?(:items) then
89
+ if ret.is_a?(Hash) && ret.key?(:items)
63
90
  ret[:items].reverse.each do |line|
64
- if options.raw then
91
+ if options.raw
65
92
  puts line
66
93
  else
67
- puts MrMurano::Pretties::makePretty(line, options)
94
+ puts MrMurano::Pretties.makePretty(line, options)
68
95
  end
69
96
  end
70
97
  else
71
98
  sol.error "Couldn't get logs: #{ret}"
99
+ # 2017-06-23: Shouldn't this be exit? What're we breaking out of?
72
100
  break
73
101
  end
74
-
75
102
  end
76
103
  end
77
104
  end
78
- # vim: set ai et sw=2 ts=2 :
105
+ alias_command 'logs application', 'logs', '--type', 'application'
106
+ alias_command 'logs product', 'logs', '--type', 'product'
107
+ alias_command 'application logs', 'logs', '--type', 'application'
108
+ alias_command 'product logs', 'logs', '--type', 'product'
109
+
@@ -1,63 +1,91 @@
1
+ # Last Modified: 2017.08.16 /coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright © 2016-2017 Exosite LLC.
5
+ # License: MIT. See LICENSE.txt.
6
+ # vim:tw=0:ts=2:sw=2:et:ai
7
+
1
8
  require 'MrMurano/Mock'
9
+ require 'MrMurano/ReCommander'
2
10
 
3
11
  command 'mock' do |c|
4
- c.syntax = %{murano mock}
5
- c.summary = %{Enable or disable testpoint. Show current UUID.}
6
- c.description = %{mock lets you enable testpoints to do local lua development}
12
+ c.syntax = %(murano mock)
13
+ c.summary = %(Enable or disable testpoint, or show current UUID)
14
+ c.description = %(
15
+ The mock command lets you enable testpoints to do local Lua development.
16
+ ).strip
17
+ c.project_not_required = true
7
18
 
8
- c.action do |args, options|
19
+ c.action do |_args, _options|
9
20
  ::Commander::UI.enable_paging
10
21
  say MrMurano::SubCmdGroupHelp.new(c).get_help
11
22
  end
12
23
  end
13
24
 
14
25
  command 'mock enable' do |c|
15
- c.syntax = %{murano mock enable}
16
- c.summary = %{Create a testpoint file.}
17
- c.description = %{Run syncup after running this to carry the change through to Murano.
18
- Returns the UUID to be used for authenticating.
19
- }
20
- c.option '--raw', %{print raw uuid}
26
+ c.syntax = %(murano mock enable)
27
+ c.summary = %(Create a testpoint file)
28
+ c.description = %(
29
+ Create a testpoint file.
30
+
31
+ Run syncup after running this to carry the change through to Murano.
32
+
33
+ Returns the UUID to be used for authenticating.
34
+ ).strip
35
+ c.option '--raw', %(print raw uuid)
36
+
21
37
  c.action do |args, options|
38
+ c.verify_arg_count!(args)
22
39
  mock = MrMurano::Mock.new
23
- uuid = mock.create_testpoint()
24
- if options.raw then
40
+ uuid = mock.create_testpoint
41
+ if options.raw
25
42
  say uuid
26
43
  else
27
- say %{Created testpoint file. Run `murano syncup` to activate. The following is the authorization token:}
28
- say %{$ export AUTHORIZATION="#{uuid}"}
44
+ say %(Created testpoint file. Run `murano syncup` to activate. The following is the authorization token:)
45
+ say %($ export AUTHORIZATION="#{uuid}")
29
46
  end
30
47
  end
31
48
  end
32
49
 
33
50
  command 'mock disable' do |c|
34
- c.syntax = %{murano mock disable}
35
- c.summary = %{Remove the testpoint file.}
36
- c.description = %{Run syncup after running this to carry the change through to Murano.}
51
+ c.syntax = %(murano mock disable)
52
+ c.summary = %(Remove the testpoint file)
53
+ c.description = %(
54
+ Remove the testpoint file.
37
55
 
38
- c.action do |args, options|
56
+ Run syncup after running this to carry the change through to Murano.
57
+ ).strip
58
+
59
+ c.action do |args, _options|
60
+ c.verify_arg_count!(args)
39
61
  mock = MrMurano::Mock.new
40
- removed = mock.remove_testpoint()
41
- if removed then
42
- say %{Deleted testpoint file. Run `murano syncup` to remove the testpoint.}
62
+ removed = mock.remove_testpoint
63
+ if removed
64
+ say %(Deleted testpoint file. Run `murano syncup` to remove the testpoint.)
43
65
  else
44
- say %{No testpoint file to remove.}
66
+ say %(No testpoint file to remove.)
45
67
  end
46
68
  end
47
69
  end
48
70
 
49
71
  command 'mock show' do |c|
50
- c.syntax = %{murano mock disable}
51
- c.summary = %{Remove the testpoint file.}
52
- c.description = %{Run syncup after running this to carry the change through to Murano.}
72
+ c.syntax = %(murano mock disable)
73
+ c.summary = %(Remove the testpoint file)
74
+ c.description = %(
75
+ Remove the testpoint file.
53
76
 
54
- c.action do |args, options|
77
+ Run syncup after running this to carry the change through to Murano.
78
+ ).strip
79
+
80
+ c.action do |args, _options|
81
+ c.verify_arg_count!(args)
55
82
  mock = MrMurano::Mock.new
56
- uuid = mock.show()
57
- if uuid then
83
+ uuid = mock.show
84
+ if uuid
58
85
  say uuid
59
86
  else
60
- say %{Could not find testpoint file or UUID in testpoint file.}
87
+ say %(Could not find testpoint file or UUID in testpoint file.)
61
88
  end
62
89
  end
63
90
  end
91
+
@@ -1,91 +1,109 @@
1
+ # Last Modified: 2017.08.16 /coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright © 2016-2017 Exosite LLC.
5
+ # License: MIT. See LICENSE.txt.
6
+ # vim:tw=0:ts=2:sw=2:et:ai
7
+
8
+ require 'MrMurano/ReCommander'
1
9
 
2
10
  command :password do |c|
3
- c.syntax = %{murano password}
4
- c.summary = %{About password commands}
5
- c.description = %{Sub-commands for working with usernames and passwords}
6
- c.action do |args, options|
11
+ c.syntax = %(murano password)
12
+ c.summary = %(About password commands)
13
+ c.description = %(
14
+ Commands for working with usernames and passwords.
15
+ ).strip
16
+ c.project_not_required = true
17
+ c.action do |_args, _options|
7
18
  ::Commander::UI.enable_paging
8
19
  say MrMurano::SubCmdGroupHelp.new(c).get_help
9
20
  end
10
21
  end
11
-
12
22
  alias_command 'password current', :config, 'user.name'
13
23
 
14
24
  command 'password list' do |c|
15
- c.syntax = %{murano password list}
16
- c.summary = %{List the usernames with saved passwords}
17
- c.description = %{List the usernames and hosts that have been saved}
18
- c.action do |args, options|
25
+ c.syntax = %(murano password list)
26
+ c.summary = %(List the usernames with saved passwords)
27
+ c.description = %(
28
+ List the usernames and hosts that have been saved.
29
+ ).strip
30
+ c.project_not_required = true
31
+
32
+ c.action do |args, _options|
33
+ c.verify_arg_count!(args)
34
+
19
35
  psd = MrMurano::Passwords.new
20
36
  psd.load
21
37
 
22
38
  ret = psd.list
23
39
  psd.outf(ret) do |dd, ios|
24
- rows=[]
40
+ rows = []
25
41
  dd.each_pair do |key, value|
26
- value.each{|v| rows << [key, v] }
42
+ value.each { |v| rows << [key, v] }
27
43
  end
28
- psd.tabularize({
29
- :rows=>rows, :headers => [:Host, :Username]
30
- }, ios)
44
+ psd.tabularize(
45
+ { rows: rows, headers: %i[Host Username] },
46
+ ios
47
+ )
31
48
  end
32
49
  end
33
50
  end
51
+ alias_command 'passwords list', 'password list'
34
52
 
35
53
  command 'password set' do |c|
36
- c.syntax = %{murano password set <username> [<host>]}
37
- c.summary = %{Set password for username}
38
-
39
- c.option '--password PASSWORD', String, %{The password to use}
40
- c.option '--from_env', %{Use password in MURANO_PASSWORD}
54
+ c.syntax = %(murano password set <username> [<host>])
55
+ c.summary = %(Set password for username)
56
+ c.description = %(
57
+ Set password for username.
58
+ ).strip
59
+ c.option '--password PASSWORD', String, %(The password to use)
60
+ c.option '--from_env', %(Use password in MURANO_PASSWORD)
61
+ c.project_not_required = true
41
62
 
42
63
  c.action do |args, options|
43
- psd = MrMurano::Passwords.new
44
- psd.load
45
-
46
- if args.count < 1 then
47
- psd.error "Missing username"
48
- exit 1
49
- end
64
+ c.verify_arg_count!(args, 2, ['Missing username'])
50
65
 
51
66
  username = args.shift
52
67
  host = args.shift
53
68
  host = $cfg['net.host'] if host.nil?
54
69
 
55
- if options.password then
70
+ psd = MrMurano::Passwords.new
71
+ psd.load
72
+ if options.password
56
73
  pws = options.password
57
- elsif options.from_env then
74
+ elsif options.from_env
58
75
  pws = ENV['MURANO_PASSWORD']
59
76
  else
60
- pws = ask("Password: ") { |q| q.echo = "*" }
77
+ pws = ask('Password: ') { |q| q.echo = '*' }
61
78
  end
62
-
63
79
  psd.set(host, username, pws)
64
80
  psd.save
65
-
66
81
  end
67
82
  end
68
83
 
69
84
  command 'password delete' do |c|
70
- c.syntax = %{murano password delete <username> [<host>]}
71
- c.summary = %{Delete password for username}
85
+ c.syntax = %(murano password delete <username> [<host>])
86
+ c.summary = %(Delete password for username)
87
+ c.description = %(
88
+ Delete password for username.
89
+ ).strip
90
+ c.project_not_required = true
91
+
92
+ c.option('-y', '--[no-]yes', %(Answer "yes" to all prompts and run non-interactively))
72
93
 
73
94
  c.action do |args, options|
95
+ c.verify_arg_count!(args, 2, ['Missing username'])
96
+
74
97
  psd = MrMurano::Passwords.new
75
98
  psd.load
76
99
 
77
- if args.count < 1 then
78
- psd.error "Missing username"
79
- exit 1
80
- end
81
-
82
100
  username = args.shift
83
101
  host = args.shift
84
102
  host = $cfg['net.host'] if host.nil?
85
103
 
104
+ psd.cmd_confirm_delete!(username, options.yes, 'abort!')
86
105
  psd.remove(host, username)
87
106
  psd.save
88
107
  end
89
108
  end
90
109
 
91
- # vim: set ai et sw=2 ts=2 :