Class: StatusCmd
- Inherits:
-
Object
- Object
- StatusCmd
- Includes:
- MrMurano::Verbose
- Defined in:
- lib/MrMurano/commands/status.rb
Constant Summary collapse
- STATUS_CMD_DESCRIPTION =
%( The status command tells you the status of files ================================================ Compares the local project against what is up in Murano, showing a summary of what things are new or changed. With the --diff option, if an item has changes, the remote item and local item are passed to a diff tool and that output is displayed. - The diff tool and options to it can be set with the config key 'diff.cmd'. Filters allow for selecting a subset of items to check based on patterns. - File glob filters can be used to select local files. The glob is compared with the full file path. Each item type also supports specific filters. These always start with #. - E.g, Endpoints can be selected with a "#<method>#<path glob>" pattern. ).strip
Constants included from MrMurano::Verbose
MrMurano::Verbose::TABULARIZE_DATA_FORMAT_ERROR
Instance Method Summary collapse
- #command_status(cmd) ⇒ Object
- #gmerge(ret, type, desc, options) ⇒ Object
- #highlight_chg(msg) ⇒ Object
- #highlight_del(msg) ⇒ Object
- #interject(msg) ⇒ Object
- #pretty(ret, options) ⇒ Object
- #pretty_diff(item, options) ⇒ Object
- #pretty_group_header(group, header_any, header_empty, grouped) ⇒ Object
Methods included from MrMurano::Verbose
ask_yes_no, #ask_yes_no, #assert, assert, cmd_confirm_delete!, #cmd_confirm_delete!, debug, #debug, dump_file_json, dump_file_plain, dump_file_yaml, #dump_output_file, #error, error, #error_file_format!, fancy_ticks, #fancy_ticks, #load_file_json, #load_file_plain, #load_file_yaml, #load_input_file, outf, #outf, #outformat_engine, #pluralize?, pluralize?, #prepare_hash_csv, #read_hashf!, #tabularize, tabularize, verbose, #verbose, warning, #warning, #whirly_interject, whirly_interject, #whirly_linger, whirly_linger, #whirly_msg, whirly_msg, #whirly_pause, whirly_pause, #whirly_start, whirly_start, #whirly_stop, whirly_stop, #whirly_unpause, whirly_unpause
Instance Method Details
#command_status(cmd) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/MrMurano/commands/status.rb', line 73 def command_status(cmd) cmd.syntax = %(murano status [--options] [filters]) cmd.summary = %(Get the status of files) cmd.description = STATUS_CMD_DESCRIPTION cmd.must_not_be_managed = true # Add flag: --type [application|product|all]. cmd_add_solntype_pickers(cmd) cmd.option '--all', 'Check everything' cmd.option '--[no-]asdown', %(Report as if syncdown instead of syncup) cmd.option '--[no-]asup', %(Report as if syncup instead of syncdown (default: true)) cmd.option '--[no-]diff', %(For modified items, show a diff) cmd.option '--[no-]grouped', %(Group all adds, deletes, and mods together) cmd.option '--[no-]show-all', %(List unchanged as well) cmd.option '--[no-]show-type', %(Include type of item) cmd_option_syncable_pickers(cmd) cmd.example %(Show item statuses for dirty items: # # - Items that exist locally by not on the remote; # - Items that exist remotely by not on the local; # - Items that have differences between the local and remote sources ), %(murano status) cmd.example %(Show differences between local Services (event handlers) # and those configured on the platform ), %(murano diff -S) cmd.example %(Show differences between local Endpoints and those configured # on the platform but only files starting with "example", # e.g., "endpoints/example1.lua", "endpoints/example-foo.lua", etc. # # NOTE: Use single quotes to prevent shell interpolation of the '*'. ), %(murano diff -E 'endpoints/example*') cmd.example %(Show status of specific files ), %(murano status services/user.lua endpoints/example.lua) cmd.action do |args, | # SKIP: cmd.verify_arg_count!(args) .default( all: nil, asdown: nil, asup: nil, diff: false, grouped: true, show_all: false, show_type: false, # delete/create/update are not options the user can specify # for status or diff commands; but the SyncUpDown class expects # them. delete: true, create: true, update: true, ) cmd_defaults_solntype_pickers() cmd_defaults_syncable_pickers() @grouped = { toadd: [], todel: [], tomod: [], unchg: [], skipd: [], clash: [] } # Check that user doesn't try to asdown and asup, or no-asdown and no-asup. if .asdown.nil? && .asup.nil? .asdown = false .asup = true elsif !.asdown.nil? && !.asup.nil? unless .asdown ^ .asup error('Please specify either --asdown or --asup, but not both!') exit 1 end elsif .asdown.nil? .asdown = !.asup elsif .asup.nil? .asup = !.asdown else raise('Unexpected code path.') end MrMurano::SyncRoot.instance.each_filtered(.__hash__) do |_name, type, klass, desc| MrMurano::Verbose.whirly_msg "Fetching #{Inflecto.pluralize(desc)}..." begin syncable = klass.new rescue MrMurano::ConfigError => err MrMurano::Verbose.error "Could not fetch status for #{desc}: #{err}" rescue StandardError => _err raise else ret = syncable.status(, args) gmerge(ret, type, desc, ) end end MrMurano::Verbose.whirly_stop pretty(@grouped, ) if .grouped end end |
#gmerge(ret, type, desc, options) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/MrMurano/commands/status.rb', line 249 def gmerge(ret, type, desc, ) if .grouped out = @grouped else out = { toadd: [], todel: [], tomod: [], unchg: [], skipd: [], clash: [] } end %i[toadd todel tomod unchg skipd clash].each do |kind| ret[kind].each do |item| hitem = item.to_h hitem[:pp_type] = type hitem[:pp_desc] = desc hitem[:locus] = item.location_friendly(show_type: .show_type) out[kind] << hitem end end pretty(out, ) unless .grouped end |
#highlight_chg(msg) ⇒ Object
241 242 243 |
# File 'lib/MrMurano/commands/status.rb', line 241 def highlight_chg(msg) Rainbow(msg).green.bright end |
#highlight_del(msg) ⇒ Object
245 246 247 |
# File 'lib/MrMurano/commands/status.rb', line 245 def highlight_del(msg) Rainbow(msg).red.bright end |
#interject(msg) ⇒ Object
170 171 172 |
# File 'lib/MrMurano/commands/status.rb', line 170 def interject(msg) MrMurano::Verbose.whirly_interject { say msg } end |
#pretty(ret, options) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/MrMurano/commands/status.rb', line 174 def pretty(ret, ) pretty_group_header( ret[:toadd], 'Only on local machine', 'new locally', .grouped ) ret[:toadd].each do |item| interject " + #{item[:pp_type]} #{highlight_chg(item[:locus])}" pretty_diff(item, ) end pretty_group_header( ret[:todel], 'Only on remote server', 'new remotely', .grouped ) ret[:todel].each do |item| interject " - #{item[:pp_type]} #{highlight_del(item[:locus])}" pretty_diff(item, ) end pretty_group_header( ret[:tomod], 'Items that differ', 'that differs', .grouped ) ret[:tomod].each do |item| interject " M #{item[:pp_type]} #{highlight_chg(item[:locus])}" interject item[:diff] if .diff end # 2018-04-24: (lb): If one or the other solutions is not setup (app or prod) # don't care, and don't indicate to user that missing soln's items are dirty. # MAYBE: (lb): We can probably delete this comment. Keeping until more confident. #unless ret[:skipd].empty? # pretty_group_header( # ret[:skipd], 'Items without a solution', 'without a solution', options.grouped # ) # ret[:skipd].each do |item| # interject " - #{item[:pp_type]} #{highlight_del(item[:locus])}" # end #end unless ret[:clash].empty? pretty_group_header( ret[:clash], 'Conflicting items', 'in conflict', .grouped ) ret[:clash].each do |item| abbrev = $cfg['tool.ascii'] && 'x' || '✗' interject " #{abbrev} #{item[:pp_type]} #{highlight_del(item[:locus])}" end end return unless .show_all interject 'Unchanged:' if .grouped ret[:unchg].each { |item| interject " #{item[:pp_type]} #{item[:locus]}" } end |
#pretty_diff(item, options) ⇒ Object
235 236 237 238 239 |
# File 'lib/MrMurano/commands/status.rb', line 235 def pretty_diff(item, ) return unless .diff && $cfg['tool.verbose'] return unless !item[:diff].nil? && !item[:diff].empty? interject item[:diff] end |
#pretty_group_header(group, header_any, header_empty, grouped) ⇒ Object
226 227 228 229 230 231 232 233 |
# File 'lib/MrMurano/commands/status.rb', line 226 def pretty_group_header(group, header_any, header_empty, grouped) return unless grouped if !group.empty? interject "#{header_any}:" else interject "Nothing #{header_empty}" end end |