1 ;;; Click --- Command Line Interface Creation Kit for GNU Guile
2 ;;; Copyright © 2021 Javier Sancho <jsf@jsancho.org>
4 ;;; This file is part of Click.
6 ;;; Click is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or
9 ;;; (at your option) any later version.
11 ;;; Click is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;; General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with Click. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (click command)
29 set-command-click-manager!))
33 (define <command-vtable> (make-struct/no-tail <applicable-struct-vtable> 'pwpwpwpwpwpw))
35 (define (command-printer struct port)
36 (let ((type (if (group? struct) "Group" "Command"))
37 (name (command-name struct)))
39 (format port "<~a ~a>" type name)
40 (format port "<~a>" type))))
42 (struct-set! <command-vtable> vtable-index-printer command-printer)
46 (define (make-command name option-spec help-text procedure commands)
47 (make-struct/no-tail <command-vtable> #f name option-spec help-text procedure commands))
49 (define (set-command-click-manager! command click-manager)
50 (struct-set! command 0 click-manager))
52 (define (command-name command)
53 (struct-ref command 1))
55 (define (command-option-spec command)
56 (struct-ref command 2))
58 (define (command-help-text command)
59 (struct-ref command 3))
61 (define (command-procedure command)
62 (struct-ref command 4))
64 (define (command-commands command)
65 (struct-ref command 5))
67 (define (command? command)
68 (and (equal? (struct-vtable command) <command-vtable>)
69 (null? (command-commands command))))
71 (define (group? command)
72 (and (equal? (struct-vtable command) <command-vtable>)
73 (not (null? (command-commands command)))))