X-Git-Url: https://git.jsancho.org/?p=guile-click.git;a=blobdiff_plain;f=click%2Futil.scm;fp=click%2Futil.scm;h=c3ac062cd606aeff46bf46a1bfc03cc58d35055a;hp=8a4f771676e14e985772e1d08c8af37cc3c95e62;hb=6d51ec37e2379849f195976753e4b6919c0cfe1d;hpb=27b4e1f5bfac39323bdff089aac094b8e98b0258 diff --git a/click/util.scm b/click/util.scm index 8a4f771..c3ac062 100644 --- a/click/util.scm +++ b/click/util.scm @@ -18,11 +18,10 @@ (define-module (click util) - #:use-module (ice-9 getopt-long) - #:use-module (ice-9 readline) #:use-module (click constant) #:export (getopt-long-option-spec option-property + option-type program-name %program-name)) @@ -31,7 +30,9 @@ (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))) @@ -40,8 +41,34 @@ (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))) + + +;; 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))) + (cond ((not default) + TYPE-TEXT) + ((integer? default) + TYPE-INTEGER) + ((number? default) + TYPE-NUMBER) + (else + TYPE-TEXT))))