#:use-module (click constant)
#:export (getopt-long-option-spec
option-property
- program-name
- %program-name))
+ option-type))
-(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)))
(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))))