Extract some functions from the help command

Simplify the `help' command by extracting the code into separate
functions.
This commit is contained in:
Tom Willemse 2014-03-01 13:24:58 +01:00
parent 3036734e4b
commit 73961321ff

View file

@ -78,6 +78,23 @@ Displays version and some copyright information."
(display "under the terms of the GNU General Public License.") (newline) (display "under the terms of the GNU General Public License.") (newline)
(display "For more information about these matters, see the file named COPYING.") (newline)) (display "For more information about these matters, see the file named COPYING.") (newline))
(define (print-command-help command)
"Print the help message for 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))))
(define (print-short-command-help command)
"Print COMMAND's name and its short description."
(format #t " ~a~15t~a~%" (car command) (assq-ref command #:usage)))
(define (print-general-help)
"Print the general help message for gitto."
(display "gitto [command [arguments ...]]")
(newline)
(for-each print-short-command-help command-list))
(define-command (help #:optional command) (define-command (help #:optional command)
"Display this help." "Display this help."
"Usage: gitto help [COMMAND] "Usage: gitto help [COMMAND]
@ -86,17 +103,8 @@ Display a help message. If COMMAND is not specified, print some
information about gitto, otherwise print some information about information about gitto, otherwise print some information about
COMMAND." COMMAND."
(if command (if command
(let ((command-spec (assoc-ref command-list command))) (print-command-help command)
(if command-spec (print-general-help)))
(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~15t~a~%" (car cmd) (assq-ref cmd #:usage)))
command-list))))
(define (known? repo) (define (known? repo)
"Do we know REPO?" "Do we know REPO?"