samg-timetrap 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/lib/timetrap.rb +56 -50
- metadata +1 -1
data/README.md
CHANGED
@@ -50,7 +50,7 @@ The basic usage is as follows::
|
|
50
50
|
$ t out
|
51
51
|
|
52
52
|
The first command, ``t switch writing``, switches to the timesheet "writing"
|
53
|
-
(or creates it if it does not exist). ``t in document timetrap
|
53
|
+
(or creates it if it does not exist). ``t in document timetrap --at "10 minutes
|
54
54
|
ago"`` creates a new period in the current timesheet, and annotates it with the
|
55
55
|
description "document timetrap". The optional ``--at`` flag can be passed to start
|
56
56
|
the entry at a time other than the present. The ``--at`` flag is able to parse
|
data/lib/timetrap.rb
CHANGED
@@ -13,41 +13,72 @@ module Timetrap
|
|
13
13
|
attr_accessor :args
|
14
14
|
extend self
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
USAGE = <<-EOF
|
17
|
+
|
18
|
+
Timetrap - Simple Time Tracking
|
19
|
+
|
20
|
+
Usage: #{File.basename $0} COMMAND [OPTIONS] [ARGS...]
|
21
|
+
|
22
|
+
where COMMAND is one of:
|
23
|
+
* alter - alter the description of the active period
|
24
|
+
usage: t alter [--id ID] [--start TIME] [--end TIME] [NOTES]
|
25
|
+
-i, --id <id:i> Alter entry with id <id> instead of the running entry
|
26
|
+
-s, --start <time:qs> Change the start time to <time>
|
27
|
+
-e, --end <time:qs> Change the end time to <time>
|
28
|
+
* backend - open an the backend's interactive shell
|
29
|
+
usage: t backend
|
30
|
+
* display - display the current timesheet
|
31
|
+
usage: t display [--ids] [TIMESHEET]
|
32
|
+
-v, --ids Print database ids (for use with alter)
|
33
|
+
* format - export a sheet to csv format
|
34
|
+
NOT IMPLEMENTED
|
35
|
+
* in - start the timer for the current timesheet
|
36
|
+
usage: t in [--at TIME] [NOTES]
|
37
|
+
-a, --at <time:qs> Use this time instead of now
|
38
|
+
* kill - delete a timesheet
|
39
|
+
usage: t kill [--id ID] [TIMESHEET]
|
40
|
+
-i, --id <id:i> Alter entry with id <id> instead of the running entry
|
41
|
+
* list - show the available timesheets
|
42
|
+
usage: t list
|
43
|
+
* now - show the status of the current timesheet
|
44
|
+
usage: t now
|
45
|
+
* out - stop the timer for the current timesheet
|
46
|
+
usage: t out [--at TIME]
|
47
|
+
-a, --at <time:qs> Use this time instead of now
|
48
|
+
* running - show all running timesheets
|
49
|
+
NOT IMPLEMENTED
|
50
|
+
* switch - switch to a new timesheet
|
51
|
+
usage: t switch TIMESHEET
|
52
|
+
|
53
|
+
OTHER OPTIONS
|
54
|
+
-h, --help Display this help
|
55
|
+
EOF
|
29
56
|
|
30
57
|
def parse arguments
|
31
58
|
args.parse arguments
|
32
59
|
end
|
33
60
|
|
34
61
|
def invoke
|
35
|
-
invoke_command_if_valid
|
62
|
+
args['-h'] ? say(USAGE) : invoke_command_if_valid
|
63
|
+
end
|
64
|
+
|
65
|
+
def commands
|
66
|
+
Timetrap::CLI::USAGE.scan(/\* \w+/).map{|s| s.gsub(/\* /, '')}
|
36
67
|
end
|
37
68
|
|
38
69
|
def invoke_command_if_valid
|
39
70
|
command = args.unused.shift
|
40
|
-
case (valid =
|
71
|
+
case (valid = commands.select{|name| name =~ %r|^#{command}|}).size
|
41
72
|
when 0 then say "Invalid command: #{command}"
|
42
73
|
when 1 then send valid[0]
|
43
74
|
else; say "Ambigous command: #{command}"; end
|
44
75
|
end
|
45
76
|
|
46
77
|
def alter
|
47
|
-
entry = args['
|
78
|
+
entry = args['-i'] ? Entry[args['-i']] : Timetrap.active_entry
|
48
79
|
say "can't find entry" && return unless entry
|
49
|
-
entry.update :start => args['
|
50
|
-
entry.update :end => args['
|
80
|
+
entry.update :start => args['-s'] if args['-s'] =~ /.+/
|
81
|
+
entry.update :end => args['-e'] if args['-e'] =~ /.+/
|
51
82
|
entry.update :note => unused_args if unused_args =~ /.+/
|
52
83
|
end
|
53
84
|
|
@@ -56,15 +87,15 @@ module Timetrap
|
|
56
87
|
end
|
57
88
|
|
58
89
|
def in
|
59
|
-
Timetrap.start unused_args, args['
|
90
|
+
Timetrap.start unused_args, args['-a']
|
60
91
|
end
|
61
92
|
|
62
93
|
def out
|
63
|
-
Timetrap.stop args['
|
94
|
+
Timetrap.stop args['-a']
|
64
95
|
end
|
65
96
|
|
66
97
|
def kill
|
67
|
-
if e = Entry[args['
|
98
|
+
if e = Entry[args['-i']]
|
68
99
|
out = "are you sure you want to delete entry #{e.id}? "
|
69
100
|
out << "(#{e.note}) " if e.note.to_s =~ /.+/
|
70
101
|
print out
|
@@ -84,7 +115,7 @@ module Timetrap
|
|
84
115
|
say "will not kill"
|
85
116
|
end
|
86
117
|
else
|
87
|
-
victim = args['
|
118
|
+
victim = args['-i'] ? args['-i'].to_s.inspect : sheet.inspect
|
88
119
|
say "can't find #{victim} to kill", 'sheets:', *sheets
|
89
120
|
end
|
90
121
|
end
|
@@ -93,7 +124,7 @@ module Timetrap
|
|
93
124
|
sheet = sheet_name_from_string(unused_args)
|
94
125
|
sheet = (sheet =~ /.+/ ? sheet : Timetrap.current_sheet)
|
95
126
|
say "Timesheet: #{sheet}"
|
96
|
-
id_heading = args['
|
127
|
+
id_heading = args['-v'] ? 'Id' : ' '
|
97
128
|
say "#{id_heading} Day Start End Duration Notes"
|
98
129
|
last_start = nil
|
99
130
|
from_current_day = []
|
@@ -103,7 +134,7 @@ module Timetrap
|
|
103
134
|
from_current_day << e
|
104
135
|
e_end = e.end || Time.now
|
105
136
|
say "%-4s%16s%11s -%9s%10s %s" % [
|
106
|
-
(args['
|
137
|
+
(args['-v'] ? e.id : ''),
|
107
138
|
format_date_if_new(e.start, last_start),
|
108
139
|
format_time(e.start),
|
109
140
|
format_time(e.end),
|
@@ -315,31 +346,6 @@ module Timetrap
|
|
315
346
|
create_table unless table_exists?
|
316
347
|
end
|
317
348
|
CLI.args = Getopt::Declare.new(<<-EOF)
|
318
|
-
|
319
|
-
|
320
|
-
where COMMAND is one of:
|
321
|
-
alter - alter the description of the active period
|
322
|
-
backend - open an the backend's interactive shell
|
323
|
-
display - display the current timesheet
|
324
|
-
format - export a sheet to csv format
|
325
|
-
in - start the timer for the current timesheet
|
326
|
-
kill - delete a timesheet
|
327
|
-
list - show the available timesheets
|
328
|
-
now - show the status of the current timesheet
|
329
|
-
out - stop the timer for the current timesheet
|
330
|
-
running - show all running timesheets
|
331
|
-
switch - switch to a new timesheet
|
332
|
-
|
333
|
-
COMMAND OPTIONS
|
334
|
-
options for `display'
|
335
|
-
--ids Print database ids (for use with alter)
|
336
|
-
|
337
|
-
options for `in' and `out'
|
338
|
-
--at <time:qs> Use this time instead of now
|
339
|
-
|
340
|
-
options for `alter'
|
341
|
-
--id <id:i> Alter entry with id <id> instead of the running entry
|
342
|
-
--start <time:qs> Change the start time to <time>
|
343
|
-
--end <time:qs> Change the end time to <time>
|
349
|
+
#{CLI::USAGE}
|
344
350
|
EOF
|
345
351
|
end
|