Class: HCl::App
Constant Summary collapse
- HCL_DIR =
(ENV['HCL_DIR'] || "#{ENV['HOME']}/.hcl").freeze
- SETTINGS_FILE =
"#{HCL_DIR}/settings.yml".freeze
- ALIAS_LIST =
"#{HCL_DIR}/aliases".freeze
- CONFIG_FILE =
"#{HCL_DIR}/config.yml".freeze
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
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
#alias, #aliases, #cancel, #completion, #config, #console, deprecate, #log, #note, #resume, #set, #show, #start, #status, #stop, #tasks, #toggle, #unalias, #unset
Methods included from Utility
#as_hours, #current_time, #fail, #get_ident, #get_starting_time, #get_task, #get_task_ids, #time2float
Constructor Details
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
17 18 19 |
# File 'lib/hcl/app.rb', line 17 def http @http end |
Class Method Details
.command(*args) ⇒ Object
Run the given command and arguments.
27 28 29 |
# File 'lib/hcl/app.rb', line 27 def self.command *args new.process_args(*args).run end |
Instance Method Details
#command?(command) ⇒ true, false
Return true if the string is a known command, false otherwise.
35 36 37 |
# File 'lib/hcl/app.rb', line 35 def command? command Commands.method_defined? command end |
#process_args(*args) ⇒ Object
86 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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/hcl/app.rb', line 86 def process_args *args @options = 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: # show all available tasks hcl tasks # create a task alias hcl alias <task_alias> <project_id> <task_id> # remove a task alias hcl unalias <task_alias> # list task aliases hcl aliases # start a task using an alias hcl [start] @<task_alias> [+<time>] [<message>] # add a line to a running timer hcl note <message> # stop a running timer hcl stop [<message>] # log a task and time without leaving a timer running hcl log @<task_alias> [+<time>] [<message>] # toggle the current or last running timer, or a specific task hcl toggle [@<task_alias>] # delete the current or last running timer hcl (cancel | oops | nvm) # display the daily timesheet hcl [show [<date>]] # show your current credentials hcl config # display Harvest service status hcl status Examples: hcl alias mytask 1234 4567 hcl @mytask +:15 Doing a thing that I started 15 minutes ago. hcl note Adding a note to my running task. hcl stop That's enough for now. hcl toggle hcl show yesterday hcl show last tuesday Options: EOM opt :reauth, "Force refresh of auth details" opt :changelog, "Review the HCl changelog" end @command = args.shift @args = args self end |
#run ⇒ Object
Start the application.
40 41 42 43 44 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 83 84 |
# File 'lib/hcl/app.rb', line 40 def run request_config if @options[:reauth] if @options[:changelog] system %[ more "#{File.join(File.dirname(__FILE__), '../../CHANGELOG.markdown')}" ] exit end begin if @command if command? @command result = send @command, *@args if not result.nil? if result.respond_to? :join, include_all=false puts result.join(', ') elsif result.respond_to? :to_s, include_all=false puts result end end else puts start(@command, *@args) end else puts show end rescue CommandError => e $stderr.puts e exit 1 rescue RuntimeError => e $stderr.puts "Error: #{e}" exit 1 rescue Faraday::Error => e $stderr.puts "Connection failed. (#{e.})" exit 1 rescue HarvestMiddleware::ThrottleFailure => e $stderr.puts "Too many requests, retrying in #{e.retry_after+5} seconds..." sleep e.retry_after+5 run rescue HarvestMiddleware::AuthFailure => e $stderr.puts "Unable to authenticate: #{e}" request_config run rescue HarvestMiddleware::Failure => e $stderr.puts "API failure: #{e}" exit 1 end end |