Class: CICI::CLI
- Inherits:
-
Object
- Object
- CICI::CLI
- Defined in:
- lib/cici/cli.rb
Instance Method Summary collapse
- #decrypt ⇒ Object
- #encrypt ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #parse_options ⇒ Object
- #print_help(exit_code) ⇒ Object
- #run_command ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cici/cli.rb', line 18 def initialize @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 |
Instance Method Details
#decrypt ⇒ Object
91 92 93 |
# File 'lib/cici/cli.rb', line 91 def decrypt @decrypter.start(@options.set) end |
#encrypt ⇒ Object
87 88 89 |
# File 'lib/cici/cli.rb', line 87 def encrypt @encrypter.start end |
#parse_options ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cici/cli.rb', line 50 def = Options.new .verbose = false .debug = false opt_parser = OptionParser.new do |opts| opts. = 'Usage: cici encrypt|decrypt [options]' opts.on('-v', '--version', 'Print version') do puts CICI::Version.get exit end opts.on('--verbose', 'Verbose output') do .verbose = true end opts.on('--debug', 'Debug output (also turns on verbose)') do .verbose = true .debug = true end opts.on('--set SET_NAME', 'Set to decrypt (Note: option ignored for encrypt command)') do |set_name| .set = set_name end opts.on('-h', '--help', 'Prints this help') do puts opts exit end end help = opt_parser.help .help = help abort(help) if ARGV.empty? opt_parser.parse!(ARGV) end |
#print_help(exit_code) ⇒ Object
45 46 47 48 |
# File 'lib/cici/cli.rb', line 45 def print_help(exit_code) puts @options.help exit exit_code end |
#run_command ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# 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 |