Class: Brick::CLI::SubcommandLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/brick/cli/core/subcommand_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#envObject (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_dirglobObject



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.expand_path('../../../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_commandsObject

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_filesObject



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