Class: Switchboard::Command
- Inherits:
-
Object
- Object
- Switchboard::Command
show all
- Defined in:
- lib/switchboard/commands/command.rb
Direct Known Subclasses
Switchboard::Commands::Config, Switchboard::Commands::Default, Switchboard::Commands::Disco, Switchboard::Commands::Disco::Info, Switchboard::Commands::Disco::Items, Switchboard::Commands::Grep, Switchboard::Commands::Help, Switchboard::Commands::Last, Switchboard::Commands::PEP, Switchboard::Commands::PEP::Location, Switchboard::Commands::PEP::Tune, Switchboard::Commands::PubSub, Switchboard::Commands::PubSub::Affiliations, Switchboard::Commands::PubSub::Config, Switchboard::Commands::PubSub::Create, Switchboard::Commands::PubSub::Delete, Switchboard::Commands::PubSub::Info, Switchboard::Commands::PubSub::Items, Switchboard::Commands::PubSub::Listen, Switchboard::Commands::PubSub::Nodes, Switchboard::Commands::PubSub::Options, Switchboard::Commands::PubSub::Publish, Switchboard::Commands::PubSub::Purge, Switchboard::Commands::PubSub::Retract, Switchboard::Commands::PubSub::Subscribe, Switchboard::Commands::PubSub::Subscriptions, Switchboard::Commands::PubSub::Unsubscribe, Switchboard::Commands::Register, Switchboard::Commands::Roster, Switchboard::Commands::Roster::Add, Switchboard::Commands::Roster::List, Switchboard::Commands::Roster::Online, Switchboard::Commands::Roster::Remove, Switchboard::Commands::Unregister
Class Method Summary
collapse
Class Method Details
.description(description = nil) ⇒ Object
29
30
31
32
|
# File 'lib/switchboard/commands/command.rb', line 29
def self.description(description = nil)
@description = description if description
@description
end
|
.help ⇒ Object
34
35
36
|
# File 'lib/switchboard/commands/command.rb', line 34
def self.help
"No help is available for this command (#{self.to_command_name})."
end
|
.options(opts) ⇒ Object
TODO consider accepting a block in subclasses
39
40
41
42
43
|
# File 'lib/switchboard/commands/command.rb', line 39
def self.options(opts)
@options = opts
@options.banner = "Usage: #{opts.program_name} [options] #{self.to_command_name} [options] [args]"
@options
end
|
.run! ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/switchboard/commands/command.rb', line 45
def self.run!
puts self.options(OptionParser.new).help
commands = Switchboard.commands(self)
if commands.any?
puts
puts "Available commands:"
commands.each do |name, command|
puts " #{command.to_command.ljust(15)}#{command.description}"
command.options(OptionParser.new).summarize do |line|
puts " " * 16 + line
end
end
puts
puts "See '#{@options.program_name} help COMMAND' for more information on a specific command."
end
end
|
.to_command ⇒ Object
63
64
65
|
# File 'lib/switchboard/commands/command.rb', line 63
def self.to_command
self.name.gsub("Switchboard::Commands::", "").split("::").last.downcase
end
|
.to_command_name(delimiter = " ") ⇒ Object
67
68
69
|
# File 'lib/switchboard/commands/command.rb', line 67
def self.to_command_name(delimiter = " ")
self.name.gsub("Switchboard::Commands::", "").split("::").map { |c| c.downcase } * delimiter
end
|