Class: HCl::App
Defined Under Namespace
Classes: UnknownCommand
Constant Summary collapse
- SETTINGS_FILE =
"#{ENV['HOME']}/.hcl_settings"
- CONFIG_FILE =
"#{ENV['HOME']}/.hcl_config"
Class Method Summary collapse
-
.command(*args) ⇒ Object
Run the given command and arguments.
Instance Method Summary collapse
-
#command?(command) ⇒ true, false
Return true if the string is a known command, false otherwise.
-
#initialize ⇒ App
constructor
A new instance of App.
- #process_args(*args) ⇒ Object
-
#run ⇒ Object
Start the application.
Methods included from Commands
#aliases, #note, #set, #show, #start, #stop, #tasks, #unset
Methods included from Utility
Constructor Details
#initialize ⇒ App
Returns a new instance of App.
44 45 46 47 |
# File 'lib/hcl/app.rb', line 44 def initialize read_config read_settings end |
Class Method Details
.command(*args) ⇒ Object
Run the given command and arguments.
50 51 52 |
# File 'lib/hcl/app.rb', line 50 def self.command *args hcl = new.process_args(*args).run end |
Instance Method Details
#command?(command) ⇒ true, false
Return true if the string is a known command, false otherwise.
58 59 60 |
# File 'lib/hcl/app.rb', line 58 def command? command Commands.instance_methods.include? command.to_s end |
#process_args(*args) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/hcl/app.rb', line 87 def process_args *args Trollop::(args) do stop_on Commands.instance_methods version "HCl version #{VERSION}" <<-EOM HCl is a command-line client for manipulating Harvest time sheets. Commands: hcl show [date] hcl tasks hcl aliases hcl set <key> <value ...> hcl unset <key> hcl start <task> [msg] hcl stop [msg] hcl note <msg> Examples: $ hcl tasks $ hcl start 1234 4567 this is my log message $ hcl set task.mytask 1234 4567 $ hcl start mytask this is my next log message $ hcl show yesterday $ hcl show last tuesday Options: EOM end @command = args.shift @args = args self end |
#run ⇒ Object
Start the application.
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/hcl/app.rb', line 63 def run begin if @command if command? @command result = send @command, *@args if not result.nil? if result.respond_to? :to_a puts result.to_a.join(', ') elsif result.respond_to? :to_s puts result end end else raise UnknownCommand, "unrecognized command `#{@command}'" end else show end rescue TimesheetResource::Failure => e puts "Internal failure. #{e}" exit 1 end end |