Class: CommandKit::Command
- Inherits:
-
Object
- Object
- CommandKit::Command
- Includes:
- Arguments, Description, Env, Examples, ExceptionHandler, FileUtils, Help, Main, Options, Printing, Stdio, Usage
- Defined in:
- lib/command_kit/command.rb
Overview
Note:
The command class base-class.
Examples
class MyCmd < CommandKit::Command
usage '[OPTIONS] [-o OUTPUT] FILE'
option :count, short: '-c',
value: {
type: Integer,
default: 1
},
desc: "Number of times"
option :output, short: '-o',
value: {
type: String,
usage: 'FILE'
},
desc: "Optional output file"
argument :file, required: true,
usage: 'FILE',
desc: "Input file"
examples [
'-o path/to/output.txt path/to/input.txt',
'-v -c 2 -o path/to/output.txt path/to/input.txt',
]
description 'Example command'
def run(*files)
# ...
end
end
initialize and using instance variables
option :verbose, short: '-v', desc: "Increase verbose level" do
@verbose += 1
end
def initialize(**kwargs)
super(**kwargs)
@verbose = 0
end
Direct Known Subclasses
Constant Summary
Constants included from Printing
Instance Attribute Summary
Attributes included from CommandName
Attributes included from Options
Attributes included from Options::Parser
Attributes included from Env
Method Summary
Methods included from FileUtils
Methods included from ExceptionHandler
Methods included from Printing
#print_error, #print_exception
Methods included from Stdio
#abort, #gets, #initialize, #print, #printf, #putc, #puts, #readline, #readlines, #stderr, #stdin, #stdout
Methods included from Description
#description, #help, #help_description
Methods included from Description::ModuleMethods
Methods included from Help
Methods included from Help::ModuleMethods
Methods included from Examples
#examples, #help, #help_examples
Methods included from Examples::ModuleMethods
Methods included from CommandName
Methods included from CommandKit::CommandName::ModuleMethods
Methods included from Options
Methods included from Options::ModuleMethods
Methods included from Options::Parser
#help, #help_options, #initialize, #main, #on_ambiguous_argument, #on_ambiguous_option, #on_invalid_argument, #on_invalid_option, #on_missing_argument, #on_needless_argument, #on_parse_error, #parse_options