clockout 0.4.2 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/clock +44 -9
- data/lib/clockout.rb +8 -2
- data/lib/printer.rb +1 -0
- metadata +2 -2
data/bin/clock
CHANGED
@@ -10,13 +10,16 @@ See hours:
|
|
10
10
|
Options:
|
11
11
|
--estimations, -e: Show estimations made, if any
|
12
12
|
--condensed, -c: Condense output (don't show the timeline for each day)
|
13
|
-
--generate-config, -g: Generate config file (clock.yml)
|
14
13
|
--user, -u (<email>): Only count current user's commits (or specified user)
|
15
14
|
--help, -h: Show this message
|
16
15
|
|
16
|
+
Generators:
|
17
|
+
$ clock generate config Generate config file (clock.yml)
|
18
|
+
$ clock generate hook Generate a post-commit hook for clockout!
|
19
|
+
|
17
20
|
Other:
|
18
|
-
$ clock in
|
19
|
-
$ clock out
|
21
|
+
$ clock in Clock-in (when you start working, preceding a commit)
|
22
|
+
$ clock out Clock-out (after you've worked overtime following a commit)
|
20
23
|
EOS
|
21
24
|
|
22
25
|
TEMPLATE_CLOCKFILE = <<-EOF
|
@@ -81,16 +84,22 @@ def parse_options(args)
|
|
81
84
|
i = 0
|
82
85
|
while i < args.length
|
83
86
|
arg = args[i]
|
87
|
+
next_arg = args[i+1]
|
84
88
|
if (arg == "-h" || arg == "--help")
|
85
89
|
opts[:help] = true
|
86
90
|
elsif (arg == "-e" || arg == "--estimations")
|
87
91
|
opts[:estimations] = true
|
88
92
|
elsif (arg == "-c" || arg == "--condensed")
|
89
93
|
opts[:condensed] = true
|
90
|
-
elsif (arg == "
|
91
|
-
|
94
|
+
elsif (arg == "generate")
|
95
|
+
if next_arg == "hook" || next_arg == "config"
|
96
|
+
i += 1
|
97
|
+
opts[:generate] = next_arg
|
98
|
+
else
|
99
|
+
puts_error "invalid generator '#{next_arg}' (there's only 'config' and 'hook', see --help)."
|
100
|
+
exit
|
101
|
+
end
|
92
102
|
elsif (arg == "-u" || arg == "--user")
|
93
|
-
next_arg = args[i+1]
|
94
103
|
if next_arg && next_arg[0] != '-'
|
95
104
|
opts[:user] = next_arg
|
96
105
|
i += 1
|
@@ -152,6 +161,10 @@ if (ARGV[0] == "in" || ARGV[0] == "out")
|
|
152
161
|
# Add in: or out:, along with the time if it doesn't exist
|
153
162
|
file << "\n#{seek_line}\n#{time_line}" if !mod
|
154
163
|
end
|
164
|
+
elsif (ARGV[0] == "last")
|
165
|
+
print "[clockout] ".green if (ARGV[1] == "--hook")
|
166
|
+
clock = Clockout.new(path, nil, 2)
|
167
|
+
clock.print_last
|
155
168
|
else
|
156
169
|
opts = parse_options(ARGV)
|
157
170
|
|
@@ -160,9 +173,31 @@ else
|
|
160
173
|
exit
|
161
174
|
end
|
162
175
|
|
163
|
-
if opts[:
|
164
|
-
|
165
|
-
|
176
|
+
if opts[:generate]
|
177
|
+
root = Clockout.root_path(path)
|
178
|
+
exit if !root
|
179
|
+
if opts[:generate] == "config"
|
180
|
+
if !generate_clock_file(path) && clock_path
|
181
|
+
puts_error "config file already exists for this repo: #{clock_path}"
|
182
|
+
end
|
183
|
+
elsif opts[:generate] == "hook"
|
184
|
+
hook_path = root+"/.git/hooks/post-commit"
|
185
|
+
hook_txt = "#clockout\nclock last --hook"
|
186
|
+
if File.exist? hook_path
|
187
|
+
contents = File.open(hook_path).read
|
188
|
+
if (contents[hook_txt])
|
189
|
+
puts_error "post-commit clock hook already added"
|
190
|
+
else
|
191
|
+
File.open(hook_path, "a") do |file|
|
192
|
+
file.puts "\n\n#{hook_txt}"
|
193
|
+
end
|
194
|
+
end
|
195
|
+
else
|
196
|
+
File.open(hook_path, "w") do |file|
|
197
|
+
file.puts "#!/bin/sh\n\n#{hook_txt}"
|
198
|
+
end
|
199
|
+
File.chmod(0755, hook_path)
|
200
|
+
end
|
166
201
|
end
|
167
202
|
exit
|
168
203
|
end
|
data/lib/clockout.rb
CHANGED
@@ -171,6 +171,11 @@ class Clockout
|
|
171
171
|
@blocks = run(data)
|
172
172
|
end
|
173
173
|
|
174
|
+
def print_last
|
175
|
+
last = @blocks.last.last
|
176
|
+
puts "#{last.minutes.round(2)} minutes logged" if last
|
177
|
+
end
|
178
|
+
|
174
179
|
def self.get_repo(path, original_path = nil)
|
175
180
|
begin
|
176
181
|
return Grit::Repo.new(path), path
|
@@ -211,6 +216,7 @@ class Clockout
|
|
211
216
|
end
|
212
217
|
|
213
218
|
def self.clock_path(path)
|
219
|
+
return nil if !path
|
214
220
|
path+"/clock.yml"
|
215
221
|
end
|
216
222
|
|
@@ -219,7 +225,7 @@ class Clockout
|
|
219
225
|
root_path
|
220
226
|
end
|
221
227
|
|
222
|
-
def initialize(path = nil, author = nil)
|
228
|
+
def initialize(path = nil, author = nil, num=500)
|
223
229
|
@time_per_day = Hash.new(0)
|
224
230
|
|
225
231
|
# Default options
|
@@ -234,7 +240,7 @@ class Clockout
|
|
234
240
|
# Merge with config override options
|
235
241
|
$opts.merge!(clock_opts) if clock_opts
|
236
242
|
|
237
|
-
commits = repo.commits('master',
|
243
|
+
commits = repo.commits('master', num)
|
238
244
|
commits.reverse!
|
239
245
|
|
240
246
|
prepare_blocks(commits, author)
|
data/lib/printer.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clockout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.5'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grit
|