[plt-scheme] Command Line Processing

From: Doug Williams (m.douglas.williams at gmail.com)
Date: Fri Jun 19 11:53:57 EDT 2009

I am writing an application that uses command-line (from scheme/cmdline) to
parse command line arguments. Consider the following simple test-app.ss

#lang scheme

(define verbose-mode (make-parameter #f))

(define input-file (make-parameter "input.xml"))

(define output-directory (make-parameter "output"))

 #:program "test-app"
 [("-v" "--verbose") "Generate with verbose messages"
                     (verbose-mode #t)]
 [("-i" "--input-file") if
                        "Input file"
                        (input-file if)]
 [("-o" "--output-directory") od
                              "Output directory"
                              (output-directory od)]
 #:args () (void))

(printf "Test Command-Line Application~n")
(printf "  verbose-mode = ~a~n" (verbose-mode))
(printf "  input-file = ~s~n" (input-file))
(printf "  output-directory = ~s~n" (output-directory))

When I make an executable of this using Scheme>Create Executable ... and
select Stand-alone and MzScheme, I can get it to work, but I have some

Why do I need "--" before my arguments? [They seem to be parsed by MzScheme
if I don't.]

For example:

>test-app -v
Welcome to MzScheme v4.2 [3m], Copyright (c) 2004-2009 PLT Scheme Inc.
Test Command-Line Application
  verbose-mode = #f
  input-file = "input.xml"
  output-directory = "output"

I get the MzScheme banner and my application doesn't see the "-v". So
presumable, MzScheme parsed it.

>test-app -- -v
Test Command-Line Application
  verbose-mode = #t
  input-file = "input.xml"
  output-directory = "output"

Works as expected.

Is there any way to get this behavior without the "--"? Should I be using
mzc to compile it instead of DrScheme?

It seems to work as expected if I select Launcher when using Scheme>Create
Executable ....

What is the best way to test programs using command-line during development?
It seems I'd like to be able to tell if I am NOT being executed from the
command line and do some alternate processing in that case - either use the
defaults or use current-command-line-arguments to set specific values and
let command-line parse those.

Any help/thoughts would be welcome.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090619/50589dbc/attachment.html>

Posted on the users mailing list.