[plt-scheme] Command Line Processing

From: Paulo J. Matos (pocmatos at gmail.com)
Date: Fri Jun 19 12:39:03 EDT 2009

On Fri, Jun 19, 2009 at 4:53 PM, Doug
Williams<m.douglas.williams at gmail.com> wrote:
> I am writing an application that uses command-line (from scheme/cmdline) to
> parse command line arguments. Consider the following simple test-app.ss
> program:
>
> #lang scheme
>
> (define verbose-mode (make-parameter #f))
>
> (define input-file (make-parameter "input.xml"))
>
> (define output-directory (make-parameter "output"))
>
> (command-line
>  #:program "test-app"
>  #:once-each
>  [("-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
> questions.
>
> 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.
>

It seems to have definitely to do with the fact that you are creating
it inside DrScheme, because if you do in a command line (your file is
saved as test.scm):
pmatos at pocm06r ~ $ ~/Applications/plt/plt-4.2/bin/mzc --exe test test.scm
pmatos at pocm06r ~ $ ./test -v
Test Command-Line Application
  verbose-mode = #t
  input-file = "input.xml"
  output-directory = "output"

Cheers,

Paulo Matos

> Thanks,
> Doug
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>



-- 
Paulo Jorge Matos - pocmatos at gmail.com
http://www.pmatos.net


Posted on the users mailing list.