lib/koma/cli.rb in koma-0.11.0 vs lib/koma/cli.rb in koma-0.12.0
- old
+ new
@@ -2,17 +2,19 @@
require 'json'
require 'yaml'
module Koma
class CLI < Thor
+ class_option :version, type: :boolean, aliases: :V
+
desc 'ssh <host1,host2,..>', '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
Koma::HostInventory.disabled_keys.each do |key|
- option "with-#{key}", type: :boolean, desc: "enable #{key}"
+ option "enable-#{key}", type: :boolean, desc: "enable #{key}"
end
def ssh(host = nil)
if host.nil?
begin
stdin = timeout(1) { $stdin.read }
@@ -32,11 +34,11 @@
else
puts JSON.pretty_generate(gathered)
end
end
- desc 'run-command <host1,host2,..> <command1> <command2> ...', 'run command on a remote machine'
+ desc 'run-command <host1,host2,..> <command1> <command2> ...', 'run command on remote hosts'
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 run_command(host = nil, *commands)
if host.nil?
@@ -73,11 +75,11 @@
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
Koma::HostInventory.disabled_keys.each do |key|
- option "with-#{key}", type: :boolean, desc: "enable #{key}"
+ option "enable-#{key}", type: :boolean, desc: "enable #{key}"
end
def exec
backend = Koma::Backend::Exec.new(nil, options)
if options[:yaml]
puts YAML.dump(backend.gather)
@@ -92,12 +94,11 @@
key += ' (disabled)' if Koma::HostInventory.disabled_keys.include?(key)
puts key
end
end
- option :version, type: :boolean, aliases: :V
- def help(version = nil)
- if version
+ def help(command = nil)
+ if options[:version]
puts Koma::VERSION
else
super
end
end