- parse-cmdlnprocedure
- in - CMDLINE - full command line as list of strings, such as returned by command-line (from scheme.process-context).
- in - PRMLS - list of command line arguments for application
- Argument list in this form: '(-arg0 [default val0] -arg1 [default val1] ...). Default values are optional, otherwise defaults to #f. An argument with default of #f acts as switch. (See below example.)
- in - USAGE - optional. If given, refers to variable that contains string with usage/help info for application.
- in - VALONLY-LIST - symbol list - list of 'privileged' options having 'bare' values placed first or last on command line, not needing a preceding option argument (e.g., '-src'). The list contains option names without leading hyphen. The order of options in the list specifies the order values are inserted on the command line. When values are last on command line, the end of options must be marked with the argument '--'.
- returns two values: result (an alist), and a cmdarg procedure
- the result alist has keys as defined in PRMLS (without leading hyphen), and values that were entered on the command line or the default. If a default wasn't given for an argument in PRMLS, the default is #f. PRMLS defaults may be any value but typically are string, number, boolean types.
- the "cmdarg" procedure (can have any name) takes a key and returns its assoc value in 'result'. Conversion to a different type may be necessary. When the key doesn't exist in result, cmdarg returns #f.
A typical invocation might look like this:
;; myapp.scm (import nutils) ;; .... (define-values (res cmdarg) (parse-cmdln (command-line) '(-a #f -b 2000 -c "" -d "") usage '(c d)) (and res (let ((a* (cmdarg 'a))) (proc-a (str2bool a*)) (proc-b (obj->num (cmdarg 'b))) ...))
The application could be invoked as:
$ myapp valueC valueD -a -b 44 or equivocaly, $ myapp -a -b 44 -- valueC valueD
With this input a* would receive #t (toggling the default #f), and (cmdarg 'b) returns the string "44", converted to 44. (cmdarg 'c) returns "valueC", 'd' is associated with "valueD".