Start rework of command-line module.

This commit is contained in:
Dominik Pantůček 2023-03-13 22:31:01 +01:00
parent 924f5d6675
commit 798b23c858
2 changed files with 64 additions and 1 deletions

View file

@ -28,7 +28,8 @@
dictionary
month
period
member-file)
member-file
command-line)
;; Print banner
(print "brmsaptool 0.2 (c) 2023 Brmlab, z.s.")
@ -40,6 +41,7 @@
(month-tests!)
(period-tests!)
(member-file-tests!)
(command-line-tests!)
(newline)
(load-member-file "members/joe")

61
command-line.scm Normal file
View file

@ -0,0 +1,61 @@
;;
;; command-line.scm
;;
;; Argument parsing on command-line with interpreter -- support.
;;
;; ISC License
;;
;; Copyright 2023 Brmlab, z.s.
;; Dominik Pantůček <dominik.pantucek@trustica.cz>
;;
;; Permission to use, copy, modify, and/or distribute this software
;; for any purpose with or without fee is hereby granted, provided
;; that the above copyright notice and this permission notice appear
;; in all copies.
;;
;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
;;
(module
command-line
(command-line
command-line-tests!)
(import scheme
(chicken base)
testing)
(define (parse-command-line specs)
#f)
(define-syntax make-option
(syntax-rules ()
((_ opt help (args ...) body ...)
(list (symbol->string 'opt)
help
(lambda (args ...) body ...)))
((_ opt help proc)
(list (symbol->string 'opt) help proc))
((_ opt help)
(list (symbol->string 'opt help 'help)))))
(define-syntax command-line
(syntax-rules ()
((_ ((exps ...) ...))
(parse-command-line
(list (make-option exps ...) ...)))))
;; Performs self-tests of the command-line module
(define (command-line-tests!)
(run-tests
command-line
))
)