Class: Bard::CLI::Command

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/bard/cli/command.rb

Direct Known Subclasses

New, Provision

Class Method Summary collapse

Class Method Details

.desc(command, description) ⇒ Object



4
5
6
7
8
# File 'lib/bard/cli/command.rb', line 4

def self.desc command, description
  @command = command
  @method = command.split(" ").first.to_sym
  @description = description
end

.option(*args, **kwargs) ⇒ Object



10
11
12
13
# File 'lib/bard/cli/command.rb', line 10

def self.option *args, **kwargs
  @option_args = args
  @option_kwargs = kwargs
end

.setup(cli) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bard/cli/command.rb', line 15

def self.setup cli
  cli.desc @command, @description
  cli.option *@option_args, **@option_kwargs if @option_args || @option_kwargs
  # put in local variables so next block can capture it
  command_class = self
  method = @method
  cli.define_method method do |*args|
    command = command_class.new(self)
    command.send method, *args
  end
end