class Speedflow::Command
Used to manage the commands
Attributes
argv[W]
@return [Hash] List of arguments
Public Class Methods
argv()
click to toggle source
Public: Define argv (used to test)
Returns Array of argv.
# File lib/speedflow/command.rb, line 95 def argv @argv ||= ARGV end
config_from_fresh_options(program, command, options = {})
click to toggle source
Public: Get config from fresh options
program - Program. command - Commad. options - Options.
Returns configuration Hash
.
# File lib/speedflow/command.rb, line 50 def config_from_fresh_options(program, command, options = {}) execute_from_option(program, command, 'config') do |value| options = { config: value } end config_from_options(options) end
config_from_options(options)
click to toggle source
Speedflow
configuration with the options passed in as overrides
options - the configuration overrides
Returns a full Speedflow
configuration.
# File lib/speedflow/command.rb, line 33 def config_from_options(options) Speedflow::Configuration.get(options) rescue ConfigurationFileNotFound => exception error exception.message abort rescue ConfigurationFileFormat => exception error exception.message abort end
execute_from_option(prog, command, opt_key) { |value| ... }
click to toggle source
Public: Exectute option from key
prog - Program. command - Commad. opt_key - Option key.
Returns nothing.
# File lib/speedflow/command.rb, line 65 def execute_from_option(prog, command, opt_key) opt_index = prog.options.find_index { |o| o.config_key == opt_key } opt = prog.options[opt_index] opt_parser = OptionParser.new do |opts| command.add_default_options(opts) opts.on(*opt.for_option_parser) { |value| yield(value) } end # rubocop:disable HandleExceptions begin opt_parser.parse(argv) rescue OptionParser::InvalidOption # Nothing. end # rubocop:enable HandleExceptions end
inherited(base)
click to toggle source
Keep a list of subclasses of Speedflow::Command
every time it's inherited. Called automatically.
base - the subclass
Returns nothing.
Calls superclass method
# File lib/speedflow/command.rb, line 23 def inherited(base) subclasses << base super(base) end
invalid_command(cmd)
click to toggle source
Display invalid command.
cmd - the command
Returns nothing
# File lib/speedflow/command.rb, line 87 def invalid_command(cmd) error "Command not found '#{cmd}'." notice 'Please, use --help to display valid commands.' end
subclasses()
click to toggle source
A list of subclasses of Speedflow::Command
Returns Array of commands.
# File lib/speedflow/command.rb, line 13 def subclasses @subclasses ||= [] end