summaryrefslogtreecommitdiff
path: root/module/scripts
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2011-07-23 18:50:22 +0200
committerAndy Wingo <wingo@pobox.com>2011-07-23 18:50:22 +0200
commit4f0ea6e3cef32d54c1a276945b8885433a137b7c (patch)
tree016287aacd0a85fe3c75d03a385ea6e78f50bdae /module/scripts
parentf4a76a315ad8f1f6f4dbdfbd2f030c6b299cb5a4 (diff)
downloadguile-4f0ea6e3cef32d54c1a276945b8885433a137b7c.tar.gz
add support for guild help FOO
* module/scripts/help.scm (main): Add support for guild help FOO.
Diffstat (limited to 'module/scripts')
-rw-r--r--module/scripts/help.scm70
1 files changed, 53 insertions, 17 deletions
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)
string<?))))
-(define (main . args)
+(define (list-commands all?)
(display "\
Usage: guild COMMAND [ARGS]
@@ -91,19 +92,54 @@ Usage: guild COMMAND [ARGS]
Commands:
")
- (let ((all? (or (equal? args '("--all"))
- (equal? args '("-a")))))
- (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)))))
+ (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))))