Class: Roll::Command
- Inherits:
-
Object
- Object
- Roll::Command
- Defined in:
- lib/roll/command.rb
Overview
Command-line Interface
– TODO: clean command to remove dead directories from environment ++
Direct Known Subclasses
CommandEnv, CommandHelp, CommandIn, CommandIndex, CommandList, CommandOut, CommandPath, CommandSync, CommandUse, CommandVerify
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Command-line arguments.
-
#op ⇒ Object
readonly
Instance of OptionParser.
-
#opts ⇒ Object
readonly
Command-line options.
Class Method Summary collapse
-
.main(*argv) ⇒ Object
Initialize and execute command.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(*argv) ⇒ Command
constructor
New Command.
Constructor Details
#initialize(*argv) ⇒ Command
New Command.
37 38 39 40 41 42 43 |
# File 'lib/roll/command.rb', line 37 def initialize(*argv) # only need optparse when command is run require 'optparse' @op = OptionParser.new @args = argv @opts = {} end |
Instance Attribute Details
#args ⇒ Object (readonly)
Command-line arguments.
13 14 15 |
# File 'lib/roll/command.rb', line 13 def args @args end |
#op ⇒ Object (readonly)
Instance of OptionParser.
19 20 21 |
# File 'lib/roll/command.rb', line 19 def op @op end |
#opts ⇒ Object (readonly)
Command-line options.
16 17 18 |
# File 'lib/roll/command.rb', line 16 def opts @opts end |
Class Method Details
.main(*argv) ⇒ Object
Initialize and execute command.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/roll/command.rb', line 22 def self.main(*argv) #cmd = argv.shift idx = argv.index{ |e| e !~ /^\-/ } cmd = idx ? argv.delete_at(idx) : 'help' begin require "roll/commands/#{cmd}" rescue LoadError cmd = 'help' require "roll/commands/#{cmd}" end klass = ::Roll.const_get("Command#{cmd.capitalize}") klass.new(*argv).execute end |
Instance Method Details
#execute ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/roll/command.rb', line 46 def execute setup op.on_tail("--warn", "-w", "Show warnings.") do $VERBOSE = true end op.on_tail("--debug", "Run in debugging mode.") do $DEBUG = true $VERBOSE = true end op.on_tail("--help", "-h", "Display this help message.") do puts op exit end op.parse!(args) call end |