On Wednesday, October 12, 2016 at 6:54:45 AM UTC-4, Ian Thomas wrote: > On Tuesday, October 11, 2016 at 9:50:12 PM UTC-4, Ben Greenman wrote: > > Indirect answer: could you use `command-line` instead? > > > > > > > > #lang racket/base > > (require racket/cmdline) > > > > > > (define input-from (make-parameter #f)) > > > > > > (command-line > > #:program "sample" > > #:once-each > > [("-i" "--input-file") > > i > > "Use <input_file> as the input file." > > (input-from i)] > > #:args (file) > > (printf "my argument is: ~a\n" file) > > ;; do things with `file` and `input-from` here > > ) > > > > > > On Tue, Oct 11, 2016 at 9:24 PM, Ian Thomas <i.th...@me.com> wrote: > > I'm trying to add a simple command line interface to a program and receive > > the following error: > > > > > > > > parse-command-line: expected argument of type <table as a list of > > flag-list/procedure pairs (spec-line help list strings must match procedure > > arguments)>; given: '((once-each (("-i" "--input\ > > > > -file") #<procedure:...sis/com_line.rkt:12:25> ("Use <input_file> as the > > input file.")))) > > > > context...: > > > > > > > > The command should take a single flag and an input file as arguments. Code > > below. Any help would be much appreciated. > > > > > > > > #lang racket > > > > > > > > (require racket/base > > > > racket/cmdline) > > > > > > > > (parse-command-line "com_line" > > > > ;; argv > > > > (current-command-line-arguments) > > > > ;; table > > > > `((once-each > > > > [("-i" "--input-file") > > > > ,(lambda (flag in) (displayln "Using <in>")) > > > > ("Use <input_file> as the input file.")])) > > > > ;; finish-proc > > > > (lambda (flag-accum file) file) > > > > ;; help-proc > > > > (lambda () (displayln "com_line -i | --input-file input > > file")) > > > > ;; unknown-proc > > > > (lambda (unknown_flag) (displayln "Unknown flag: > > <unknown_flag>"))) > > > > > > > > -- > > > > You received this message because you are subscribed to the Google Groups > > "Racket Users" group. > > > > To unsubscribe from this group and stop receiving emails from it, send an > > email to racket-users...@googlegroups.com. > > > > For more options, visit https://groups.google.com/d/optout. > > I'd like to handle usage - help-proc - and unknown flags - unknown-proc - and > the documentation states you need to use parse-command-line and not > command-line to achieve this.
I've re-read the documentation and added some more arguments to the parse-command-line function, and now I think I'm almost there. Error messages immediately below: updated code follows. $ ./com_line --input-file hacking.rkt Using <in> com_line: expects 1 <Input file.> on the command line, given 0 arguments $ ./com_line --help com_line -i | --input-file input file com_line: expects 1 <Input file.> on the command line, given 0 arguments #lang racket (require racket/base racket/cmdline) (parse-command-line "com_line" ;; argv (current-command-line-arguments) ;; table `((once-each [("-i" "--input-file") ,(lambda (flag in) (displayln "Using <in>")) ("Use input file as the input file." "Input file.")])) ;; finish-proc (lambda (flag-accum file) file) ;; arg-help-strs '("Input file.") ;; help-proc (lambda (flag) (displayln "com_line -i | --input-file input file")) ;; unknown-proc (lambda (unknown_flag) (displayln "Unknown flag: <unknown_flag>"))) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.