Class: Kitchen::Box::CLI
- Inherits:
-
Thor
- Object
- Thor
- Kitchen::Box::CLI
- Defined in:
- lib/kitchen/box/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
18 19 20 |
# File 'lib/kitchen/box/cli.rb', line 18 def self.exit_on_failure? true end |
Instance Method Details
#doctor ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kitchen/box/cli.rb', line 35 def doctor source = catalog entries = selected_entries(source) raise UserError, "No boxes match the selected filters" if entries.empty? results = entries.map { |entry| check_entry(source, entry) } if [:json] puts JSON.pretty_generate(results) else results.each { |entry| puts "#{entry[:error] ? "FAIL" : "OK"} #{entry[:file]}#{entry[:error] && " #{entry[:error]}"}" } end exit 1 if results.any? { |entry| entry[:error] } end |
#list ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/kitchen/box/cli.rb', line 23 def list entries = selected_entries(catalog) if [:json] puts JSON.pretty_generate(entries) else rows = entries.map { |entry| entry.values_at(*Catalog::FIELDS.first(6)) } print_table([%w{Name Version Provider Architecture File Bytes}, *rows]) end end |
#prune ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/kitchen/box/cli.rb', line 52 def prune raise UserError, "Use kitchen box prune --dry-run to preview cache cleanup" unless [:dry_run] cache = Cache.new([:cache]) plan = cache.prune_plan(**filters) if [:json] puts JSON.pretty_generate(plan.merge(cache: cache.root, dry_run: true)) else puts "Dry run for #{cache.root}" plan.fetch(:removable).each { |row| puts "Would remove #{box_label(row)} (#{row.fetch(:bytes)} bytes)\n #{row.fetch(:path)}" } plan.fetch(:protected).each { |row| puts "Keep #{box_label(row)} (#{row.fetch(:reason)})" } bytes = plan.fetch(:reclaimable_bytes) puts "#{plan.fetch(:removable).size} archive(s), #{bytes} bytes reclaimable (#{format("%.2f", bytes.fdiv(1024**2))} MiB)" end end |