class Cl::Cmd

Base class for all command classes that can be run.

Inherit your command classes from this class, use the {Cl::Cmd::Dsl} to declare arguments, options, summary, description, examples etc., and implement the method run.

See {Cl::Cmd::Dsl} for details on the DSL methods.

Attributes

auto_register[RW]
args[R]
ctx[R]

Public Class Methods

cmds() click to toggle source
# File lib/cl/cmd.rb, line 35
def cmds
  registry.values.uniq
end
new(ctx, args) click to toggle source
# File lib/cl/cmd.rb, line 59
def initialize(ctx, args)
  @ctx = ctx
  args, opts = self.class.parse(ctx, self, args)
  @opts = self.class.opts.apply(self, self.opts.merge(opts))
  @args = self.class.args.apply(self, args, opts) unless help? && !is_a?(Help)
end
parse(ctx, cmd, args) click to toggle source
# File lib/cl/cmd.rb, line 39
def parse(ctx, cmd, args)
  parser = Parser.new(cmd, args)
  args, opts = parser.args, parser.opts unless self == Help
  opts = merge(ctx.config[registry_key], opts) if ctx.config[registry_key]
  [args, opts || {}]
end
suggestions(opt) click to toggle source
# File lib/cl/cmd.rb, line 46
def suggestions(opt)
  suggest(opts.map(&:name), opt.sub(/^--/, ''))
end

Public Instance Methods

deprecations() click to toggle source
# File lib/cl/cmd.rb, line 70
def deprecations
  @deprecations ||= {}
end
opts() click to toggle source
# File lib/cl/cmd.rb, line 66
def opts
  @opts ||= {}
end