Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Parsing arbitrary arguments of a proc (::cmdline::getopt ??)

74 views
Skip to first unread message

Koszalek Opalek

unread,
Nov 23, 2009, 8:06:54 AM11/23/09
to
I'd like to use ::cmdline::getopt to parse arguments of a procedure.
This is different from what ::cmdline::getopt is intended for - I do
not parse arguments of #!/usr/bin/tclsh script but arguments of a
proc
invoked inside an interactive Tcl shell.

That is I'd like to be able to do this:

proc my_proc_with_arbitrary_args {args} {

set options {
{a "set the atime only"}
{m "set the mtime only"}
{c "do not create non-existent files"}
{r.arg "" "use time from ref_file"}
{t.arg -1 "use specified time"}
}
set usage ": MyCommandName \[options] filename ...\noptions:"
array set params [::cmdline::getoptions args $options $usage]
}

This does not work beacause of hard-coded references to argv0, argv
inside ::cmdline::getopt. Can I work around this issue somehow?

I wrote my own procedure for parsing the cmd-line (even before
I knew ::cmdline::getopt existed) but if there is some standard
argument parsing module I'd be happy to try it.

K.

Harald Oehlmann

unread,
Nov 23, 2009, 8:35:59 AM11/23/09
to
Hi K. !

On 23 Nov., 14:06, Koszalek Opalek <koszalekopa...@interia.pl> wrote:
> I'd like to use ::cmdline::getopt to parse arguments of a procedure.
> This is different from what ::cmdline::getopt is intended for - I do
> not parse arguments of #!/usr/bin/tclsh script but arguments of a
> proc

Within standard tcl, there is the package opt which allows to define
procs with arguments as you asked for.
Unfortunately, there is not much doc. I used the source code in lib/
tclxxx/opt

See also at:
http://wiki.tcl.tk/1539

Hope this helps,
Harald

0 new messages