Class: ArgManager
- Inherits:
-
Object
- Object
- ArgManager
- Defined in:
- lib/woodstove/argmanager.rb
Overview
woodstove argmanager - a simple argument manager for woodstove Copyright © 2016 the furry entertainment project Licensed under the MIT license.
Instance Method Summary collapse
- #commands ⇒ Object
-
#initialize ⇒ ArgManager
constructor
A new instance of ArgManager.
- #register(key, command) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ ArgManager
Returns a new instance of ArgManager.
5 6 7 |
# File 'lib/woodstove/argmanager.rb', line 5 def initialize @commands = {} end |
Instance Method Details
#commands ⇒ Object
23 24 25 |
# File 'lib/woodstove/argmanager.rb', line 23 def commands @commands end |
#register(key, command) ⇒ Object
20 21 22 |
# File 'lib/woodstove/argmanager.rb', line 20 def register key, command @commands[key] = command end |
#run ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/woodstove/argmanager.rb', line 8 def run @commands.each do |command| if ARGV[0] == command[1].long || ARGV[0] == command[1].short command[1].run ARGV[1..-1] return end end if @commands[:help] @commands[:help].incorrect_usage exit 1 end end |