Class: Speedflow::Command
- Inherits:
-
Object
- Object
- Speedflow::Command
- Extended by:
- Message
- Defined in:
- lib/speedflow/command.rb
Overview
Used to manage the commands
Direct Known Subclasses
Class Attribute Summary collapse
-
.argv ⇒ Object
Public: Define argv (used to test).
Class Method Summary collapse
-
.config_from_fresh_options(program, command, options = {}) ⇒ Object
Public: Get config from fresh options.
-
.config_from_options(options) ⇒ Object
Speedflow configuration with the options passed in as overrides.
-
.execute_from_option(prog, command, opt_key) ⇒ Object
Public: Exectute option from key.
-
.inherited(base) ⇒ Object
Keep a list of subclasses of Speedflow::Command every time it’s inherited.
-
.invalid_command(cmd) ⇒ Object
Display invalid command.
-
.subclasses ⇒ Object
A list of subclasses of Speedflow::Command.
Methods included from Message
error, info, message, notice, success
Class Attribute Details
.argv ⇒ Object
Public: Define argv (used to test)
Returns Array of argv.
95 96 97 |
# File 'lib/speedflow/command.rb', line 95 def argv @argv ||= ARGV end |
Class Method Details
.config_from_fresh_options(program, command, options = {}) ⇒ Object
Public: Get config from fresh options
program - Program. command - Commad. options - Options.
Returns configuration Hash.
50 51 52 53 54 55 56 |
# File 'lib/speedflow/command.rb', line 50 def (program, command, = {}) execute_from_option(program, command, 'config') do |value| = { config: value } end () end |
.config_from_options(options) ⇒ Object
Speedflow configuration with the options passed in as overrides
options - the configuration overrides
Returns a full Speedflow configuration.
33 34 35 36 37 38 39 40 41 |
# File 'lib/speedflow/command.rb', line 33 def () Speedflow::Configuration.get() rescue ConfigurationFileNotFound => exception error exception. abort rescue ConfigurationFileFormat => exception error exception. abort end |
.execute_from_option(prog, command, opt_key) ⇒ Object
Public: Exectute option from key
prog - Program. command - Commad. opt_key - Option key.
Returns nothing.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/speedflow/command.rb', line 65 def execute_from_option(prog, command, opt_key) opt_index = prog..find_index { |o| o.config_key == opt_key } opt = prog.[opt_index] opt_parser = OptionParser.new do |opts| command.(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) ⇒ Object
Keep a list of subclasses of Speedflow::Command every time it’s inherited. Called automatically.
base - the subclass
Returns nothing.
23 24 25 26 |
# File 'lib/speedflow/command.rb', line 23 def inherited(base) subclasses << base super(base) end |
.invalid_command(cmd) ⇒ Object
Display invalid command.
cmd - the command
Returns nothing
87 88 89 90 |
# 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 ⇒ Object
A list of subclasses of Speedflow::Command
Returns Array of commands.
13 14 15 |
# File 'lib/speedflow/command.rb', line 13 def subclasses @subclasses ||= [] end |