Class: Cl::Cmd

Inherits:
Object
  • Object
show all
Extended by:
Dsl, Merge, Underscore
Includes:
Registry
Defined in:
lib/cl/cmd.rb,
lib/cl/dsl.rb

Overview

Base class for all command classes that can be run.

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

See Dsl for details on the DSL methods.

Direct Known Subclasses

Help

Defined Under Namespace

Modules: Dsl

Constant Summary

Constants included from Merge

Merge::MERGE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Merge

merge

Methods included from Underscore

underscore

Methods included from Dsl

abstract, arg, description, examples, opt, required, required?, summary

Constructor Details

#initialize(ctx, args) ⇒ Cmd

Returns a new instance of Cmd.



44
45
46
47
48
49
# File 'lib/cl/cmd.rb', line 44

def initialize(ctx, args)
  args, opts = self.class.parse(ctx, args)
  @ctx = ctx
  @opts = self.class.opts.apply(self, self.opts.merge(opts))
  @args = self.class.args.apply(self, args, opts)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



41
42
43
# File 'lib/cl/cmd.rb', line 41

def args
  @args
end

#ctxObject (readonly)

Returns the value of attribute ctx.



41
42
43
# File 'lib/cl/cmd.rb', line 41

def ctx
  @ctx
end

#deprecationsObject

Returns the value of attribute deprecations.



42
43
44
# File 'lib/cl/cmd.rb', line 42

def deprecations
  @deprecations
end

Class Method Details

.cmdsObject



28
29
30
# File 'lib/cl/cmd.rb', line 28

def cmds
  registry.values
end

.parse(ctx, args) ⇒ Object



32
33
34
35
36
# File 'lib/cl/cmd.rb', line 32

def parse(ctx, args)
  opts = Parser.new(self.opts, args).opts unless self == Help
  opts = merge(ctx.config[registry_key], opts) if ctx.config[registry_key]
  [args, opts || {}]
end

Instance Method Details

#optsObject



51
52
53
# File 'lib/cl/cmd.rb', line 51

def opts
  @opts ||= {}
end