Module: Clamp::Subcommand::Declaration

Included in:
Command
Defined in:
lib/clamp/subcommand/declaration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_subcommand(*args, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/clamp/subcommand/declaration.rb', line 30

def default_subcommand(*args, &block)
  if args.empty?
    @default_subcommand ||= nil
  else
    $stderr.puts "WARNING: Clamp default_subcommand syntax has changed; check the README."
    $stderr.puts "  (from #{caller.first})"
    subcommand(*args, &block)
    self.default_subcommand = args.first
  end
end

Instance Method Details

#find_subcommand(name) ⇒ Object



24
25
26
# File 'lib/clamp/subcommand/declaration.rb', line 24

def find_subcommand(name)
  recognised_subcommands.find { |sc| sc.is_called?(name) }
end

#has_subcommands?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/clamp/subcommand/declaration.rb', line 20

def has_subcommands?
  !recognised_subcommands.empty?
end

#recognised_subcommandsObject



8
9
10
# File 'lib/clamp/subcommand/declaration.rb', line 8

def recognised_subcommands
  @recognised_subcommands ||= []
end

#subcommand(name, description, subcommand_class = self, &block) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/clamp/subcommand/declaration.rb', line 12

def subcommand(name, description, subcommand_class = self, &block)
  if block
    # generate a anonymous sub-class
    subcommand_class = Class.new(subcommand_class, &block)
  end
  recognised_subcommands << Subcommand.new(name, description, subcommand_class)
end