require 'thor' require 'json' require 'yaml' module Koma class CLI < Thor desc 'ssh', 'stdout remote host inventory' option :key, type: :string, banner: '', desc: 'inventory keys', aliases: :k option :yaml, type: :boolean, desc: 'stdout YAML', aliases: :y option :identity_file, type: :string, banner: '', desc: 'identity file', aliases: :i option :port, type: :numeric, banner: '', desc: 'port', aliases: :p def ssh(host) backend = Koma::Backend::Ssh.new(host, options) if options[:yaml] puts YAML.dump(backend.gather) else puts JSON.pretty_generate(backend.gather) end end desc 'exec', 'stdout local host inventory' option :key, type: :string, banner: '', desc: 'inventory keys', aliases: :k option :yaml, type: :boolean, desc: 'stdout YAML', aliases: :y def exec backend = Koma::Backend::Exec.new(nil, options) if options[:yaml] puts YAML.dump(backend.gather) else puts JSON.pretty_generate(backend.gather) end end desc 'keys', 'host inventory keys' def keys Specinfra::HostInventory.inventory_keys.each do |key| puts key end end end end