Class: CLIForge::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cli_forge/configuration.rb

Direct Known Subclasses

DefaultConfiguration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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  = {}
  @embedded_commands = {}
end

Instance Attribute Details

#bin_nameObject

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_separatorObject

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_commandObject

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_commandsObject (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 embedded_commands
  @embedded_commands
end

#search_pathsObject

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_filtersObject

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)
  @embedded_commands[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)
  @embedded_commands.delete(name.to_sym)
end