Sha256: 088b5ddced49d0d1ee9f322bddd60731fe737d2bb1cb9422c56ec5397f3e65a6

Contents?: true

Size: 847 Bytes

Versions: 8

Compression:

Stored size: 847 Bytes

Contents

module Runbook::CLIBase
  def self.included(base)
    base.extend(ClassMethods)

    base.check_unknown_options!

    base.class_option(
      :config,
      aliases: "-c",
      type: :string,
      group: :base,
      desc: "Path to runbook config file"
    )
  end

  def initialize(args = [], local_options = {}, config = {})
    super(args, local_options, config)

    cmd_name = config[:current_command].name
    _set_cli_config(options[:config], cmd_name) if options[:config]
  end

  module ClassMethods
    def exit_on_failure?
      true
    end
  end

  protected

  def _set_cli_config(config, cmd)
    unless File.exist?(config)
      raise Thor::InvocationError, "#{cmd}: cannot access #{config}: No such file or directory"
    end
    Runbook::Configuration.cli_config_file = config
    Runbook::Configuration.reconfigure
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
careacademy-runbook-1.2.0 lib/runbook/cli_base.rb
runbook-1.1.0 lib/runbook/cli_base.rb
runbook-1.0.0 lib/runbook/cli_base.rb
runbook-0.16.1 lib/runbook/cli_base.rb
runbook-0.16.0 lib/runbook/cli_base.rb
runbook-0.15.0 lib/runbook/cli_base.rb
runbook-0.14.0 lib/runbook/cli_base.rb
runbook-0.13.0 lib/runbook/cli_base.rb