From 39b5431da12ecf3c72d8b86eff600155450fa8be Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sat, 8 Jun 2013 01:04:45 +0200 Subject: [PATCH] Specify usage information in the command --- gitto/main.scm | 127 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 88 insertions(+), 39 deletions(-) diff --git a/gitto/main.scm b/gitto/main.scm index 705faf7..3c82e49 100644 --- a/gitto/main.scm +++ b/gitto/main.scm @@ -31,16 +31,22 @@ (define-syntax define-command (syntax-rules () ((_ (name . args) + usage + longdoc exp exp* ...) (begin (set! command-list (cons - (cons (symbol->string (quote name)) - (case-lambda + (list (symbol->string (quote name)) + (cons + #:function + (case-lambda* (args exp exp* ...) (lst (format #t "Wrong number of arguments.~%")))) - command-list)))))) + (cons #:usage usage) + (cons #:documentation longdoc)) + command-list)))))) (define command-list '()) (define config-exclusion-list '()) @@ -62,6 +68,9 @@ set in the current environment." (define-command (version) "Display version information." + "Usage: gitto version + +Displays version and some copyright information." (display "gitto 0.1.0") (newline) (display "Copyright (C) 2012 Tom Willemse") (newline) (display "This program comes with ABSOLUTELY NO WARRANTY.") (newline) @@ -69,24 +78,25 @@ set in the current environment." (display "under the terms of the GNU General Public License.") (newline) (display "For more information about these matters, see the file named COPYING.") (newline)) -(define-command (help) - "Display some help." - (display "\ -gitto [command [arguments ...]] - add Register a new repository directory - remove Remove a repository directory - check Check if a repository has been registered - list List all repositories and their status - list locations List all registered repositories' locations - purge Remove all repositories that don't exist - config Show each repository's configuration - config global Show template configuration - config update Merge template configuration with each - repository's configuration - config hooks Install configured hooks for repositories - version Display version - help Display this help -")) +(define-command (help #:optional command) + "Display this help." + "Usage: gitto help [COMMAND] + +Display a help message. If COMMAND is not specified, print some +information about gitto, otherwise print some information about +COMMAND." + (if command + (let ((command-spec (assoc-ref command-list command))) + (if command-spec + (format #t "~a~%" (assq-ref command-spec #:documentation)) + (format #t "Unknown command: ~a~%" command))) + (begin + (display "gitto [command [arguments ...]]") + (newline) + (for-each + (lambda (cmd) + (format #t " ~a~20t~a~%" (car cmd) (assq-ref cmd #:usage))) + command-list)))) (define (known? repo) "Do we know REPO?" @@ -112,12 +122,21 @@ gitto [command [arguments ...]] (close-port port))) (define-command (check repository) - "Check to see if REPOSITORY has been registered." + "Check to see if a repository has been registered." + "Usage: gitto check REPO + +Checks whether or not the git repository REPO has been registered with +gitto." (format #t "Repository is~a registered~%" (if (known? repository) "" " not"))) (define-command (add repository) - "Register REPOSITORY in the repository list." + "Register a repository." + "Usage: gitto add REPO + +Add REPO to the registered repository list. This command will fail if +REPO does not indicate a git repository or if it has already been +registered." (set! repository (make (realpath repository))) (if (not (known? repository)) (begin @@ -138,7 +157,12 @@ gitto [command [arguments ...]] (newline)) (define-command (remove repository) - "Remove/unregister REPOSITORY from the repository list." + "Unregister a repository." + "Usage: gitto remove REPO + +Removes REPO from the registered repository list. This command will +fail if REPO does not indicate a git repository of if it hasn't been +registered." (unless (member repository repositories same-repository?) (set! repository (realpath repository))) @@ -153,6 +177,16 @@ gitto [command [arguments ...]] (define-command (list . args) "List information about every repository." + "Usage: gitto list + gitto list locations + +The first form shows an overview of the status of your registered +repositories and their branches. By default branches without changer +aren't shown, but you can change this behaviour by setting the +`show-unchanged-branches?' variable in your init file. + +The second form prints the location on your filesystem for each +registered repository as absolute paths." (if (and (not (eq? args '())) (equal? (car args) "locations")) (list-repository-locations) (for-each print repositories))) @@ -168,7 +202,11 @@ gitto [command [arguments ...]] (string