Module: Prmd::CLI::Base
Overview
Base module for CLI commands.
Instance Method Summary collapse
-
#execute(options = {}) ⇒ void
abstract
Method called to actually execute the command provided with an options Hash from the commands #parse_options.
-
#make_parser(options = {}) ⇒ OptionParser
abstract
Create a parser specific for this command.
-
#noop_execute(options = {}) ⇒ void
Method called when the command is ran with the :noop option enabled.
-
#parse_options(argv, options = {}) ⇒ Hash<Symbol, Object>
Parse the given argv and produce a options Hash specific to the command.
-
#run(argv, options = {}) ⇒ void
Run this command given a argv and optional options Hash.
Instance Method Details
#execute(options = {}) ⇒ void
This method returns an undefined value.
Method called to actually execute the command provided with an options Hash from the commands #parse_options.
113 114 115 |
# File 'lib/prmd/cli/base.rb', line 113 def execute( = {}) # end |
#make_parser(options = {}) ⇒ OptionParser
Create a parser specific for this command. The parsers produced by this method should yield their options.
25 26 27 |
# File 'lib/prmd/cli/base.rb', line 25 def make_parser( = {}) # end |
#noop_execute(options = {}) ⇒ void
This method returns an undefined value.
Method called when the command is ran with the :noop option enabled. As the option implies, this should do absolutely nothing.
122 123 124 |
# File 'lib/prmd/cli/base.rb', line 122 def noop_execute( = {}) $stderr.puts end |
#parse_options(argv, options = {}) ⇒ Hash<Symbol, Object>
Parse the given argv and produce a options Hash specific to the command. The returned options Hash will include an :argv key which contains the remaining args from the parse operation.
67 68 69 70 71 72 73 74 75 |
# File 'lib/prmd/cli/base.rb', line 67 def (argv, = {}) opts = {} parser = make_parser() do |key, value| set_option(opts, key, value) end argv = execute_parser(parser, argv) opts[:argv] = argv opts end |
#run(argv, options = {}) ⇒ void
This method returns an undefined value.
Run this command given a argv and optional options Hash. If all you have is the options from the #parse_options method, use #execute instead.
136 137 138 139 140 141 142 143 |
# File 'lib/prmd/cli/base.rb', line 136 def run(argv, = {}) = .merge((argv, )) if [:noop] noop_execute() else execute() end end |