Module: Shebang::Command::ClassMethods
- Defined in:
- lib/shebang/command.rb
Overview
Several methods that become available as class methods once Shebang::Command is extended by another class.
Instance Method Summary (collapse)
-
- (Object) banner(text)
Sets the banner for the command, trailing or leading newlines will be removed.
-
- (Object) command(name, options = {})
Binds a class to the specified command name.
-
- (Object) help(title, text)
Sets a general "help topic" with a custom title and content.
-
- (Object) option(short, long, desc = nil, options = {})
(also: #o)
Creates a new option for a command.
-
- (Object) usage(text)
A small shortcut for defining the syntax of a command.
Instance Method Details
- (Object) banner(text)
Sets the banner for the command, trailing or leading newlines will be removed.
72 73 74 |
# File 'lib/shebang/command.rb', line 72 def (text) @__banner = text.strip end |
- (Object) command(name, options = {})
Binds a class to the specified command name.
54 55 56 57 58 59 60 61 62 |
# File 'lib/shebang/command.rb', line 54 def command(name, = {}) name = name.to_sym if Shebang::Commands.key?(name) Shebang.error("The command #{name} has already been registered") end Shebang::Commands[name] = self end |
- (Object) help(title, text)
Sets a general "help topic" with a custom title and content.
101 102 103 104 |
# File 'lib/shebang/command.rb', line 101 def help(title, text) @__help_topics ||= {} @__help_topics[title] = text.strip end |
- (Object) option(short, long, desc = nil, options = {}) Also known as: o
Creates a new option for a command.
117 118 119 120 121 122 |
# File 'lib/shebang/command.rb', line 117 def option(short, long, desc = nil, = {}) @__options ||= [] option = Shebang::Option.new(short, long, desc, ) @__options.push(option) end |
- (Object) usage(text)
A small shortcut for defining the syntax of a command. This method is just a shortcut for the following:
help('Usage', 'foobar [OPTIONS]'
86 87 88 |
# File 'lib/shebang/command.rb', line 86 def usage(text) help('Usage', text) end |