Class: Minfra::Cli::CliStarter
- Inherits:
-
Object
- Object
- Minfra::Cli::CliStarter
- Defined in:
- lib/minfra/cli/cli_starter.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#env_name ⇒ Object
readonly
Returns the value of attribute env_name.
-
#envs ⇒ Object
readonly
Returns the value of attribute envs.
-
#hiera ⇒ Object
readonly
Returns the value of attribute hiera.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
-
#initialize(argv) ⇒ CliStarter
constructor
A new instance of CliStarter.
- #install ⇒ Object
- #minfrarc_loaded? ⇒ Boolean
- #minfrarc_me_loaded? ⇒ Boolean
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ CliStarter
Returns a new instance of CliStarter.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/minfra/cli/cli_starter.rb', line 16 def initialize(argv) @argv = argv @options = {} # base_path, env, argv_file @minfrarc_loaded = false @minfrarc_me_loaded = false @base_path = Pathname.new(@options[:base_path] || ENV.fetch('MINFRA_PATH', nil)). @env_name = @options[:env] || ENV['MINFRA_ENVIRONMENT'] || 'dev' init_config init_logger @logger.debug("Minfra: loglevel: #{@logger.level}, env: #{@config.orch_env}, options: #{@options.inspect}") init_minfrarc unless @options[:norc] init_envs init_hiera init_plugins register_subcommands @plugins.setup require_relative 'main_command' setup_subcommands end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
6 7 8 |
# File 'lib/minfra/cli/cli_starter.rb', line 6 def argv @argv end |
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
6 7 8 |
# File 'lib/minfra/cli/cli_starter.rb', line 6 def base_path @base_path end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/minfra/cli/cli_starter.rb', line 6 def config @config end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/minfra/cli/cli_starter.rb', line 6 def env @env end |
#env_name ⇒ Object (readonly)
Returns the value of attribute env_name.
6 7 8 |
# File 'lib/minfra/cli/cli_starter.rb', line 6 def env_name @env_name end |
#envs ⇒ Object (readonly)
Returns the value of attribute envs.
6 7 8 |
# File 'lib/minfra/cli/cli_starter.rb', line 6 def envs @envs end |
#hiera ⇒ Object (readonly)
Returns the value of attribute hiera.
6 7 8 |
# File 'lib/minfra/cli/cli_starter.rb', line 6 def hiera @hiera end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/minfra/cli/cli_starter.rb', line 6 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/minfra/cli/cli_starter.rb', line 6 def @options end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
6 7 8 |
# File 'lib/minfra/cli/cli_starter.rb', line 6 def plugins @plugins end |
Instance Method Details
#install ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/minfra/cli/cli_starter.rb', line 69 def install cli = self Kernel.define_method(:minfra_cli) do cli end Kernel.define_method(:l) do |key, default = nil| minfra_cli.hiera.l(key, default) end Kernel.define_method(:l!) do |key, default = nil| minfra_cli.hiera.l!(key, default) end end |
#minfrarc_loaded? ⇒ Boolean
8 9 10 |
# File 'lib/minfra/cli/cli_starter.rb', line 8 def minfrarc_loaded? @minfrarc_loaded end |
#minfrarc_me_loaded? ⇒ Boolean
12 13 14 |
# File 'lib/minfra/cli/cli_starter.rb', line 12 def minfrarc_me_loaded? @minfrarc_me_loaded end |
#run ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/minfra/cli/cli_starter.rb', line 46 def run exit_code = 0 if @options[:argv_file] CSV.foreach(@options[:argv_file]) do |row| args = @argv + row @logger.debug("Running (#{env_name}): #{args.join(' ')} ") begin Minfra::Cli::Main.start(args) rescue StandardError # esp. Minfra::Cli::Errors::ExitError ! exit_code = 1 end end @logger.debug('Done argv_file loop') else begin Minfra::Cli::Main.start(@argv) rescue Minfra::Cli::Errors::ExitError exit_code = 1 end end exit_code end |