Sha256: c9d512fe4021a41390c7146ebd68b74873eee6d090f6c7c28804a14010c1f244
Contents?: true
Size: 1.64 KB
Versions: 2
Compression:
Stored size: 1.64 KB
Contents
module Cloudkick::Command class Help < Base class HelpGroup < Array attr_reader :title def initialize(title) @title = title end def command(name, description) self << [name, description] end def space self << ['', ''] end end def self.groups @groups ||= [] end def self.group(title, &block) groups << begin group = HelpGroup.new(title) yield group group end end def self.create_default_groups! group 'Commands' do |group| group.command 'help', 'show this usage' group.command 'version', 'show the gem version' group.space group.command 'pssh --query <query> ' \ '--username <username> ' \ '--command <command>', 'parallel ssh your nodes' end end def index display usage end def version display Cloudkick::Client.version end def usage longest_command_length = self.class.groups.map do |group| group.map { |g| g.first.length } end.flatten.max self.class.groups.inject(StringIO.new) do |output, group| output.puts "=== %s" % group.title output.puts group.each do |command, description| if command.empty? output.puts else output.puts "%-*s # %s" % [longest_command_length, command, description] end end output.puts output end.string end end end Cloudkick::Command::Help.create_default_groups!
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cloudkick-0.2.8 | lib/cloudkick/commands/help.rb |
cloudkick-0.2.7 | lib/cloudkick/commands/help.rb |