Class: Moose::Inventory::Cli::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/moose_inventory/cli/console.rb

Overview

Small read-only interactive console for browsing inventory state.

Constant Summary collapse

COMMANDS =
['help', 'hosts', 'groups', 'host NAME', 'group NAME',
'tags host NAME', 'tags group NAME', 'audit [LIMIT]', 'quit'].freeze

Instance Method Summary collapse

Constructor Details

#initialize(context:, input: $stdin, output: $stdout) ⇒ Console

Returns a new instance of Console.



13
14
15
16
17
# File 'lib/moose_inventory/cli/console.rb', line 13

def initialize(context:, input: $stdin, output: $stdout)
  @context = context
  @input = input
  @output = output
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/moose_inventory/cli/console.rb', line 19

def run
  output.puts 'Moose Inventory console (read-only). Type help or quit.'
  input.each_line do |line|
    parts = parse_command(line)
    next if parts.nil? || parts.empty?

    break if quit_command?(parts)

    dispatch(parts)
  end
  output.puts 'Goodbye.'
end