X-Git-Url: https://git.jsancho.org/?p=guile-click.git;a=blobdiff_plain;f=click%2Fcommand.scm;fp=click%2Fcommand.scm;h=d60ea1d9b151613b7dbaa75ba158136bb791ecfd;hp=0000000000000000000000000000000000000000;hb=84da61950d4a4038f76fdb9f66e0bbbb71f75385;hpb=ebf74b7c3fda8ead57a398bb6a1555067150d06f diff --git a/click/command.scm b/click/command.scm new file mode 100644 index 0000000..d60ea1d --- /dev/null +++ b/click/command.scm @@ -0,0 +1,73 @@ +;;; Click --- Command Line Interface Creation Kit for GNU Guile +;;; Copyright © 2021 Javier Sancho +;;; +;;; This file is part of Click. +;;; +;;; Click is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; Click is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with Click. If not, see . + + +(define-module (click command) + #:export (command? + command-commands + command-help-text + command-name + command-option-spec + command-procedure + group? + make-command + set-command-click-manager!)) + + +;; Command VTable +(define (make-struct/no-tail 'pwpwpwpwpwpw)) + +(define (command-printer struct port) + (let ((type (if (group? struct) "Group" "Command")) + (name (command-name struct))) + (if name + (format port "<~a ~a>" type name) + (format port "<~a>" type)))) + +(struct-set! vtable-index-printer command-printer) + + +;; Command API +(define (make-command name option-spec help-text procedure commands) + (make-struct/no-tail #f name option-spec help-text procedure commands)) + +(define (set-command-click-manager! command click-manager) + (struct-set! command 0 click-manager)) + +(define (command-name command) + (struct-ref command 1)) + +(define (command-option-spec command) + (struct-ref command 2)) + +(define (command-help-text command) + (struct-ref command 3)) + +(define (command-procedure command) + (struct-ref command 4)) + +(define (command-commands command) + (struct-ref command 5)) + +(define (command? command) + (and (equal? (struct-vtable command) ) + (null? (command-commands command)))) + +(define (group? command) + (and (equal? (struct-vtable command) ) + (not (null? (command-commands command)))))