Class: Moose::Inventory::Cli::Application
- Inherits:
-
Thor
- Object
- Thor
- Moose::Inventory::Cli::Application
- Includes:
- Helpers
- Defined in:
- lib/moose_inventory/cli/application.rb
Overview
Top-level Thor application for moose-inventory. rubocop:disable Metrics/ClassLength
Constant Summary
Constants included from Helpers
Instance Method Summary collapse
- #console ⇒ Object
- #doctor ⇒ Object
- #export(file = nil) ⇒ Object
- #import(file) ⇒ Object
- #version ⇒ Object
Instance Method Details
#console ⇒ Object
87 88 89 |
# File 'lib/moose_inventory/cli/application.rb', line 87 def console Moose::Inventory::Cli::Console.new(context: inventory_context).run end |
#doctor ⇒ Object
36 37 38 39 40 |
# File 'lib/moose_inventory/cli/application.rb', line 36 def doctor report = build_operation(Moose::Inventory::Operations::InventoryDoctor).call render_doctor_report(report) exit(1) unless report[:ok] end |
#export(file = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/moose_inventory/cli/application.rb', line 43 def export(file = nil) snapshot = build_operation(Moose::Inventory::Operations::InventorySnapshot).export output = serialize_snapshot(snapshot) if file.nil? puts output else File.write(file, output) puts "Exported inventory snapshot to #{file}." end end |
#import(file) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/moose_inventory/cli/application.rb', line 58 def import(file) snapshot = YAML.safe_load_file(file, aliases: false) operation = build_operation(Moose::Inventory::Operations::ImportInventorySnapshot) return render_import_preview(operation.preview(snapshot: snapshot)) if [:preview] abort('ERROR: --preview-format requires --preview.') if [:preview_format] result = operation.call(snapshot: snapshot) record_audit({ command: 'import', action: 'import', entity_type: 'inventory', entity_names: file }, result: result) puts "Imported inventory snapshot from #{file}." puts "Created hosts: #{result.created_hosts}" puts "Created groups: #{result.created_groups}" puts "Variables changed: #{result.updated_variables}" puts "Associations added: #{result.associations}" rescue Psych::SyntaxError => e abort("ERROR: Could not parse inventory snapshot '#{file}': #{e.}") rescue db.exceptions[:moose] => e abort("ERROR: #{e.}") end |