X-Git-Url: https://git.jsancho.org/?p=guile-click.git;a=blobdiff_plain;f=click%2Futil.scm;h=827a4a9b2e12885fa179317b56dbdfe5d2334638;hp=4fc80bad05526d47a2a0f8ed22dc02e7ef3d27fe;hb=487cd0d4c6c0ee9681cc132e5316ded7fc5dd0f7;hpb=a2c12dede99c0d296194699e025a2e541c8a98a0 diff --git a/click/util.scm b/click/util.scm index 4fc80ba..827a4a9 100644 --- a/click/util.scm +++ b/click/util.scm @@ -18,19 +18,15 @@ (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)) + option-type + program-name)) -(define %program-name (make-fluid "guile")) -(define (program-name) - (fluid-ref %program-name)) (define (getopt-long-option-spec option-spec) + "Transform click option spec into getopt-long format" (map (lambda (option) (cons (car option) (cons (list 'value (not (option-property option 'flag))) @@ -39,18 +35,37 @@ (cdr option))))) option-spec)) + (define* (option-property option property-name #:optional (default #f)) + "Return the option property with a given name" (let ((property (assq property-name (cdr option)))) (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" + +(define program-name (make-parameter #f)) + + +;; Types +(define TYPE-TEXT + `((description . "TEXT") + (convert . ,identity))) +(define TYPE-INTEGER + `((description . "INTEGER") + (convert . ,string->number))) +(define TYPE-NUMBER + `((description . "NUMBER") + (convert . ,string->number))) + +(define (option-type option) + "Return allowed type for the value in the option" (let ((default (option-property option 'default))) - (if (not default) - (let ((prompt (option-property option 'prompt))) - (if prompt - (readline (format #f "~a: " prompt)) - default)) - default))) + (cond ((not default) + TYPE-TEXT) + ((integer? default) + TYPE-INTEGER) + ((number? default) + TYPE-NUMBER) + (else + TYPE-TEXT))))