I've just ported a small sript to Racket to investigate Racket as a
scripting language for cli tasks. (My past Racket experiences have
really only been with the HTDP languages.) I was quite happy with the
process and the results, but I have one question I haven't been able to
figure out on my own:

How can I specify a mandatory argument such that without the argument
the script will stop, possibly with an error, and preferably display the
help?

In the following, I would like to make the "-d" flag non-optional, or
alternatively specify it as a required non-flag argument. Perhaps I just
need to specify it as a non-flag argument and raise my own errors? Or is
there a built-in way that I've not found?

------------------------------------------------------------------------

(define slow-copy
  (command-line
   #:program "slowcp"
   #:usage-help "\n Copy <files> at a limited rate"
   #:once-each
   [("-t") time "the duration of <time> in seconds between each copy; default: 
5"
           (copy-delay (string->number time))]
   [("-d") dest "the directory to which <files> will be copied; default: ."
           (destination dest)]
   #:args files
   files
   ))

------------------------------------------------------------------------

» the complete script is here:
» https://github.com/tuirgin/racket-cli/blob/master/slowcp.rkt

Any criticism or pointers towards a more idiomatic implementation are
definitely welcome.

-- 
Christopher D. Walborn      :      http://laconic-prolixity.blogspot.com
------------------------------------------------------------------------
1st Gent.: Our deeds are fetters that we forge ourselves.
2nd Gent.: Ay, truly: but I think it is the world
           That brings the iron. (Middlemarch, George Eliot)

-- 
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.

Reply via email to