Class: MisterBin::Command
- Inherits:
-
Object
- Object
- MisterBin::Command
- Includes:
- Colsole
- Defined in:
- lib/mister_bin/command.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Class Method Summary collapse
- .command(name, text) ⇒ Object
- .environment(name, value) ⇒ Object
- .example(text) ⇒ Object
- .execute(argv = []) ⇒ Object
- .help(text) ⇒ Object
- .meta ⇒ Object
- .option(flags, text) ⇒ Object
- .param(param, text) ⇒ Object
-
.summary(text) ⇒ Object
DSL.
- .usage(text) ⇒ Object
- .version(text) ⇒ Object
Instance Method Summary collapse
-
#initialize(args = nil) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(args = nil) ⇒ Command
Returns a new instance of Command.
10 11 12 |
# File 'lib/mister_bin/command.rb', line 10 def initialize(args = nil) @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/mister_bin/command.rb', line 8 def args @args end |
Class Method Details
.command(name, text) ⇒ Object
49 50 51 52 |
# File 'lib/mister_bin/command.rb', line 49 def command(name, text) target_commands << name.to_sym .commands << [name, text] end |
.environment(name, value) ⇒ Object
62 63 64 |
# File 'lib/mister_bin/command.rb', line 62 def environment(name, value) .env_vars << [name, value] end |
.example(text) ⇒ Object
58 59 60 |
# File 'lib/mister_bin/command.rb', line 58 def example(text) .examples << text end |
.execute(argv = []) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mister_bin/command.rb', line 15 def execute(argv=[]) args = Docopt.docopt docopt, version: .version, argv: argv instance = new args target = find_target_command instance, args exitcode = instance.send target exitcode.is_a?(Numeric) ? exitcode : 0 rescue Docopt::Exit => e puts e. 1 end |
.help(text) ⇒ Object
33 34 35 |
# File 'lib/mister_bin/command.rb', line 33 def help(text) .help = text end |
.meta ⇒ Object
66 67 68 |
# File 'lib/mister_bin/command.rb', line 66 def @meta ||= CommandMeta.new end |
.option(flags, text) ⇒ Object
45 46 47 |
# File 'lib/mister_bin/command.rb', line 45 def option(flags, text) . << [flags, text] end |
.param(param, text) ⇒ Object
54 55 56 |
# File 'lib/mister_bin/command.rb', line 54 def param(param, text) .params << [param, text] end |
.summary(text) ⇒ Object
DSL
29 30 31 |
# File 'lib/mister_bin/command.rb', line 29 def summary(text) .summary = text end |
.usage(text) ⇒ Object
41 42 43 |
# File 'lib/mister_bin/command.rb', line 41 def usage(text) .usages << text end |
.version(text) ⇒ Object
37 38 39 |
# File 'lib/mister_bin/command.rb', line 37 def version(text) .version = text end |