Skip to content

Commit 8ee3c2d

Browse files
committed
Improve usage message
1 parent a02a200 commit 8ee3c2d

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/main.scm

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(declare (uses functions options util convolutional full pooling))
22

3-
(use getopt-long)
3+
(use getopt-long srfi-13)
44

55
(define prog-name "layer")
66

@@ -18,14 +18,22 @@
1818
(desc (cadr def))
1919
(grammar (caddr def)))
2020
(format #t "Usage: ~A ~A [OPTIONS]\n\n~A.\n\n" prog-name command desc)
21-
(print "Options:")
22-
(print (usage grammar))))
21+
(print "Required parameters:\n")
22+
(print (usage (filter required? grammar)))
23+
(print "Optional:\n")
24+
(print (usage (filter (lambda (o) (not (required? o))) grammar)))))
2325

2426
(define (print-program-usage #!optional error)
2527
(when error (begin (print error) (newline)))
2628
(format #t "Usage: ~A COMMAND [OPTIONS]\n\n~A.\n\n" prog-name prog-desc)
27-
(print "Commands:")
28-
(for-each (lambda (c) (print " " (car c) "\t\t" (cadr c))) commands))
29+
(print "Commands:\n")
30+
(let ((max-command-width (apply max (map (compose string-length car) commands))))
31+
(for-each (lambda (c)
32+
(let* ((spaces (+ 4 (- max-command-width (string-length (car c)))))
33+
(sep (make-string spaces #\ )))
34+
(print " " (car c) sep (cadr c))))
35+
commands))
36+
(format #t "\nSee '~A COMMAND' to read more about a specific command.\n" prog-name))
2937

3038
(define (parse-options command args grammar)
3139
(handle-exceptions

0 commit comments

Comments
 (0)