(define-module (click)
+ #:use-module (ice-9 getopt-long)
#:use-module (srfi srfi-1)
#:use-module (click args)
#:use-module (click command)
(new-command (make-command name click-option-spec help procedure commands)))
(let ((click-manager
(lambda (args)
+ (when (not (program-name))
+ (program-name (car args)))
(let ((values (parse-args args click-option-spec)))
;; Call current command
(cond ((option-ref values 'help #f)
- (let ((program-name (car args)))
- (display-help program-name new-command)))
+ (display-help new-command))
(else
(when procedure
(apply procedure (map cdr (get-values option-spec values))))
(let ((next-command-args (cdar values)))
(when (not (null? next-command-args))
(let* ((next-command-name (car next-command-args))
- (next-command (find (lambda (command) (
- (display next-command-args)(newline)
- (display next-command-name) (newline)))))
+ (next-command (find (lambda (command)
+ (equal? (command-name command) next-command-name))
+ commands)))
+ (next-command next-command-args)))))
options)))
-(define* (display-help program-name command)
+(define* (display-help command)
"Display help message"
;; Usage
- (format #t "Usage: ~a [OPTIONS]" program-name)
+ (format #t "Usage: ~a [OPTIONS]" (program-name))
(when (group? command)
(format #t " COMMAND [ARGS]..."))
(format #t "~%~%")
#:use-module (click constant)
#:export (getopt-long-option-spec
option-property
- option-type))
+ option-type
+ program-name))
(define (getopt-long-option-spec option-spec)
default)))
+(define program-name (make-parameter #f))
+
+
;; Types
(define TYPE-TEXT
`((description . "TEXT")
#:name "initdb"
#:help "Init database."
#:procedure (lambda ()
- (format #t "Initialized the database"))))
+ (format #t "Initialize the database.~%"))))
(define dropdb
(command
#:name "dropdb"
#:help "Drop database."
#:procedure (lambda ()
- (format #t "Dropped the database"))))
+ (format #t "Drop the database.~%"))))
(define cli
(group