Class: Keystorage::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/keystorage/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/keystorage/cli.rb', line 7

def initialize(argv)
  @options = Hash.new
  @options[:file] = DEFAULT_FILE
  @argv = argv.clone
  @opt = OptionParser.new
  @opt.banner="Usage: keystorage [options] command [command options] args..."
  @opt.on('--help', 'show this message') { usage; exit }
  @opt.on('-f FILE','--file=FILE', 'file to store password') { |v|
    @options[:file] = v;
  }
end

Class Method Details

.run(argv) ⇒ Object



38
39
40
# File 'lib/keystorage/cli.rb', line 38

def run(argv)
  self.new(argv).execute
end

Instance Method Details

#executeObject



28
29
30
31
32
33
34
35
# File 'lib/keystorage/cli.rb', line 28

def execute
  argv = @opt.parse(@argv)
  command = argv.shift
  unless command
    usage;exit
  end
  Commands.send(command,argv,@options) 
end

#usageObject



19
20
21
22
23
24
25
26
# File 'lib/keystorage/cli.rb', line 19

def usage
  puts @opt;
  puts "Commands:"
  @commands = ["list","set","get","help"]
  @commands.each do |m|
    puts "    "+m
  end
end