-
Notifications
You must be signed in to change notification settings - Fork 8
Home
mosop edited this page Dec 1, 2016
·
35 revisions
- Basics
- Parsing Options
- Handling Exits
- Bash Completion
- Defining Subcommand
- Generating Help
- Versioning Commands
You can set a command's version with the CommandBase.version method.
class Command < Cli::Command
version "1.0.0"
endTo access the version string in a running context, use the CommandBase#version method.
class Command < Cli::Command
version "1.0.0"
def run
version # => "1.0.0"
end
endLike the CommandBase#help! method, the CommandBase#version! method exits with a version string.
class Command < Cli::Command
version "1.0.0"
def run
version! # prints "1.0.0" and exits
end
endWithout an explicit definition, a subcommand inherits its supercommand's version.
class Command < Cli::Supercommand
version "1.1.0"
command "specific"
command "inherit"
module Commands
class Specific < Cli::Command
version "1.0.0"
def run
version # => "1.0.0"
end
end
class Inherit < Cli::Command
def run
version # => "1.1.0"
end
end
end
endThe Options.version method adds the -v and --version options to your command. These options can be used to print a version string.
class Command < Cli::Command
class Options
version # equivalent to on(%w(-v --version)) { command.version! }
end
endYou can change the option's name:
class Command < Cli::Command
class Options
version "--show-version"
end
end