Browse code
Error correction and switch to CLON
- Use CLON to handle the command line arguments
- Improve error handling
Showing 5 changed files
... | ... |
@@ -14,6 +14,20 @@ a record do not begin with either a single tab or three spaces) and it detects i |
14 | 14 |
Additionally, if run in interactive mode `-i`, when it discovers invalid input, it will prompt for a replacement |
15 | 15 |
and attempt to correct the error. Also, with `-W`, it should be able to recover from whitespace errors on its own. |
16 | 16 |
|
17 |
+## Install: |
|
18 |
+ |
|
19 |
+Just do this: |
|
20 |
+ |
|
21 |
+``` |
|
22 |
+CC=`which gcc` \ |
|
23 |
+sbcl --no-userinit \ |
|
24 |
+ --load ~/quicklisp/setup.lisp \ |
|
25 |
+ --eval '(push (truename ".") asdf:*central-registry*)' \ |
|
26 |
+ --eval '(ql:quickload :timesheet)' \ |
|
27 |
+ --load timesheet-client.lisp \ |
|
28 |
+ --eval '(timesheet.cli::make-executable)' |
|
29 |
+``` |
|
30 |
+ |
|
17 | 31 |
## Todo: |
18 | 32 |
|
19 | 33 |
- Expand error handling |
... | ... |
@@ -24,15 +38,18 @@ and attempt to correct the error. Also, with `-W`, it should be able to recover |
24 | 38 |
## Examples: |
25 | 39 |
|
26 | 40 |
``` |
27 |
-% ./timesheet -h |
|
28 |
-timesheet file parser, version 0:4 |
|
29 |
--c --client boolean Sort by client |
|
30 |
--r --reverse boolean Reverse sort |
|
31 |
--W --ignore-whitespace boolean Ignore whitespace errors in input |
|
32 |
--i --interactive boolean Run Interactively |
|
33 |
--v --version boolean Version |
|
34 |
--s --status boolean Print a summary of the hours worked and the prices |
|
35 |
--h --help boolean show help |
|
41 |
+Usage: timesheet [-crWisvh] [OPTIONS] TIMESHEETS ... |
|
42 |
+ |
|
43 |
+A program for managing logs of hours worked |
|
44 |
+Main actions |
|
45 |
+ -c, --client Sort records by client |
|
46 |
+ -r, --reverse Reverse the sort direction |
|
47 |
+ -W, --ignore-whitespace Ignore whitespace errors in input |
|
48 |
+ -i, --interactive Run interactively |
|
49 |
+ -s, --status Print a short summary of work status |
|
50 |
+Other options |
|
51 |
+ -v, --version Show the program version |
|
52 |
+ -h, --help Show this help |
|
36 | 53 |
``` |
37 | 54 |
|
38 | 55 |
By default, it orders the log by dates. With the `-r` option, it displays the dates in descending order: |
... | ... |
@@ -29,3 +29,9 @@ |
29 | 29 |
(:use #:cl #:anaphora #:alexandria #:serapeum #:fwoar.lisputils |
30 | 30 |
#:timesheet.parser) |
31 | 31 |
(:import-from #:format-string-builder #:define-message)) |
32 |
+ |
|
33 |
+(defpackage #:timesheet.cli |
|
34 |
+ (:use #:cl #:anaphora #:alexandria #:serapeum #:fwoar.lisputils |
|
35 |
+ #:timesheet.parser #:timesheet #:net.didierverna.clon) |
|
36 |
+ (:import-from #:format-string-builder #:define-message)) |
|
37 |
+ |
32 | 38 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,41 @@ |
1 |
+ |
|
2 |
+(in-package #:timesheet.cli) |
|
3 |
+ |
|
4 |
+(defsynopsis (:postfix "TIMESHEETS ...") |
|
5 |
+ (text :contents "A program for managing logs of hours worked") |
|
6 |
+ (group (:header "Main actions") |
|
7 |
+ (flag :short-name "c" |
|
8 |
+ :long-name "client" |
|
9 |
+ :description "Sort records by client") |
|
10 |
+ (flag :short-name "r" |
|
11 |
+ :long-name "reverse" |
|
12 |
+ :description "Reverse the sort direction") |
|
13 |
+ (flag :short-name "W" |
|
14 |
+ :long-name "ignore-whitespace" |
|
15 |
+ :description "Ignore whitespace errors in input") |
|
16 |
+ (flag :short-name "i" :long-name "interactive" |
|
17 |
+ :description "Run interactively") |
|
18 |
+ (flag :short-name "s" :long-name "status" |
|
19 |
+ :description "Print a short summary of work status")) |
|
20 |
+ (group (:header "Other options") |
|
21 |
+ (flag :short-name "v" :long-name "version" |
|
22 |
+ :description "Show the program version") |
|
23 |
+ (flag :short-name "h" :long-name "help" |
|
24 |
+ :description "Show this help"))) |
|
25 |
+ |
|
26 |
+(defun pprint-log-main () |
|
27 |
+ (make-context) |
|
28 |
+ (cond |
|
29 |
+ ((getopt :long-name "help") (help)) |
|
30 |
+ (t (timesheet::with-timesheet-configuration () |
|
31 |
+ (timesheet::pprint-log |
|
32 |
+ (remainder) |
|
33 |
+ :client (getopt :long-name "client") |
|
34 |
+ :interactive (getopt :long-name "interactive") |
|
35 |
+ :ignore-whitespace (getopt :long-name "ignore-whitespace") |
|
36 |
+ :version (getopt :long-name "version") |
|
37 |
+ :status (getopt :long-name "status") |
|
38 |
+ :reverse (getopt :long-name "reverse")))))) |
|
39 |
+ |
|
40 |
+(defun make-executable () |
|
41 |
+ (dump "timesheet" pprint-log-main)) |
... | ... |
@@ -8,13 +8,13 @@ |
8 | 8 |
:depends-on (#:alexandria |
9 | 9 |
#:anaphora |
10 | 10 |
#:cells |
11 |
+ #:net.didierverna.clon |
|
11 | 12 |
#:command-line-arguments |
12 | 13 |
#:drakma |
13 | 14 |
#:format-string-builder |
14 | 15 |
#:fwoar.lisputils |
15 | 16 |
#:local-time-duration |
16 | 17 |
#:lquery |
17 |
- #:manardb |
|
18 | 18 |
#:ningle |
19 | 19 |
#:serapeum |
20 | 20 |
#:should-test |
... | ... |
@@ -139,28 +139,6 @@ |
139 | 139 |
(let* ((entries (parse-file file ignore-whitespace))) |
140 | 140 |
(mapcan #'get-entry-ranges entries))) |
141 | 141 |
|
142 |
-(defparameter +pprint-log-option-spec+ |
|
143 |
- '((("client" #\c) :type boolean :optional t :documentation "Sort by client") |
|
144 |
- (("reverse" #\r) :type boolean :optional t :documentation "Reverse sort") |
|
145 |
- (("ignore-whitespace" #\W) :type boolean :optional t :documentation "Ignore whitespace errors in input") |
|
146 |
- (("interactive" #\i) :type boolean :optional t :documentation "Run Interactively") |
|
147 |
- (("version" #\v) :type boolean :optional t :documentation "Version") |
|
148 |
- (("status" #\s) :type boolean :optional t |
|
149 |
- :documentation "Print a summary of the hours worked and the prices") |
|
150 |
- (("help" #\h) :type boolean :optional t :documentation "show help"))) |
|
151 |
- |
|
152 |
-(defparameter *version* "0:4") |
|
153 |
- |
|
154 |
-(define-message version-message (version) |
|
155 |
- (:own-line () "timesheet file parser, version " :str)) |
|
156 |
- |
|
157 |
-(defun show-version () |
|
158 |
- (version-message t *version*)) |
|
159 |
- |
|
160 |
-(defun show-help () |
|
161 |
- (show-version) |
|
162 |
- (command-line-arguments:show-option-help +pprint-log-option-spec+ :sort-names t)) |
|
163 |
- |
|
164 | 142 |
(defun sort-by-date (results) |
165 | 143 |
(stable-sort results #'local-time:timestamp< |
166 | 144 |
:key (alambda (apply #'local-time:encode-timestamp |
... | ... |
@@ -272,12 +250,3 @@ |
272 | 250 |
(ubiquitous:defaulted-value #p"~/time.md" :timesheet :file))) |
273 | 251 |
,@body))) |
274 | 252 |
|
275 |
-(defun pprint-log-main (argv) |
|
276 |
- (with-timesheet-configuration () |
|
277 |
- (command-line-arguments:handle-command-line |
|
278 |
- +pprint-log-option-spec+ |
|
279 |
- 'pprint-log |
|
280 |
- :command-line (cdr argv) |
|
281 |
- :name "timesheet" |
|
282 |
- :rest-arity t))) |
|
283 |
- |