class CICI::CLI

Public Class Methods

new() click to toggle source
# File lib/cici/cli.rb, line 18
def initialize
  @options = parse_options

  @ui = CICI::UI.new(@options.verbose, @options.debug)
  @ui.debug("Options: #{@options}")

  @config = CICI::Config.new(@ui)
  @config.load

  @decrypter = CICI::Decrypt.new(@ui, @config)
  @encrypter = CICI::Encrypt.new(@ui, @decrypter, @config)

  run_command
end

Public Instance Methods

decrypt() click to toggle source
# File lib/cici/cli.rb, line 91
def decrypt
  @decrypter.start(@options.set)
end
encrypt() click to toggle source
# File lib/cici/cli.rb, line 87
def encrypt
  @encrypter.start
end
parse_options() click to toggle source
# File lib/cici/cli.rb, line 50
def parse_options
  options = Options.new
  options.verbose = false
  options.debug = false

  opt_parser = OptionParser.new do |opts|
    opts.banner = 'Usage: cici encrypt|decrypt [options]'

    opts.on('-v', '--version', 'Print version') do
      puts CICI::Version.get
      exit
    end
    opts.on('--verbose', 'Verbose output') do
      options.verbose = true
    end
    opts.on('--debug', 'Debug output (also turns on verbose)') do
      options.verbose = true
      options.debug = true
    end
    opts.on('--set SET_NAME', 'Set to decrypt (Note: option ignored for encrypt command)') do |set_name|
      options.set = set_name
    end
    opts.on('-h', '--help', 'Prints this help') do
      puts opts
      exit
    end
  end

  help = opt_parser.help
  options.help = help
  abort(help) if ARGV.empty?

  opt_parser.parse!(ARGV)

  options
end
print_help(exit_code) click to toggle source
run_command() click to toggle source
# File lib/cici/cli.rb, line 33
def run_command
  case ARGV[0]
  when 'encrypt'
    encrypt
  when 'decrypt'
    decrypt
  else
    @ui.fail('Command invalid.')
    print_help(1)
  end
end