Class: Bitsa::ArgsProcessor
- Inherits:
-
Object
- Object
- Bitsa::ArgsProcessor
- Defined in:
- lib/bitsa/args_processor.rb
Overview
Arguments passed on the command line. Trollop trollop.rubyforge.org is used to handle the parsing.
Constant Summary collapse
- SUB_COMMANDS =
Valid commands.
%w(update reload search skel)
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
The command to execute.
-
#global_opts ⇒ Object
readonly
Global options passed on the command line.
-
#search_data ⇒ Object
readonly
Data to search cached contacts for.
Instance Method Summary collapse
-
#parse(args) ⇒ Object
Parse arguments and setup attributes.
Instance Attribute Details
#cmd ⇒ Object (readonly)
The command to execute
36 37 38 |
# File 'lib/bitsa/args_processor.rb', line 36 def cmd @cmd end |
#global_opts ⇒ Object (readonly)
Global options passed on the command line.
33 34 35 |
# File 'lib/bitsa/args_processor.rb', line 33 def global_opts @global_opts end |
#search_data ⇒ Object (readonly)
Data to search cached contacts for.
39 40 41 |
# File 'lib/bitsa/args_processor.rb', line 39 def search_data @search_data end |
Instance Method Details
#parse(args) ⇒ Object
Parse arguments and setup attributes. If invalid data is passed a Trollop exception is thrown and the program terminated.
It also handles showing the Help and Version information.
45 46 47 48 49 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 |
# File 'lib/bitsa/args_processor.rb', line 45 def parse(args) @global_opts = Trollop::(args) do version "bitsa v#{Bitsa::VERSION}" "Usage: bitsa [global-options] [subcommand] [command-opts]\n\nGlobal options are:\n" opt :config_file, "Configuration file", type: String, default: "~/.bitsa_config.yml" opt :auto_check, "Autocheck interval in days. 0 to disable (default: 1)", type: Integer opt :login, "Login", :type => String opt :password, "Password", :type => String stop_on SUB_COMMANDS "\nbitsa subcommands\n update: get the latest changes from Gmail\n reload: Clear all cached addresses and reload from Gmail\n search: Search for the passed string\n skel: Write a skeleton configuration file to standard output\n\nInformation about this program\n" end @cmd = args.shift || '' @search_data = '' if cmd == "search" @search_data << args.shift unless args.empty? elsif !ArgsProcessor::SUB_COMMANDS.include?(cmd) Trollop::die "unknown subcommand '#{cmd}'" end end |