Skip to content

Commit

Permalink
Show command arguments and their types in the help commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mwitmer committed Feb 4, 2014
1 parent c1ea323 commit 1872d10
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions module/guile-wm/module/help.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,42 @@

(use-wm-modules message menu)

(define (format-type type)
(case type
((#:string) "string")
((#:symbol) "symbol")
((#:number) "number")))

(define (format-arg arg)
(format #f "(^(color cyan)~a^(color white): ^(color salmon)~a^(color white)) "
(car arg) (format-type (cdr arg))))

(define (format-args args)
(if (list? args)
(apply string-append (map format-arg args))
(format-arg args)))

(define (command-description c)
(define summary (command-summary c))
(format #f "~a\n~a" summary (command-documentation c)))

(define (command-summary c)
(format #f "^(color wheat)~a^(color white) ~a"
(symbol->string c)
(format-args (hashq-ref commands c))))

(define-command (help)
"List all the commands and show documentation for the one selected
by the user"
(menu "Select a command:"
(map (lambda (c) (cons (symbol->string c) (command-documentation c)))
(map (lambda (c)
(cons (symbol->string c)
(command-description c)))
(hash-map->list (lambda (k v) k) commands))
(lambda (doc)
(if doc (message doc) (message "Not documented")))))
(if doc (sticky-message doc) (message "Not documented")))))

(define-command (document (cmd #:symbol))
"Display docstring for command CMD"
(or
(and=> (command-documentation cmd) message)
(message (format #f "No command with name ~a" cmd))))
(sticky-message (command-description cmd)))

0 comments on commit 1872d10

Please sign in to comment.