Class: GemOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose_ticketing/utilities/gem_options.rb

Class Method Summary collapse

Class Method Details

.create_parserObject



7
8
9
10
# File 'lib/nexpose_ticketing/utilities/gem_options.rb', line 7

def self.create_parser
  @parser = OptionParser.new
  self
end

.parseObject

Parses the options to make them available



88
89
90
# File 'lib/nexpose_ticketing/utilities/gem_options.rb', line 88

def self.parse
  @parser.parse!
end

.with_banner(gem_usage_string) ⇒ Object

How the gem is used e.g ‘nexpose ticketing jira [options]’



13
14
15
16
17
# File 'lib/nexpose_ticketing/utilities/gem_options.rb', line 13

def self.with_banner(gem_usage_string)
  @parser.banner = "Usage: #{gem_usage_string} [options]"
  @parser.separator ''
  self
end

.with_banner_and_options(gem_usage_string) ⇒ Object

Creates banner and options



26
27
28
29
30
# File 'lib/nexpose_ticketing/utilities/gem_options.rb', line 26

def self.with_banner_and_options(gem_usage_string)
  with_banner(gem_usage_string)
  with_options
  self
end

.with_configuration_encryption(config_paths, enc_path = nil) ⇒ Object

For setting encryption switch. Can be set to work with two configurations Config_paths is an array



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nexpose_ticketing/utilities/gem_options.rb', line 34

def self.with_configuration_encryption(config_paths, enc_path = nil)
  @parser.on('-e',
          '--encrypt_config',
          'Encrypt the configuration file(s) without running the gem') do |e|
    ConfigParser.get_config(config_paths.first, enc_path) unless enc_path.nil?
    ConfigParser.get_config(config_paths.last)
    puts "\nConfiguration File(s) Encrypted"
    exit
  end
  self
end

.with_helpObject



46
47
48
49
50
51
52
# File 'lib/nexpose_ticketing/utilities/gem_options.rb', line 46

def self.with_help
  @parser.on_tail('-h', '--help', 'Show this message') do |h|
    puts @parser
    exit
  end
  self
end

.with_help_and_version(gem, version) ⇒ Object



62
63
64
65
66
# File 'lib/nexpose_ticketing/utilities/gem_options.rb', line 62

def self.with_help_and_version(gem, version)
  with_help
  with_version(gem, version)
  self
end

.with_optionsObject

Header for options list



20
21
22
23
# File 'lib/nexpose_ticketing/utilities/gem_options.rb', line 20

def self.with_options
  @parser.separator 'Options:'
  self
end

.with_other_option(short_switch, long_switch, description, &handler) ⇒ Object

Method to allow integrations to create own options, with both short and long switches and description. Handler is the block to run when option is called.



71
72
73
74
75
# File 'lib/nexpose_ticketing/utilities/gem_options.rb', line 71

def self.with_other_option(short_switch, long_switch, description, &handler)
  @parser.on("-#{short_switch}", "--#{long_switch}", description) do |opt|
    handler.call
  end
end

.with_single_switch_option(identifier, switch, description, &handler) ⇒ Object

Method to allow integrations to create own options, with only one size of switch and description. ‘-’ for short switches and ‘–’ for long switches is required. Handler is the block to run when option is called.



81
82
83
84
85
# File 'lib/nexpose_ticketing/utilities/gem_options.rb', line 81

def self.with_single_switch_option(identifier, switch, description, &handler)
  @parser.on("#{identifier}#{switch}", description) do |opt|
    handler.call
  end
end

.with_version(gem, version) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/nexpose_ticketing/utilities/gem_options.rb', line 54

def self.with_version(gem, version)
  @parser.on_tail('--version', 'Version Information') do |v|
    puts "#{gem} #{version}"
    exit
  end
  self
end