Sha256: f11b20cdc1a665da689017c79d751f347a7bf45fb4d1b2b8d5a607c3deab8721

Contents?: true

Size: 943 Bytes

Versions: 4

Compression:

Stored size: 943 Bytes

Contents

require 'optparse'
require 'keystorage/commands'

module Keystorage
  class CLI
    def initialize(argv)
      @options = Hash.new
      @options[:file] = ENV["HOME"]+"/.keystore"
      @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
    
    def usage
      puts @opt;
      puts "Commands:"
      @commands = ["list","set","get","help"]
      @commands.each do |m|
        puts "    "+m
      end
    end

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
keystorage-0.3.0 lib/keystorage/cli.rb
keystorage-0.2.0 lib/keystorage/cli.rb
keystorage-0.1.1 lib/keystorage/cli.rb
keystorage-0.1.0 lib/keystorage/cli.rb