On Wednesday, October 12, 2016 at 3:15:11 PM UTC-4, Ian Thomas wrote: > On Wednesday, October 12, 2016 at 10:19:28 AM UTC-4, Ben Greenman wrote: > > Alright, here's something that I think does what you want. > > > > > > > > #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) (displayln "Using <in>")) > > ("Use input file as the input file.")])) > > ;; finish-proc > > (lambda (flag-accum file) file) > > ;; arg-help-strs > > '("Input file.") > > ;; help-proc > > (lambda (flag) (raise-user-error "com_line -i | --input-file input file"))) > > > > > > ;; $ ./com_line --input-file "hacking.rkt" > > ;; Using <in> > > ;; "hacking.rkt" > > > > > > ;; $ ./com_line --help > > ;; com_line -i | --input-file input file > > > > > > > > The code in your last message expects 1 flag, 1 argument to the flag > > (`in`), and 1 `file` argument. > > Okay - I've figured this out. Output from testing below. I'll add in exit > codes for the help-proc and unknown-proc so the finish-proc is never executed > in cases where the user asks for help or uses an unknown flag. I'd rather > return exit codes instead of raising an error as this code will likely be > interacting with other code via a shell. Thanks for the exception handling > suggestion.
<snip> I now believe I have a handle on how parse-command-line works. Working code that does what I want is below. Marking this post complete. Thanks #lang racket (require racket/base racket/cmdline) (require "../lib/date_analysis.rkt") (define usage "date_analyzer [-l --enable-logging] <input file>") (parse-command-line "date_analyzer" ;; argv (current-command-line-arguments) ;; table `((once-each [("-l" "--enable-logging") ,(lambda (flag) (displayln "Enable logging of errors to a log file.")) ("Enable logging to a log file.")])) ;; finish-proc (lambda (flag-accum input_file) (displayln (string-append "Run analysis on the data in " input_file)) (exit 0)) ;; arg-help-strs '("Input File") ;; help-proc (lambda (flag) (displayln usage) (exit 1)) ;; unknown-proc (lambda (unknown_flag) (displayln (string-append "Unknown flag: " unknown_flag)) (displayln usage) (exit 1))) -- 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.