Sha256: f4cd10cc16fff5d5d68fc55564a6eb0c9e5c85c6041cf261fa0b933088ae1bfb

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require 'thor'
require 'json'
require 'yaml'

module Koma
  class CLI < Thor
    desc 'ssh', 'stdout remote host inventory'
    option :key,
           type: :string,
           banner: '<key1,key2,..>',
           desc: 'inventory keys',
           aliases: :k
    option :yaml,
           type: :boolean,
           desc: 'stdout YAML',
           aliases: :y
    option :identity_file,
           type: :string,
           banner: '<identity_file>',
           desc: 'identity file',
           aliases: :i
    option :port,
           type: :numeric,
           banner: '<port>',
           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: '<key1,key2,..>',
           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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
koma-0.6.0 lib/koma/cli.rb