1 ;;; Click --- Command Line Interface Creation Kit for GNU Guile
2 ;;; Copyright © 2021 Javier Sancho <jsf@jsancho.org>
4 ;;; This file is part of Click.
6 ;;; Click is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or
9 ;;; (at your option) any later version.
11 ;;; Click is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;; General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with Click. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (click display)
21 #:use-module (ice-9 format)
22 #:use-module (click util)
23 #:export (display-error
27 (define (get-type-description option)
28 "Return allowed type for the value in the option"
29 (assoc-ref (option-type option) 'description))
31 (define (display-help procedure option-spec)
32 (format #t "Usage: ~a [OPTIONS]
37 " (program-name) (procedure-documentation procedure))
39 (let* ((options (map (lambda (option)
44 (option-property option 'single-char)))
46 (format #f ", -~a" single-char)
49 (not (option-property option 'flag))))
51 (format #f " ~a" (get-type-description option))
53 (option-property option 'help "")))
55 (sep (+ 2 (apply max (map (lambda (option)
56 (string-length (car option)))
58 (for-each (lambda (option)
62 (- sep (string-length (car option)))
66 (define (display-error wrong-option)
67 (format #t "Usage: ~a [OPTIONS]
68 Try '~a --help' for help.
70 Error: No such option: ~a
71 " (program-name) (program-name) wrong-option))