From a2c12dede99c0d296194699e025a2e541c8a98a0 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Thu, 9 Sep 2021 18:48:43 +0200 Subject: [PATCH] Prompt for values --- click.scm | 6 ++++-- click/util.scm | 12 ++++++++++++ examples/hello.scm | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/click.scm b/click.scm index c3769a4..afeb2f9 100644 --- a/click.scm +++ b/click.scm @@ -28,8 +28,10 @@ (cond ((null? option-spec) '()) (else - (let ((option (caar option-spec))) - (cons (cons option (option-ref options option #f)) + (let* ((option (car option-spec)) + (option-name (car option)) + (default (option-default-value option))) + (cons (cons option-name (option-ref options option-name default)) (get-options-value options (cdr option-spec))))))) (define (command option-spec procedure) diff --git a/click/util.scm b/click/util.scm index 65ad862..4fc80ba 100644 --- a/click/util.scm +++ b/click/util.scm @@ -18,8 +18,10 @@ (define-module (click util) + #:use-module (ice-9 readline) #:use-module (click constant) #:export (getopt-long-option-spec + option-default-value option-property program-name %program-name)) @@ -42,3 +44,13 @@ (if property (cadr property) default))) + +(define* (option-default-value option #:optional (no-prompt #f)) + "Get default 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))) diff --git a/examples/hello.scm b/examples/hello.scm index 9f00e6b..4f59ccc 100755 --- a/examples/hello.scm +++ b/examples/hello.scm @@ -31,7 +31,7 @@ "Simple program that greets NAME for a total of COUNT times." (let loop ((times count)) (cond ((> times 0) - (format #t "Hello ~a!" name) + (format #t "Hello ~a!~%" name) (loop (- times 1)))))))) (hello (command-line)) -- 2.39.2