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)
21 #:use-module (ice-9 getopt-long)
22 #:use-module (click constant)
23 #:use-module (click help)
24 #:use-module (click util)
25 #:use-module (click value)
30 (define (command option-spec procedure)
31 "Define a new command for the procedure"
33 (let* ((click-option-spec (append option-spec (list HELP_OPTION)))
34 (values (getopt-long args
35 (getopt-long-option-spec click-option-spec))))
36 (if (option-ref values 'help #f)
37 (let ((program-name (car args)))
38 (display-help program-name procedure click-option-spec))
39 (apply procedure (map cdr (get-values option-spec values)))))))
42 (define (group option-spec target . commands)
43 "Define a new group with a list of commands associated"
45 (let* ((click-option-spec (append option-spec (list HELP_OPTION)))
46 (values (getopt-long args
47 (getopt-long-option-spec click-option-spec))))
48 (if (or (null? (cdr args))
49 (option-ref values 'help #f))
50 (let ((program-name (car args)))
51 (display-help program-name target click-option-spec commands))
52 (apply target (map cdr (get-values option-spec values)))))))