X-Git-Url: https://git.jsancho.org/?p=guile-click.git;a=blobdiff_plain;f=click%2Fvalue.scm;fp=click%2Fvalue.scm;h=ec00445a0ec7ac104907f35a06c18795fd1a8a21;hp=0000000000000000000000000000000000000000;hb=27b4e1f5bfac39323bdff089aac094b8e98b0258;hpb=432c741eb5dac653c1a65fae2b8f15c4b444897f diff --git a/click/value.scm b/click/value.scm new file mode 100644 index 0000000..ec00445 --- /dev/null +++ b/click/value.scm @@ -0,0 +1,49 @@ +;;; Click --- Command Line Interface Creation Kit for GNU Guile +;;; Copyright © 2021 Javier Sancho +;;; +;;; This file is part of Click. +;;; +;;; Click is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; Click is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with Click. If not, see . + + +(define-module (click value) + #:use-module (ice-9 getopt-long) + #:use-module (ice-9 readline) + #:use-module (click util) + #:export (get-option-default-value + get-values)) + + +(define (get-values option-spec values) + "Return an associated list with values for all the options in option-spec" + (cond ((null? option-spec) + '()) + (else + (let* ((option (car option-spec)) + (option-name (car option)) + (value (or (option-ref values option-name #f) + (get-option-default-value option)))) + (cons (cons option-name value) + (get-values (cdr option-spec) values)))))) + + +(define* (get-option-default-value option #:optional (no-prompt #f)) + "Get value for option, asking user if prompt property is set" + (let ((default (option-property option 'default))) + (if (not default) + (let ((prompt (option-property option 'prompt))) + (if prompt + (readline (format #f "~a: " prompt)) + default)) + default)))