Class: Searchpass::CLI
- Inherits:
-
Object
- Object
- Searchpass::CLI
- Defined in:
- lib/searchpass/cli.rb
Defined Under Namespace
Classes: CredentialsFileCorrupt, CredentialsFileError, CredentialsFileNotReadable, Error
Constant Summary collapse
- PROGRAM_NAME =
"searchpass".freeze
- CREDENTIALS_FILE =
File.join(File.dirname(__FILE__), "..", "..", "credentials.json")
- CREDENTIALS_SEPARATOR =
"========================================================"
Class Method Summary collapse
Class Method Details
.run!(args) ⇒ Object
12 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 51 52 53 54 |
# File 'lib/searchpass/cli.rb', line 12 def self.run!(args) @options = OpenStruct.new @options.case_sensitive = false @options.exact = false @opt_parser = OptionParser.new do |opts| opts. = "Usage: #{PROGRAM_NAME} [options] term [term2] ... [termN]" opts.program_name = PROGRAM_NAME opts.separator "" opts.separator "Specific options:" opts.on("-c", "--case", "Perform case sensitive matching") do |v| @options.case_sensitive = v end opts.on("-e", "--exact", "Perform exact matching") do |v| @options.exact = v end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end opts.on_tail("--version", "Show version") do puts Searchpass::VERSION exit end end @opt_parser.parse!(args) if args.empty? puts "No search terms given" puts "See -h or --help for usage" exit(1) end perform_search(args) rescue OptionParser::InvalidOption => e puts e. puts "See -h or --help for usage" exit(1) rescue => e puts "ERROR: #{e.}" exit(1) end |