From 4f0ea6e3cef32d54c1a276945b8885433a137b7c Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Sat, 23 Jul 2011 18:50:22 +0200 Subject: add support for guild help FOO * module/scripts/help.scm (main): Add support for guild help FOO. --- module/scripts/help.scm | 70 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 17 deletions(-) (limited to 'module/scripts/help.scm') diff --git a/module/scripts/help.scm b/module/scripts/help.scm index 9bb6ace9c..665ba9f71 100644 --- a/module/scripts/help.scm +++ b/module/scripts/help.scm @@ -27,6 +27,7 @@ (define-module (scripts help) #:use-module (ice-9 format) + #:use-module (ice-9 documentation) #:use-module ((srfi srfi-1) #:select (fold append-map))) (define %summary "Show a brief help message.") @@ -80,7 +81,7 @@ %load-path) stringsymbol name))) - (mod (resolve-module modname #:ensure #f)) - (summary (and mod (and=> (module-variable mod '%summary) - variable-ref)))) - (if (and mod - (or all? - (let ((v (module-variable mod '%include-in-guild-list))) - (if v (variable-ref v) #t)))) - (if summary - (format #t " ~A ~23t~a\n" name summary) - (format #t " ~A\n" name))))) - (find-submodules '(scripts))))) + (for-each + (lambda (name) + (let* ((modname `(scripts ,(string->symbol name))) + (mod (resolve-module modname #:ensure #f)) + (summary (and mod (and=> (module-variable mod '%summary) + variable-ref)))) + (if (and mod + (or all? + (let ((v (module-variable mod '%include-in-guild-list))) + (if v (variable-ref v) #t)))) + (if summary + (format #t " ~A ~23t~a\n" name summary) + (format #t " ~A\n" name))))) + (find-submodules '(scripts))) + (display " +For help on a specific command, try \"guild help COMMAND\". +")) + +(define (module-commentary mod) + (file-commentary + (%search-load-path (module-filename mod)))) + +(define (main . args) + (cond + ((null? args) + (list-commands #f)) + ((or (equal? args '("--all")) (equal? args '("-a"))) + (list-commands #t)) + ((not (string-prefix? "-" (car args))) + ;; help for particular command + (let* ((name (car args)) + (mod (resolve-module `(scripts ,(string->symbol name)) + #:ensure #f))) + (if mod + (let ((commentary (module-commentary mod))) + (if commentary + (display commentary) + (format #t "No documentation found for command \"~a\".\n" + name))) + (begin + (format #t "No command named \"~a\".\n" name) + (exit 1))))) + (else + (display "Usage: guild help + guild help --all + guild help COMMAND + +Show a help on guild commands. With --all, show arcane incantations as +well. With COMMAND, show more detailed help for a particular command. +") + (exit 1)))) -- cgit v1.2.3