Class: ArgManager

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeArgManager

Returns a new instance of ArgManager.



5
6
7
# File 'lib/woodstove/argmanager.rb', line 5

def initialize
  @commands = {}
end

Instance Method Details

#commandsObject



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

#runObject



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