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,102 +1,236 @@
1
+ # Last Modified: 2017.08.18 /coding: utf-8
2
+ # frozen_string_literal: true
1
3
 
2
- command :status do |c|
3
- c.syntax = %{murano status [options] [filters]}
4
- c.summary = %{Get the status of files}
5
- c.description = %{Get the status of files
4
+ # Copyright © 2016-2017 Exosite LLC.
5
+ # License: MIT. See LICENSE.txt.
6
+ # vim:tw=0:ts=2:sw=2:et:ai
6
7
 
7
- Compares the local project against what is up in Murano, returning a summary of
8
- what things are new or changed.
8
+ require 'inflecto'
9
+ require 'MrMurano/verbosing'
10
+ require 'MrMurano/SyncRoot'
9
11
 
10
- When --diff is passed, for items that have changes, the remote item and local
11
- item are passed to a diff tool and that output is included.
12
+ # Load options to control which things to sync
13
+ def cmd_option_syncable_pickers(cmd)
14
+ MrMurano::SyncRoot.instance.each_option do |short, long, desc|
15
+ cmd.option short, long, Inflecto.pluralize(desc)
16
+ end
17
+ MrMurano::SyncRoot.instance.each_alias_opt do |long, desc|
18
+ cmd.option long, Inflecto.pluralize(desc)
19
+ end
12
20
 
13
- The diff tool and options to it can be set with the config key 'diff.cmd'.
21
+ cmd.option(
22
+ '--[no-]nesting',
23
+ %(Disable support for arranging Lua modules hierarchically)
24
+ ) do |nestation|
25
+ # This is only called if user specifies switch.
26
+ $cfg['modules.no-nesting'] = !nestation
27
+ end
28
+ end
14
29
 
30
+ def cmd_defaults_syncable_pickers(options)
31
+ # Weird. The options is a Commander::Command::Options object, but
32
+ # options.class says nil! Also, you cannot index properties or
33
+ # even options.send('opt'). But we can just twiddle the raw table.
34
+ table = options.__hash__
35
+ MrMurano::SyncRoot.instance.each_alias_sym do |pseudo, pseudo_sym, name, name_sym|
36
+ unless table[pseudo_sym].nil?
37
+ if table[name_sym].nil?
38
+ table[name_sym] = table[pseudo_sym]
39
+ elsif table[name_sym] != table[pseudo_sym]
40
+ MrMurano::Verbose.warning("Ignoring --#{pseudo} because --#{name} also specified")
41
+ end
42
+ end
43
+ end
44
+ end
15
45
 
16
- Filters allow for selecting a subset of items to check based on patterns.
46
+ command :status do |c|
47
+ c.syntax = %(murano status [--options] [filters])
48
+ c.summary = %(Get the status of files)
49
+ c.description = %(
50
+ Get the status of files.
17
51
 
18
- File glob filters can be used to select local files. The glob is compared with
19
- the full file path.
52
+ Compares the local project against what is up in Murano, showing a summary
53
+ of what things are new or changed.
20
54
 
21
- Each item type also supports specific filters. These always start with #.
22
- Endpoints can be selected with a "#<method>#<path glob>" pattern.
55
+ When --diff is passed, for items that have changes, the remote item and
56
+ local item are passed to a diff tool and that output is included.
23
57
 
58
+ The diff tool and options to it can be set with the config key 'diff.cmd'.
24
59
 
25
- }.gsub(/^ +/,'')
26
- c.option '--all', 'Check everything'
60
+ Filters allow for selecting a subset of items to check based on patterns.
27
61
 
28
- # Load options to control which things to status
29
- MrMurano::SyncRoot.each_option do |s,l,d|
30
- c.option s, l, d
31
- end
62
+ File glob filters can be used to select local files. The glob is compared
63
+ with the full file path.
32
64
 
33
- c.option '--[no-]asdown', %{Report as if syncdown instead of syncup}
34
- c.option '--[no-]diff', %{For modified items, show a diff}
35
- c.option '--[no-]grouped', %{Group all adds, deletes, and mods together}
36
- c.option '--[no-]showall', %{List unchanged as well}
65
+ Each item type also supports specific filters. These always start with #.
66
+ Endpoints can be selected with a "#<method>#<path glob>" pattern.
67
+ ).gsub(/^ +/, '').strip
37
68
 
38
- c.action do |args,options|
39
- options.default :delete=>true, :create=>true, :update=>true, :diff=>false,
40
- :grouped => true
69
+ # Add flag: --type [application|product|all].
70
+ cmd_add_solntype_pickers(c)
41
71
 
42
- def fmtr(item)
43
- if item.has_key? :local_path then
44
- lp = item[:local_path].relative_path_from(Pathname.pwd()).to_s
45
- if item.has_key?(:line) and item[:line] > 0 then
46
- return "#{lp}:#{item[:line]}"
47
- end
48
- lp
72
+ c.option '--all', 'Check everything'
73
+ c.option '--[no-]asdown', %(Report as if syncdown instead of syncup)
74
+ c.option '--[no-]asup', %(Report as if syncup instead of syncdown (default: true))
75
+ c.option '--[no-]diff', %(For modified items, show a diff)
76
+ c.option '--[no-]grouped', %(Group all adds, deletes, and mods together)
77
+ c.option '--[no-]show-all', %(List unchanged as well)
78
+ c.option '--[no-]show-type', %(Include type of item)
79
+ cmd_option_syncable_pickers(c)
80
+
81
+ c.action do |args, options|
82
+ # SKIP: c.verify_arg_count!(args)
83
+ options.default(
84
+ all: nil,
85
+ asdown: nil,
86
+ asup: nil,
87
+ diff: false,
88
+ grouped: true,
89
+ show_all: false,
90
+ show_type: false,
91
+ # delete/create/update are not options the user can specify
92
+ # for status or diff commands; but the SyncUpDown class expects
93
+ # them.
94
+ delete: true,
95
+ create: true,
96
+ update: true,
97
+ )
98
+ cmd_defaults_solntype_pickers(options)
99
+ cmd_defaults_syncable_pickers(options)
100
+
101
+ def fmtr(item, options)
102
+ if item.key?(:local_path)
103
+ desc = item[:local_path].relative_path_from(Pathname.pwd).to_s
104
+ desc = "#{desc}:#{item[:line]}" if item.key?(:line) && item[:line] > 0
49
105
  else
50
- item[:synckey]
106
+ desc = item[:synckey]
107
+ end
108
+ return desc unless options.show_type
109
+ unless item[:pp_desc].to_s.empty? || item[:pp_desc] == item[:synckey]
110
+ desc += " (#{item[:pp_desc]})"
51
111
  end
112
+ desc += " [#{item[:method]} #{item[:path]}]" if item[:method] && item[:path]
113
+ desc
52
114
  end
115
+
116
+ def interject(msg)
117
+ MrMurano::Verbose.whirly_interject { say msg }
118
+ end
119
+
53
120
  def pretty(ret, options)
54
- say "Adding:" if options.grouped
55
- ret[:toadd].each{|item| say " + #{item[:pp_type]} #{fmtr(item)}"}
56
- say "Deleteing:" if options.grouped
57
- ret[:todel].each{|item| say " - #{item[:pp_type]} #{fmtr(item)}"}
58
- say "Changing:" if options.grouped
59
- ret[:tomod].each{|item|
60
- say " M #{item[:pp_type]} #{fmtr(item)}"
61
- say item[:diff] if options.diff
62
- }
63
- if options.showall then
64
- say "Unchanged:" if options.grouped
65
- ret[:unchg].each{|item| say " #{item[:pp_type]} #{fmtr(item)}"}
121
+ pretty_group_header(
122
+ ret[:toadd], 'Only on local machine', 'new locally', options.grouped
123
+ )
124
+ ret[:toadd].each do |item|
125
+ interject " + #{item[:pp_type]} #{highlight_chg(fmtr(item, options))}"
126
+ end
127
+
128
+ pretty_group_header(
129
+ ret[:todel], 'Only on remote server', 'new remotely', options.grouped
130
+ )
131
+ ret[:todel].each do |item|
132
+ interject " - #{item[:pp_type]} #{highlight_del(fmtr(item, options))}"
133
+ end
134
+
135
+ pretty_group_header(
136
+ ret[:tomod], 'Items that differ', 'that differs', options.grouped
137
+ )
138
+ ret[:tomod].each do |item|
139
+ interject " M #{item[:pp_type]} #{highlight_chg(fmtr(item, options))}"
140
+ interject item[:diff] if options.diff
141
+ end
142
+
143
+ unless ret[:skipd].empty?
144
+ pretty_group_header(
145
+ ret[:skipd], 'Items without a solution', 'without a solution', options.grouped
146
+ )
147
+ ret[:skipd].each do |item|
148
+ interject " - #{item[:pp_type]} #{highlight_del(fmtr(item, options))}"
149
+ end
150
+ end
151
+
152
+ return unless options.show_all
153
+ interject 'Unchanged:' if options.grouped
154
+ ret[:unchg].each { |item| interject " #{item[:pp_type]} #{fmtr(item, options)}" }
155
+ end
156
+
157
+ def pretty_group_header(group, header_any, header_empty, grouped)
158
+ return unless grouped
159
+ if !group.empty?
160
+ interject "#{header_any}:"
161
+ else
162
+ interject "Nothing #{header_empty}"
66
163
  end
67
164
  end
68
165
 
69
- @grouped = {:toadd=>[],:todel=>[],:tomod=>[], :unchg=>[]}
70
- def gmerge(ret, type, options)
71
- if options.grouped then
166
+ def highlight_chg(msg)
167
+ Rainbow(msg).green.bright
168
+ end
169
+
170
+ def highlight_del(msg)
171
+ Rainbow(msg).red.bright
172
+ end
173
+
174
+ @grouped = { toadd: [], todel: [], tomod: [], unchg: [], skipd: [] }
175
+ def gmerge(ret, type, desc, options)
176
+ if options.grouped
72
177
  out = @grouped
73
178
  else
74
- out = {:toadd=>[],:todel=>[],:tomod=>[], :unchg=>[]}
179
+ out = { toadd: [], todel: [], tomod: [], unchg: [], skipd: [] }
75
180
  end
76
181
 
77
- [:toadd, :todel, :tomod, :unchg].each do |kind|
182
+ %i[toadd todel tomod unchg skipd].each do |kind|
78
183
  ret[kind].each do |item|
79
184
  item = item.to_h
80
185
  item[:pp_type] = type
186
+ item[:pp_desc] = desc
81
187
  out[kind] << item
82
188
  end
83
189
  end
84
190
 
85
- unless options.grouped then
86
- pretty(out, options)
191
+ pretty(out, options) unless options.grouped
192
+ end
193
+
194
+ # *** Method code starts here ***
195
+
196
+ # Check that user doesn't try to asdown and asup, or no-asdown and no-asup.
197
+ if options.asdown.nil? && options.asup.nil?
198
+ options.asdown = false
199
+ options.asup = true
200
+ elsif !options.asdown.nil? && !options.asup.nil?
201
+ unless options.asdown ^ options.asup
202
+ error('Please specify either --asdown or --asup, but not both!')
203
+ exit 1
87
204
  end
205
+ elsif options.asdown.nil?
206
+ options.asdown = !options.asup
207
+ elsif options.asup.nil?
208
+ options.asup = !options.asdown
209
+ else
210
+ raise('Unexpected code path.')
88
211
  end
89
212
 
90
- MrMurano::SyncRoot.each_filtered(options.__hash__) do |name, type, klass|
91
- sol = klass.new
92
- ret = sol.status(options, args)
93
- gmerge(ret, type, options)
213
+ MrMurano::SyncRoot.instance.each_filtered(options.__hash__) do |_name, type, klass, desc|
214
+ MrMurano::Verbose.whirly_msg "Fetching #{Inflecto.pluralize(desc)}..."
215
+ begin
216
+ syncable = klass.new
217
+ rescue MrMurano::ConfigError => err
218
+ MrMurano::Verbose.error "Could not fetch status for #{desc}: #{err}"
219
+ rescue StandardError => _err
220
+ raise
221
+ else
222
+ ret = syncable.status(options, args)
223
+ gmerge(ret, type, desc, options)
224
+ end
94
225
  end
226
+ MrMurano::Verbose.whirly_stop
95
227
 
96
228
  pretty(@grouped, options) if options.grouped
97
229
  end
98
230
  end
231
+ alias_command 'diff', 'status', '--diff', '--no-grouped'
232
+ alias_command 'diff application', 'status', '--diff', '--no-grouped', '--type', 'application'
233
+ alias_command 'diff product', 'status', '--diff', '--no-grouped', '--type', 'product'
234
+ alias_command 'application diff', 'status', '--diff', '--no-grouped', '--type', 'application'
235
+ alias_command 'product diff', 'status', '--diff', '--no-grouped', '--type', 'product'
99
236
 
100
- alias_command :diff, :status, '--diff', '--no-grouped'
101
-
102
- # vim: set ai et sw=2 ts=2 :
@@ -1,60 +1,99 @@
1
+ # Last Modified: 2017.08.16 /coding: utf-8
2
+ # frozen_string_literal: true
1
3
 
2
- command :syncdown do |c|
3
- c.syntax = %{murano syncdown [options] [filters]}
4
- c.description = %{Sync project down from Murano}
5
- c.option '--all', 'Sync everything'
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/verbosing'
9
+ require 'MrMurano/SyncRoot'
10
+ require 'MrMurano/commands/status'
11
+
12
+ def sync_add_options(c, locale)
13
+ c.option '--[no-]delete', %(Don't delete things from #{locale})
14
+ c.option '--[no-]create', %(Don't create things on #{locale})
15
+ c.option '--[no-]update', %(Don't update things on #{locale})
16
+ end
6
17
 
7
- # Load options to control which things to sync
8
- MrMurano::SyncRoot.each_option do |s,l,d|
9
- c.option s, l, d
18
+ def syncdown_files(options, args=nil)
19
+ args = [] if args.nil?
20
+ num_synced = 0
21
+ MrMurano::SyncRoot.instance.each_filtered(options) do |_name, _type, klass, desc|
22
+ MrMurano::Verbose.whirly_msg "Syncing #{Inflecto.pluralize(desc)}..."
23
+ sol = klass.new
24
+ num_synced += sol.syncdown(options, args)
10
25
  end
26
+ MrMurano::Verbose.whirly_stop
27
+ num_synced
28
+ end
11
29
 
12
- c.option '--[no-]delete', %{Don't delete things from server}
13
- c.option '--[no-]create', %{Don't create things on server}
14
- c.option '--[no-]update', %{Don't update things on server}
30
+ command :syncdown do |c|
31
+ c.syntax = %(murano syncdown [--options] [filters])
32
+ c.summary = %(Sync project down from Murano)
33
+ c.description = %(
34
+ Sync project down from Murano.
35
+ ).strip
15
36
 
16
- c.example %{Make local be like what is on the server}, %{murano syncdown --all}
17
- c.example %{Pull down new things, but don't delete or modify anything}, %{murano syncdown --all --no-delete --no-update}
18
- c.example %{Only Pull new static files}, %{murano syncdown --files --no-delete --no-update}
37
+ # Add flag: --type [application|product|all].
38
+ cmd_add_solntype_pickers(c)
19
39
 
20
- c.action do |args,options|
21
- options.default :delete=>true, :create=>true, :update=>true
40
+ c.option '--all', 'Sync everything'
41
+ cmd_option_syncable_pickers(c)
42
+ sync_add_options(c, 'local machine')
22
43
 
23
- MrMurano::SyncRoot.each_filtered(options.__hash__) do |name, type, klass|
24
- sol = klass.new
25
- sol.syncdown(options, args)
26
- end
44
+ c.example %(Make local be like what is on the server), %(murano syncdown --all)
45
+ c.example %(Pull down new things, but don't delete or modify anything), %(murano syncdown --all --no-delete --no-update)
46
+ c.example %(Only Pull new static files), %(murano syncdown --files --no-delete --no-update)
47
+
48
+ c.action do |args, options|
49
+ # SKIP: c.verify_arg_count!(args)
50
+ options.default(delete: true, create: true, update: true)
51
+ cmd_defaults_solntype_pickers(options)
52
+ cmd_defaults_syncable_pickers(options)
53
+ syncdown_files(options.__hash__, args)
27
54
  end
28
55
  end
29
- alias_command :pull, :syncdown, '--no-delete'
56
+ alias_command 'pull', 'syncdown', '--no-delete'
57
+ alias_command 'pull application', 'syncdown', '--no-delete', '--type', 'application'
58
+ alias_command 'pull product', 'syncdown', '--no-delete', '--type', 'product'
59
+ alias_command 'application pull', 'syncdown', '--no-delete', '--type', 'application'
60
+ alias_command 'product pull', 'syncdown', '--no-delete', '--type', 'product'
30
61
 
31
62
  command :syncup do |c|
32
- c.syntax = %{murano syncup [options] [filters]}
33
- c.description = %{Sync project up into Murano}
34
- c.option '--all', 'Sync everything'
63
+ c.syntax = %(murano syncup [--options] [filters])
64
+ c.summary = %(Sync project up into Murano)
65
+ c.description = %(
66
+ Sync project up into Murano.
67
+ ).strip
35
68
 
36
- # Load options to control which things to sync
37
- MrMurano::SyncRoot.each_option do |s,l,d|
38
- c.option s, l, d
39
- end
40
-
41
- c.option '--[no-]delete', %{Don't delete things from server}
42
- c.option '--[no-]create', %{Don't create things on server}
43
- c.option '--[no-]update', %{Don't update things on server}
69
+ # Add flag: --type [application|product|all].
70
+ cmd_add_solntype_pickers(c)
44
71
 
45
- c.example %{Deploy project to server}, %{murano syncup --all}
46
- c.example %{Update static files}, %{murano syncup --files}
47
- c.example %{Only add or modify static files}, %{murano syncup --files --no-delete}
72
+ c.option '--all', 'Sync everything'
73
+ cmd_option_syncable_pickers(c)
74
+ sync_add_options(c, 'server')
48
75
 
49
- c.action do |args,options|
50
- options.default :delete=>true, :create=>true, :update=>true
76
+ c.example %(Deploy project to server), %(murano syncup --all)
77
+ c.example %(Update static files), %(murano syncup --files)
78
+ c.example %(Only add or modify static files), %(murano syncup --files --no-delete)
51
79
 
52
- MrMurano::SyncRoot.each_filtered(options.__hash__) do |name, type, klass|
80
+ c.action do |args, options|
81
+ # SKIP: c.verify_arg_count!(args)
82
+ options.default(delete: true, create: true, update: true)
83
+ cmd_defaults_solntype_pickers(options)
84
+ cmd_defaults_syncable_pickers(options)
85
+ #MrMurano::Verbose.whirly_start "Syncing solutions..."
86
+ MrMurano::SyncRoot.instance.each_filtered(options.__hash__) do |_name, _type, klass, desc|
87
+ MrMurano::Verbose.whirly_msg "Syncing #{Inflecto.pluralize(desc)}..."
53
88
  sol = klass.new
54
89
  sol.syncup(options, args)
55
90
  end
91
+ MrMurano::Verbose.whirly_stop
56
92
  end
57
93
  end
58
- alias_command :push, :syncup, '--no-delete'
94
+ alias_command 'push', 'syncup', '--no-delete'
95
+ alias_command 'push application', 'syncup', '--no-delete', '--type', 'application'
96
+ alias_command 'push product', 'syncup', '--no-delete', '--type', 'product'
97
+ alias_command 'application push', 'syncup', '--no-delete', '--type', 'application'
98
+ alias_command 'product push', 'syncup', '--no-delete', '--type', 'product'
59
99
 
60
- # vim: set ai et sw=2 ts=2 :
@@ -1,109 +1,127 @@
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 'csv'
9
+ require 'MrMurano/ReCommander'
2
10
  require 'MrMurano/Solution-ServiceConfig'
3
11
 
4
12
  module MrMurano
5
13
  class Timeseries < ServiceConfig
6
- def initialize
14
+ def initialize(sid=nil)
15
+ # FIXME/2017-07-03: What soln types have timeseries?
16
+ @solntype = 'application.id'
7
17
  super
8
- @serviceName = 'timeseries'
18
+ @service_name = 'timeseries'
9
19
  end
10
20
 
11
21
  def query(query)
12
- call(:query, :post, {:q=>query})
22
+ call(:query, :post, q: query)
13
23
  end
14
24
 
15
25
  def write(writestr)
16
- call(:write, :post, { :query=>writestr })
26
+ call(:write, :post, query: writestr)
17
27
  end
18
28
 
19
29
  def command(cmd)
20
- call(:command, :post, { :q=>cmd})
30
+ call(:command, :post, q: cmd)
21
31
  end
22
-
23
32
  end
24
33
  end
25
34
 
26
35
  command :timeseries do |c|
27
- c.syntax = %{murano timeseries}
28
- c.summary = %{About Timeseries}
29
- c.description = %{These commands are deprecated.
36
+ c.syntax = %(murano timeseries)
37
+ c.summary = %(About Timeseries)
38
+ c.description = %(
39
+ These commands are deprecated.
30
40
 
31
41
  The timeseries sub-commands let you interact directly with the Timeseries
32
- instance in a solution. This allows for easier debugging, being able to
33
- quickly try out different queries or write test data.}
42
+ instance in a solution. This allows for easier debugging, being able to
43
+ quickly try out different queries or write test data.
44
+ ).strip
34
45
 
35
- c.action do |args, options|
46
+ c.action do |_args, _options|
36
47
  ::Commander::UI.enable_paging
37
48
  say MrMurano::SubCmdGroupHelp.new(c).get_help
38
49
  end
39
50
  end
40
51
 
41
52
  command 'timeseries query' do |c|
42
- c.syntax = %{murano timeseries query <query string>}
43
- c.summary = %{Query the timeseries database}
44
- c.description = %{This command is deprecated.
53
+ c.syntax = %(murano timeseries query <query string>)
54
+ c.summary = %(Query the timeseries database)
55
+ c.description = %(
56
+ This command is deprecated.
45
57
 
46
- Query the timeseries database}
47
- c.option '-o', '--output FILE', %{Download to file instead of STDOUT}
48
- c.option '--[no-]json', %{Display results as raw json}
49
- c.option '--[no-]csv', %{Display results as CSV}
58
+ Query the timeseries database.
59
+ ).strip
60
+ c.option '-o', '--output FILE', %(Download to file instead of STDOUT)
61
+ c.option '--[no-]json', %(Display results as raw json)
62
+ c.option '--[no-]csv', %(Display results as CSV)
50
63
 
51
- c.action do |args,options|
52
- options.defalts :json=>false, :csv=>false
64
+ c.action do |args, options|
65
+ # SKIP: c.verify_arg_count!(args)
66
+ options.defalts json: false, csv: false
53
67
  sol = MrMurano::Timeseries.new
54
68
  ret = sol.query args.join(' ')
55
69
 
56
70
  $cfg['tool.outformat'] = 'json' if options.json
57
71
  $cfg['tool.outformat'] = 'best csv' if options.csv
58
72
 
59
- io=nil
60
- if options.output then
61
- io = File.open(options.output, 'w')
62
- end
63
-
64
- sol.outf(ret, io) do |dd, ios|
65
- (ret[:results] or []).each do |res|
66
- (res[:series] or []).each do |ser|
67
- sol.tabularize({
68
- :title=>ser[:name],
69
- :headers=>ser[:columns],
70
- :rows=>ser[:values]
71
- }, ios)
73
+ io = File.open(options.output, 'w') if options.output
74
+ sol.outf(ret, io) do |_dd, ios|
75
+ (ret[:results] || []).each do |res|
76
+ (res[:series] || []).each do |ser|
77
+ sol.tabularize(
78
+ {
79
+ title: ser[:name],
80
+ headers: ser[:columns],
81
+ rows: ser[:values],
82
+ },
83
+ ios
84
+ )
72
85
  end
73
86
  end
74
87
  end
75
88
  io.close unless io.nil?
76
-
77
89
  end
78
90
  end
79
- alias_command :tsq, 'timeseries query'
91
+ alias_command 'tsq', 'timeseries query'
80
92
 
81
93
  command 'timeseries write' do |c|
82
- c.syntax = %{murano timeseries <write string>}
83
- c.summary = %{Write data into the timeseries database}
84
- c.description = %{This command is deprecated.
85
-
86
- Write data into the timeseries database}
87
- c.option '--[no-]json', %{Display results as raw json}
88
- c.action do |args,options|
89
- options.defalts :json=>false
94
+ c.syntax = %(murano timeseries <write string>)
95
+ c.summary = %(Write data into the timeseries database)
96
+ c.description = %(
97
+ This command is deprecated.
98
+
99
+ Write data into the timeseries database.
100
+ ).strip
101
+ c.option '--[no-]json', %(Display results as raw json)
102
+ c.action do |args, options|
103
+ c.verify_arg_count!(args)
104
+ options.defalts(json: false)
90
105
  $cfg['tool.outformat'] = 'json' if options.json
91
106
  sol = MrMurano::Timeseries.new
92
107
  ret = sol.write args.join(' ')
93
108
  sol.outf ret
94
109
  end
95
110
  end
96
- alias_command :tsw, 'timeseries write'
111
+ alias_command 'tsw', 'timeseries write'
97
112
 
98
113
  command 'timeseries command' do |c|
99
- c.syntax = %{murano timeseries command <db command>}
100
- c.summary = %{Execute a non-query command in the database}
101
- c.description = %{This command is deprecated.
102
-
103
- Execute a non-query command in the database}
104
- c.option '--[no-]json', %{Display results as raw json}
105
- c.action do |args,options|
106
- options.defalts :json=>false
114
+ c.syntax = %(murano timeseries command <db command>)
115
+ c.summary = %(Execute a non-query command in the database)
116
+ c.description = %(
117
+ This command is deprecated.
118
+
119
+ Execute a non-query command in the database.
120
+ ).strip
121
+ c.option '--[no-]json', %(Display results as raw json)
122
+ c.action do |args, options|
123
+ # SKIP: c.verify_arg_count!(args)
124
+ options.defalts(json: false)
107
125
  $cfg['tool.outformat'] = 'json' if options.json
108
126
  sol = MrMurano::Timeseries.new
109
127
  ret = sol.command args.join(' ')
@@ -111,5 +129,3 @@ Execute a non-query command in the database}
111
129
  end
112
130
  end
113
131
 
114
-
115
- # vim: set ai et sw=2 ts=2 :