]> git.jsancho.org Git - guile-click.git/blob - click/util.scm
65ad8627e12579b5a8d072638d0db43ed3b65e33
[guile-click.git] / click / util.scm
1 ;;; Click --- Command Line Interface Creation Kit for GNU Guile
2 ;;; Copyright © 2021 Javier Sancho <jsf@jsancho.org>
3 ;;;
4 ;;; This file is part of Click.
5 ;;;
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.
10 ;;;
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.
15 ;;;
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/>.
18
19
20 (define-module (click util)
21   #:use-module (click constant)
22   #:export (getopt-long-option-spec
23             option-property
24             program-name
25             %program-name))
26
27 (define %program-name (make-fluid "guile"))
28 (define (program-name)
29   (fluid-ref %program-name))
30
31 (define (getopt-long-option-spec option-spec)
32   (map (lambda (option)
33          (cons (car option)
34                (cons (list 'value (not (option-property option 'flag)))
35                      (filter (lambda (property)
36                                (not (memq (car property) CLICK_PROPERTIES)))
37                              (cdr option)))))
38        option-spec))
39
40 (define* (option-property option property-name #:optional (default #f))
41   (let ((property (assq property-name (cdr option))))
42     (if property
43         (cadr property)
44         default)))