Class: Procodile::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/procodile/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



32
33
34
# File 'lib/procodile/cli.rb', line 32

def initialize
  @options = {}
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



30
31
32
# File 'lib/procodile/cli.rb', line 30

def config
  @config
end

#optionsObject

Returns the value of attribute options.



29
30
31
# File 'lib/procodile/cli.rb', line 29

def options
  @options
end

Class Method Details

.command(name) ⇒ Object



23
24
25
26
27
# File 'lib/procodile/cli.rb', line 23

def self.command(name)
  commands[name] = {:name => name, :description => @description, :options => @options}
  @description = nil
  @options = nil
end

.commandsObject



11
12
13
# File 'lib/procodile/cli.rb', line 11

def self.commands
  @commands ||= {}
end

.desc(description) ⇒ Object



15
16
17
# File 'lib/procodile/cli.rb', line 15

def self.desc(description)
  @description = description
end

.options(&block) ⇒ Object



19
20
21
# File 'lib/procodile/cli.rb', line 19

def self.options(&block)
  @options = block
end

Instance Method Details

#run(command) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/procodile/cli.rb', line 36

def run(command)
  if self.class.commands.keys.include?(command.to_sym)
    public_send(command)
  else
    raise Error, "Invalid command '#{command}'"
  end
end