RootClass
- Namespace
- Ancestors
Root of a hierarchy of Classes. This class should be subclassed by the root of your command-line interface.
- Example: An rm-like Command-line Interface with Ame
class Rm < Ame::Root version '1.0.0' flag 'f', '', false, 'Do not prompt for confirmation' flag 'i', '', nil, 'Prompt for confirmation' do |options| options['f'] = false end flag 'R', '', false, 'Remove file hierarchies' flag 'r', '', nil, 'Equivalent to -R' do |options| options['r'] = true end splus 'FILE', String, 'File to remove' description 'Remove directory entries' def rm(files, options = {}) require 'fileutils' FileUtils.send options['R'] ? :rm_r : :rm, [first] + rest, :force => options['f'] end end Rm.process
- Example: A Git-like Command-line Interface With Ame
module Git end class Git::CLI < Ame::Root version '1.0.0' class Git < Ame::Class description 'The stupid content tracker' def initialize; end description 'Prepare patches for e-mail submission' flag ?n, 'numbered', false, 'Name output in [PATCH n/m] format' flag ?N, 'no-numbered', nil, 'Name output in [PATCH] format' do |options| options['numbered'] = false end toggle ?s, 'signoff', false, 'Add Signed-off-by: line to the commit message' switch '', 'thread', 'STYLE', nil, Ame::Types::Enumeration[:shallow, :deep], 'Controls addition of In-Reply-To and References headers' flag '', 'no-thread', nil, 'Disables addition of In-Reply-To and Reference headers' do |options, _| options.delete 'thread' end option '', 'start-number', 'N', 1, 'Start numbering the patches at N instead of 1' multioption '', 'to', 'ADDRESS', String, 'Add a To: header to the email headers' optional 'SINCE', 'N/A', 'Generate patches for commits after SINCE' def format_patch(since = '', options = {}) p since, options end description 'Annotate file lines with commit information' argument 'FILE', String, 'File to annotate' def annotate(file) p file end description 'Add file contents to the index' splat 'PATHSPEC', String, 'Files to add content from' def add(paths) p paths end description 'Display gitattributes information' splus 'PATHNAME', String, 'Files to list attributes of' def check_attr(paths) p paths end class Remote < Ame::Class description 'Manage set of remote repositories' def initialize; end description 'Shows a list of existing remotes' flag 'v', 'verbose', false, 'Show remote URL after name' def list(options = {}) p options end description 'Adds a remote named NAME for the repository at URL' argument 'name', String, 'Name of the remote to add' argument 'url', String, 'URL to the repository of the remote to add' def add(name, url) p name, url end end dispatch Remote, :default => 'list' end dispatch Git end Git::CLI.process
Class Methods
help(help#method, #dispatch, #error, #version = nil
)#method, #dispatch, #error, #version#⚙
Sets the help object to use for displaying usage information, or returns it if help is nil. The default is to use a Help::Terminal object.
version(versionString? = nil
)String#⚙
Sets or returns, depending on if version is nil or not, the version of the receiver. The version may be used by .help to output version information.
process(method#to_sym = File.basename($0)
, argumentsArray<
String>
= ARGV
)self#⚙
Process arguments as a list of options and arguments, then call method with the results of this processing on a new instance of the receiver. This method catches AbortAllProcessing. Any errors will be caught and reported using .help#error.
call(method#to_sym, argumentsArray = nil
, optionsHash<
String, Object>
= nil
)self#⚙
Call method with arguments and options on a new instance of the receiver. This method catches AbortAllProcessing.
- Raises
-
- UnrecognizedMethod
-
If the method argument to a dispatch isn’t a known method
- UnrecognizedOption
-
If an unrecognized option has been given
- MissingArgument
-
If a required argument to an option is missing
- MalformedArgument
-
If an argument to an option can’t be parsed
- SuperfluousArgument
-
If more arguments than required/optional have been given
- MissingArgument
-
If a required argument is missing
- MalformedArgument
-
If an argument can’t be parsed