Class: Brick::CLI::SubcommandLoader
- Inherits:
-
Object
- Object
- Brick::CLI::SubcommandLoader
- Defined in:
- lib/brick/cli/core/subcommand_loader.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #find_subcommands_via_dirglob ⇒ Object
-
#initialize(env = ENV) ⇒ SubcommandLoader
constructor
A new instance of SubcommandLoader.
-
#load_commands ⇒ Object
Load all the sub-commands.
- #subcommand_files ⇒ Object
Constructor Details
#initialize(env = ENV) ⇒ SubcommandLoader
Returns a new instance of SubcommandLoader.
9 10 11 |
# File 'lib/brick/cli/core/subcommand_loader.rb', line 9 def initialize( env=ENV) @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/brick/cli/core/subcommand_loader.rb', line 7 def env @env end |
Instance Method Details
#find_subcommands_via_dirglob ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/brick/cli/core/subcommand_loader.rb', line 25 def find_subcommands_via_dirglob # The "require paths" of the core knife subcommands bundled with chef files = Dir[File.('../../../cli/*.rb', __FILE__)] subcommand_files = {} files.each do |cli_file| rel_path = cli_file[/#{::Brick::BRICK_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/,1] subcommand_files[rel_path] = cli_file end subcommand_files end |
#load_commands ⇒ Object
Load all the sub-commands
14 15 16 17 |
# File 'lib/brick/cli/core/subcommand_loader.rb', line 14 def load_commands subcommand_files.each { |subcommand| Kernel.load subcommand } true end |
#subcommand_files ⇒ Object
21 22 23 |
# File 'lib/brick/cli/core/subcommand_loader.rb', line 21 def subcommand_files @subcommand_files ||= (find_subcommands_via_dirglob.values).flatten.uniq end |