1 ;;; Help --- Show help on guild commands
3 ;;;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 3 of the License, or (at your option) any later version.
10 ;;;; This library is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;;;; Lesser General Public License for more details.
15 ;;;; You should have received a copy of the GNU Lesser General Public
16 ;;;; License along with this library; if not, write to the Free
17 ;;;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 ;;;; Boston, MA 02110-1301 USA
24 ;; Show help for Guild scripts.
28 (define-module (scripts help)
29 #:use-module (ice-9 format)
30 #:use-module (ice-9 documentation)
31 #:use-module ((srfi srfi-1) #:select (fold append-map))
32 #:export (show-help show-summary show-usage main))
34 (define %summary "Show a brief help message.")
35 (define %synopsis "help\nhelp --all\nhelp COMMAND")
37 Show help on guild commands. With --all, show arcane incantations as
38 well. With COMMAND, show more detailed help for a particular command.
42 (define (directory-files dir)
43 (if (and (file-exists? dir) (file-is-directory? dir))
44 (let ((dir-stream (opendir dir)))
45 (let loop ((new (readdir dir-stream))
51 (loop (readdir dir-stream)
52 (if (or (string=? "." new) ; ignore
53 (string=? ".." new)) ; ignore
58 (define (strip-extensions path)
61 (string-suffix? ext path)
62 ;; We really can't be adding e.g. ChangeLog-2008 to the set
63 ;; of runnable scripts, just because "" is a valid
64 ;; extension, by default. So hack around that here.
65 (not (string-null? ext))
67 (- (string-length path) (string-length ext)))))
68 (append %load-compiled-extensions %load-extensions)))
73 ((equal? (car l) (cadr l)) (unique (cdr l)))
74 (else (cons (car l) (unique (cdr l))))))
76 (define (find-submodules head)
77 (let ((shead (map symbol->string head)))
80 (append-map (lambda (path)
81 (fold (lambda (x rest)
82 (let ((stripped (strip-extensions x)))
83 (if stripped (cons stripped rest) rest)))
86 (fold (lambda (x y) (in-vicinity y x)) path shead))))
90 (define (list-commands all?)
92 Usage: guild COMMAND [ARGS]
93 Run command-line scripts provided by GNU Guile and related programs.
100 (let* ((modname `(scripts ,(string->symbol name)))
101 (mod (resolve-module modname #:ensure #f))
102 (summary (and mod (and=> (module-variable mod '%summary)
106 (let ((v (module-variable mod '%include-in-guild-list)))
107 (if v (variable-ref v) #t))))
109 (format #t " ~A ~23t~a\n" name summary)
110 (format #t " ~A\n" name)))))
111 (find-submodules '(scripts)))
113 For help on a specific command, try \"guild help COMMAND\".
115 Report guild bugs to ~a
116 GNU Guile home page: <http://www.gnu.org/software/guile/>
117 General help using GNU software: <http://www.gnu.org/gethelp/>
118 For complete documentation, run: info guile 'Using Guile Tools'
119 " %guile-bug-report-address))
121 (define (module-commentary mod)
123 (%search-load-path (module-filename mod))))
125 (define (module-command-name mod)
126 (symbol->string (car (last-pair (module-name mod)))))
128 (define* (show-usage mod #:optional (port (current-output-port)))
129 (let ((usages (string-split
130 (let ((var (module-variable mod '%synopsis)))
133 (string-append (module-command-name mod)
136 (display "Usage: guild " port)
137 (display (car usages))
139 (for-each (lambda (u)
140 (display " guild " port)
145 (define* (show-summary mod #:optional (port (current-output-port)))
146 (let ((var (module-variable mod '%summary)))
149 (display (variable-ref var) port)
152 (define* (show-help mod #:optional (port (current-output-port)))
153 (show-usage mod port)
154 (show-summary mod port)
156 ((module-variable mod '%help)
158 (display (variable-ref var) port)
160 ((module-commentary mod)
161 => (lambda (commentary)
163 (display commentary port)))
165 (format #t "No documentation found for command \"~a\".\n"
166 (module-command-name mod)))))
168 (define %mod (current-module))
169 (define (main . args)
173 ((or (equal? args '("--all")) (equal? args '("-a")))
175 ((and (null? (cdr args)) (not (string-prefix? "-" (car args))))
176 ;; help for particular command
177 (let ((name (car args)))
179 ((resolve-module `(scripts ,(string->symbol name)) #:ensure #f)
184 (format #t "No command named \"~a\".\n" name)
187 (show-help %mod (current-error-port))