ui: Implement `guix --help'.

* guix/ui.scm (command-files, commands, show-guix-help): New procedures.
  (guix-main): Invoke `show-guix-help' when passed `--help'.
This commit is contained in:
Ludovic Courtès 2013-05-10 12:33:18 +02:00
parent ec5d0a85eb
commit e31ff8b8d0
1 changed files with 29 additions and 2 deletions

View File

@ -30,6 +30,7 @@
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-37)
#:autoload (ice-9 ftw) (scandir)
#:use-module (ice-9 match)
#:use-module (ice-9 format)
#:export (_
@ -385,10 +386,36 @@ reporting."
(apply format #f msg args)))))
(define (show-guix-usage)
;; TODO: Dynamically generate a summary of available commands.
(format (current-error-port)
(_ "Usage: guix COMMAND ARGS...~%")))
(define (command-files)
"Return the list of source files that define Guix sub-commands."
(define directory
(and=> (search-path %load-path "guix.scm")
(compose (cut string-append <> "/guix/scripts")
dirname)))
(if directory
(scandir directory (cut string-suffix? ".scm" <>))
'()))
(define (commands)
"Return the list of Guix command names."
(map (compose (cut string-drop-right <> 4)
basename)
(command-files)))
(define (show-guix-help)
(format #t (_ "Usage: guix COMMAND ARGS...
Run COMMAND with ARGS.\n"))
(newline)
(format #t (_ "COMMAND must be one of the sub-commands listed below:\n"))
(newline)
;; TODO: Display a synopsis of each command.
(format #t "~{ ~a~%~}" (commands))
(show-bug-report-information))
(define program-name
;; Name of the command-line program currently executing, or #f.
(make-parameter #f))
@ -417,7 +444,7 @@ found."
(define (option? str) (string-prefix? "-" str))
(match args
(() (show-guix-usage) (exit 1))
(("--help") (show-guix-usage))
(("--help") (show-guix-help))
(("--version") (show-version-and-exit "guix"))
(((? option?) args ...) (show-guix-usage) (exit 1))
((command args ...)