Class: Dandelion::Command::Base
- Inherits:
-
Object
- Object
- Dandelion::Command::Base
- Defined in:
- lib/dandelion/command.rb
Constant Summary collapse
- @@commands =
{}
Class Method Summary collapse
- .command(name) ⇒ Object
- .commands ⇒ Object
- .create(name) ⇒ Object
- .parser(options) ⇒ Object
- .require_commands ⇒ Object
Instance Method Summary collapse
-
#initialize(options) {|_self| ... } ⇒ Base
constructor
A new instance of Base.
Constructor Details
Class Method Details
.command(name) ⇒ Object
17 18 19 |
# File 'lib/dandelion/command.rb', line 17 def command(name) @@commands[name] = self end |
.commands ⇒ Object
27 28 29 |
# File 'lib/dandelion/command.rb', line 27 def commands @@commands.keys end |
.create(name) ⇒ Object
21 22 23 24 25 |
# File 'lib/dandelion/command.rb', line 21 def create(name) require_commands raise InvalidCommandError unless @@commands.include?(name) @@commands[name] end |
.parser(options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dandelion/command.rb', line 35 def parser() OptionParser.new do |opts| opts. = 'Usage: dandelion [options] <command> [<args>]' opts.on('-v', '--version', 'Display the current version') do puts "Dandelion #{Dandelion::VERSION}" exit end opts.on('-h', '--help', 'Display this screen') do require_commands puts opts puts "\nAvailable commands:" puts commands.map { |name| " #{name}" }.join("\n") exit end [:repo] = closest_repo(File.('.')) opts.on('--repo=[REPO]', 'Use the given repository') do |repo| [:repo] = File.(repo) end [:config] = nil opts.on('--config=[CONFIG]', 'Use the given configuration file') do |config| [:config] = File.(config) end end end |
.require_commands ⇒ Object
31 32 33 |
# File 'lib/dandelion/command.rb', line 31 def require_commands Dir.glob(File.join(File.dirname(__FILE__), 'command', '*.rb')) { |file| require file } end |