|
From: | Matt Wette |
Subject: | accessing repeated flagged values using (ice-9 getopt-long) |
Date: | Mon, 21 Dec 2015 11:03:55 -0800 |
Hi Folks, This was filed to address@hidden (feature addition) about two months ago, #21698. There has been no reaction there so I was wondering what others thought . This is in context to guile-2.0.11. The issue is that getopt-long goes not handle repeated flags like some may like. I have provided a patch to add a new procedure “option-ref/many”. Comments? Matt The (ice-9 getopt-long) module does not provide a process for accessing multiple command line arguments. A patch for ice-9/getopt-long.scm is attached which adds the procedure getopt-ref/many to access multiple argument values. The following program and results illustrate the use of the current getopt-ref and the proposed getopt-ref/many: mwette$ ./gotest.scm -f foo1 -b bar1 -f foo2 baz1 baz2 program arguments: ("./gotest.scm" "-f" "foo1" "-b" "bar1" "-f" "foo2" "baz1" "baz2") getopt using option-ref: foo: "foo2" bar: "bar1" getopt using option-ref/many: foo: ("foo1" "foo2")
bar: "bar1" where mwette$ cat gotest.scm #!/opt/local/bin/guile !# (use-modules (ice-9 getopt-long)) (define spec '((foo (single-char #\f) (value #t)) (bar (single-char #\b) (value #t)))) (let* ((args (program-arguments)) (opts (getopt-long args spec))) (simple-format #t "program arguments:\n") (simple-format #t "~S\n" args) (simple-format #t "\ngetopt using option-ref:\n") (simple-format #t "foo: ~S\n" (option-ref opts 'foo #f)) (simple-format #t "bar: ~S\n" (option-ref opts 'bar #f)) (simple-format #t "\ngetopt using option-ref/many:\n") (simple-format #t "foo: ~S\n" (option-ref/many opts 'foo #f)) (simple-format #t "bar: ~S\n" (option-ref/many opts 'bar #f)) ) |
getopt-long.patch
Description: Binary data
[Prev in Thread] | Current Thread | [Next in Thread] |