Class: Clandestine::CommandLineOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/clandestine/command_line_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandLineOptions

Returns a new instance of CommandLineOptions.



8
9
10
11
# File 'lib/clandestine/command_line_options.rb', line 8

def initialize
  @options = {}
  @parser = OptionParser.new
end

Instance Attribute Details

#options=(value) ⇒ Object

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



5
6
7
# File 'lib/clandestine/command_line_options.rb', line 5

def options=(value)
  @options = value
end

#parserObject (readonly)

Returns the value of attribute parser.



4
5
6
# File 'lib/clandestine/command_line_options.rb', line 4

def parser
  @parser
end

Instance Method Details

#parseObject



13
14
15
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
45
46
47
48
49
50
# File 'lib/clandestine/command_line_options.rb', line 13

def parse
  parser.banner = "Clandestine v#{Clandestine::VERSION}\nUsage: clandestine [option] [key]\n\n"

  parser.on('-a', '--add <key>', 'Add password for <key>') do |key|
    options[:add] = key
  end

  parser.on('-g', '--get [key]', 'Get password for [key] (Returns all keys if key isn\'t given)') do |key|
    options[:get] = key
  end

  parser.on('-d', '--delete <key>', 'Delete <key> and related password') do |key|
    options[:delete] = key
  end

  parser.on('-u', '--update [key]', 'Update password for [key] (Updates password for safe if key isn\'t given)') do |key|
    options[:update] = key
  end

  parser.on '-l', '--location', 'Print location of safe (Default is ~/.cls if env variable CLANDESTINE_SAFE isn\'t set)' do
    options[:location] = nil
  end

  parser.on '-r', '--remove', 'Remove safe completely' do
    options[:remove] = nil
  end

  parser.on '-v', '--version', 'Print version number' do |h|
    options[:version] = nil
  end

  parser.on_tail '-h', '--help', 'Print these options' do |h|
    options[:help] = parser
  end

  parser.parse!
  options
end