Class: Convoy::AutoOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/convoy/auto_options.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AutoOptions

Returns a new instance of AutoOptions.


34
35
36
# File 'lib/convoy/auto_options.rb', line 34

def initialize(options)
    @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options


32
33
34
# File 'lib/convoy/auto_options.rb', line 32

def options
  @options
end

Class Method Details

.augment(setup) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/convoy/auto_options.rb', line 4

def augment(setup)
    if setup.has_config_file?
        setup.add_global_option :config, "Configuration file to use for this execution", :short => :none, :long => '--config', :type => :string

        setup.add_global_command :convoy, :aliases => [] do |command|
            command.summary "Auto created utility command"
            command.description "Auto created utility command"
            command.requires_arguments false

            command.options do |opts|
                opts.opt :create_config, "Create configuration file at specified location", :short => :none, :long => '--create-config', :type => :string
                opts.opt :create_default_config, "Create a default configuration file", :short => :none, :long => '--create-default-config', :type => :boolean, :default => false
                opts.opt :update_config, "Update configuration file at specified location", :short => :none, :long => '--update-config', :type => :string
                opts.opt :update_default_config, "Update the default configuration file", :short => :none, :long => '--update-default-config', :type => :boolean, :default => false

                opts.conflict :create_config, :create_default_config, :update_config, :update_default_config
            end

            command.action do |options, arguments|
                ActionCommand::ConvoyUtilityCommand.new(setup, options, arguments).execute
            end
        end
    end
    setup.add_global_option :verbosity, 'Verbosity level of output for current execution (e.g. INFO, DEBUG)', :short => :none, :long => '--verbosity', :type => :string, :default => 'WARN'
    setup.add_global_option :error_output_format, 'The format to use when outputting errors (e.g. basic, advanced)', :short => :none, :long => '--error-output-format', :type => :string, :default => 'basic'
end

Instance Method Details

#error_formatterObject


53
54
55
# File 'lib/convoy/auto_options.rb', line 53

def error_formatter
    error_output_format.to_sym
end

#non_default_config_pathObject


38
39
40
41
42
43
44
45
46
47
# File 'lib/convoy/auto_options.rb', line 38

def non_default_config_path
    if options[:config_given] && File.exists?(config_path)
        config_path
    elsif !options[:config_given]
        nil
    else
        error_logger.warn "The given config file '#{options[:config]}' does not exist, falling back to default"
        nil
    end
end

#verbosityObject


49
50
51
# File 'lib/convoy/auto_options.rb', line 49

def verbosity
    error_verbosity.upcase
end