Class: Clandestine::CommandLineOptions
- Inherits:
-
Object
- Object
- Clandestine::CommandLineOptions
- Defined in:
- lib/clandestine/command_line_options.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
writeonly
Sets the attribute options.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
-
#initialize ⇒ CommandLineOptions
constructor
A new instance of CommandLineOptions.
- #parse ⇒ Object
Constructor Details
#initialize ⇒ CommandLineOptions
Returns a new instance of CommandLineOptions.
8 9 10 11 |
# File 'lib/clandestine/command_line_options.rb', line 8 def initialize = {} @parser = OptionParser.new end |
Instance Attribute Details
#options=(value) ⇒ Object
Sets the attribute options
5 6 7 |
# File 'lib/clandestine/command_line_options.rb', line 5 def (value) = value end |
#parser ⇒ Object (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
#parse ⇒ Object
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. = "Clandestine v#{Clandestine::VERSION}\nUsage: clandestine [option] [key]\n\n" parser.on('-a', '--add <key>', 'Add password for <key>') do |key| [:add] = key end parser.on('-g', '--get [key]', 'Get password for [key] (Returns all keys if key isn\'t given)') do |key| [:get] = key end parser.on('-d', '--delete <key>', 'Delete <key> and related password') do |key| [:delete] = key end parser.on('-u', '--update [key]', 'Update password for [key] (Updates password for safe if key isn\'t given)') do |key| [:update] = key end parser.on '-l', '--location', 'Print location of safe (Default is ~/.cls if env variable CLANDESTINE_SAFE isn\'t set)' do [:location] = nil end parser.on '-r', '--remove', 'Remove safe completely' do [:remove] = nil end parser.on '-v', '--version', 'Print version number' do |h| [:version] = nil end parser.on_tail '-h', '--help', 'Print these options' do |h| [:help] = parser end parser.parse! end |