Class: Escort::AutoOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/escort/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.



36
37
38
# File 'lib/escort/auto_options.rb', line 36

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

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
30
31
# File 'lib/escort/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 :escort, :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::EscortUtilityCommand.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"
  #TODO validations for the output format and the verbosity
end

Instance Method Details

#error_formatterObject



55
56
57
# File 'lib/escort/auto_options.rb', line 55

def error_formatter
  error_output_format.to_sym
end

#non_default_config_pathObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/escort/auto_options.rb', line 40

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



51
52
53
# File 'lib/escort/auto_options.rb', line 51

def verbosity
  error_verbosity.upcase
end