Class: Cl
- Inherits:
-
Object
- Object
- Cl
- Defined in:
- lib/cl.rb,
lib/cl/ui.rb,
lib/cl/arg.rb,
lib/cl/cmd.rb,
lib/cl/ctx.rb,
lib/cl/dsl.rb,
lib/cl/opt.rb,
lib/cl/args.rb,
lib/cl/cast.rb,
lib/cl/help.rb,
lib/cl/opts.rb,
lib/cl/config.rb,
lib/cl/errors.rb,
lib/cl/helper.rb,
lib/cl/parser.rb,
lib/cl/runner.rb,
lib/cl/version.rb,
lib/cl/help/cmd.rb,
lib/cl/help/cmds.rb,
lib/cl/config/env.rb,
lib/cl/help/table.rb,
lib/cl/help/usage.rb,
lib/cl/help/format.rb,
lib/cl/config/files.rb,
lib/cl/runner/multi.rb,
lib/cl/opts/validate.rb,
lib/cl/parser/format.rb,
lib/cl/helper/suggest.rb,
lib/cl/runner/default.rb
Defined Under Namespace
Modules: Cast, Merge, Regex, Runner, Suggest, Ui, Underscore, Wrap Classes: Arg, Args, Cmd, Config, Ctx, Error, Help, InvalidFormat, Opt, Opts, OutOfRange, Parser, RequiredOpts, RequiredsOpts, RequiresOpts, UnknownArgumentValue, UnknownCmd, UnknownOption, UnknownValues
Constant Summary collapse
Constants included from Merge
Instance Attribute Summary collapse
-
#ctx ⇒ Object
readonly
Returns the value of attribute ctx.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#help(*args) ⇒ Object
Returns help output for the given command.
-
#initialize(ctx, name, opts) ⇒ Cl
constructor
A new instance of Cl.
-
#run(args) ⇒ Object
Runs the command.
-
#runner(args) ⇒ Object
Returns a runner instance for the given arguments.
Methods included from Wrap
Methods included from Regex
Methods included from Merge
Constructor Details
Instance Attribute Details
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
9 10 11 |
# File 'lib/cl.rb', line 9 def ctx @ctx end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/cl.rb', line 9 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
9 10 11 |
# File 'lib/cl.rb', line 9 def opts @opts end |
Instance Method Details
#help(*args) ⇒ Object
Returns help output for the given command
49 50 51 52 |
# File 'lib/cl.rb', line 49 def help(*args) runner(['help', *args]).cmd.help rescue StandardError end |
#run(args) ⇒ Object
Runs the command.
Instantiates a runner with the given arguments, and runs it.
If the command fails (raises a Cl::Error) then the exception is caught, and the process aborted with the error message and help output for the given command.
33 34 35 36 37 38 39 |
# File 'lib/cl.rb', line 33 def run(args) runner(args).run rescue UnknownCmd => e ctx.abort e rescue Error => e ctx.abort e, help(args.first) end |
#runner(args) ⇒ Object
Returns a runner instance for the given arguments.
42 43 44 45 46 |
# File 'lib/cl.rb', line 42 def runner(args) runner = :default if args.first.to_s == 'help' runner ||= opts[:runner] || :default Runner[runner].new(ctx, args) end |