Class: CLIForge::Configuration
- Inherits:
-
Object
- Object
- CLIForge::Configuration
- Defined in:
- lib/cli_forge/configuration.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bin_name ⇒ Object
The name of the binary for this program; used to determine where to find sub-commands, help, etc.
-
#bin_separator ⇒ Object
Separator to use when searching for subcommands.
-
#default_command ⇒ Object
If no command is given, fall back to this.
-
#embedded_commands ⇒ Object
readonly
The set of embedded commands.
-
#search_paths ⇒ Object
Paths to search for sub command binaries.
Instance Method Summary collapse
-
#argument_filters ⇒ Object
The active argument filters.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#register_argument_filter(name, &block) ⇒ Object
Argument Filters —————- Argument filters are named procs that are given the current command’s arguments and have the opportunity to modify them.
-
#register_command(name, command_object) ⇒ Object
Embedded Sub Commands ——————— In addition to exposing sub commands via external bins, you can register specific commands directly:.
-
#remove_argument_filter(name) ⇒ Object
Remove a previously registered argument filter.
-
#remove_command(name) ⇒ Object
Remove a previosuly registered command.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
3 4 5 6 7 8 9 10 |
# File 'lib/cli_forge/configuration.rb', line 3 def initialize @default_command = "help" @bin_separator = "-" @search_paths = [] @argument_filters = {} = {} end |
Instance Attribute Details
#bin_name ⇒ Object
The name of the binary for this program; used to determine where to find sub-commands, help, etc.
14 15 16 |
# File 'lib/cli_forge/configuration.rb', line 14 def bin_name @bin_name end |
#bin_separator ⇒ Object
Separator to use when searching for subcommands.
23 24 25 |
# File 'lib/cli_forge/configuration.rb', line 23 def bin_separator @bin_separator end |
#default_command ⇒ Object
If no command is given, fall back to this.
17 18 19 |
# File 'lib/cli_forge/configuration.rb', line 17 def default_command @default_command end |
#embedded_commands ⇒ Object (readonly)
The set of embedded commands. Prefer using ‘register_command` and `remove_command`.
64 65 66 |
# File 'lib/cli_forge/configuration.rb', line 64 def end |
#search_paths ⇒ Object
Paths to search for sub command binaries.
20 21 22 |
# File 'lib/cli_forge/configuration.rb', line 20 def search_paths @search_paths end |
Instance Method Details
#argument_filters ⇒ Object
The active argument filters.
42 43 44 |
# File 'lib/cli_forge/configuration.rb', line 42 def argument_filters @argument_filters.values end |
#register_argument_filter(name, &block) ⇒ Object
Argument Filters
Argument filters are named procs that are given the current command’s arguments and have the opportunity to modify them.
The return value of the proc is used as the new argument set.
32 33 34 |
# File 'lib/cli_forge/configuration.rb', line 32 def register_argument_filter(name, &block) @argument_filters[name.to_sym] = block end |
#register_command(name, command_object) ⇒ Object
Embedded Sub Commands
In addition to exposing sub commands via external bins, you can register specific commands directly:
51 52 53 |
# File 'lib/cli_forge/configuration.rb', line 51 def register_command(name, command_object) [name.to_sym] = command_object end |
#remove_argument_filter(name) ⇒ Object
Remove a previously registered argument filter.
37 38 39 |
# File 'lib/cli_forge/configuration.rb', line 37 def remove_argument_filter(name) @argument_filters.delete(name.to_sym) end |
#remove_command(name) ⇒ Object
Remove a previosuly registered command.
This _does not_ block an external bin by the same name from being run!
58 59 60 |
# File 'lib/cli_forge/configuration.rb', line 58 def remove_command(name) .delete(name.to_sym) end |