Version 14 of opt

Updated 2010-05-21 08:53:49 by oehhar

Purpose: Package for parsing command options.

Does this have a manpage?

LV It does not appear to have a man page. In fact, I have seen references on other wiki pages to this package being deprecated. I'm uncertain what is considered a successor to this package.

DGP The usual successor mentioned is the cmdline package.


% package require opt
0.4.5
% OptProc OptParseTest {
        {subcommand -choice {save print} "sub command"}
        {arg1 3 "some number"}
        {-aflag}
        {-intflag      7}
        {-weirdflag                    "help string"}
        {-noStatics                    "Not ok to load static packages"}
        {-nestedloading1 true           "OK to load into nested slaves"}
        {-nestedloading2 -boolean true "OK to load into nested slaves"}
        {-libsOK        -choice {Tk SybTcl}
                                                          "List of packages that can be loaded"}
        {-precision     -int 12        "Number of digits of precision"}
        {-intval        7               "An integer"}
        {-scale         -float 1.0     "Scale factor"}
        {-zoom          1.0             "Zoom factor"}
        {-arbitrary     foobar          "Arbitrary string"}
        {-random        -string 12   "Random string"}
        {-listval       -list {}       "List value"}
        {-blahflag       -blah abc       "Funny type"}
        {arg2 -boolean "a boolean"}
        {arg3 -choice "ch1 ch2"}
        {?optarg? -list {} "optional argument"}
} {
        foreach v [info locals] {
                puts stderr [format "%14s : %s" $v [set $v]]
        }
}
OptParseTest
% OptParseTest save -4 -pr 23 -libsok SybTcl -nostatics false ch1
         args : save -4 -pr 23 -libsok SybTcl -nostatics false ch1
          Args : subcommand arg1 -noStatics -libsOK -precision arg2 arg3
         scale : 1.0
      blahflag : abc
    subcommand : save
         aflag : 0
     precision : 23
        optarg : 
     weirdflag : 0
     arbitrary : foobar
     noStatics : 1
        random : 12
nestedloading1 : 1
          arg1 : -4
nestedloading2 : 1
          arg2 : 0
        libsOK : SybTcl
          arg3 : ch1
          zoom : 1.0
       intflag : 7
        intval : 7
       listval : 

Some remarks:

  • Args: containes all specified items in the case specified by the definition.
  • -Flag: Parameters starting with das "-" are flags. They might be specified by the user. The flag names are case insensitive. Use Args to check, if a flag was specified.

Back to Official library of extensions.