CmdArgs

CmdArgs
Login

Cmdargs is a Tcl extension that provides a command-line interface to any user-created proc.

The extension is easy to use. Install it by copying the appropriate cmdargs1.0 directory (in tcl8/tcl9 and unix/win-msys subdirectory) to the corresponding Tcl package directory.

Use "package require cmdargs" in your Tcl source file. Then call CmdArgs::chkArgs in your proc as follows:

    package require cmdargs
    proc Test {args} {
        <b>CmdArgs::chkArgs $args -dstr {mydog "Fluffy" mycat "PurrBall"} -dnum {dogfood 53 catfood 21}</b>
        # use values 
        ...
    }

    The syntax is quite simple: first argument is the list of command line parameters, 
    this is easily captured by the args facility.
    
    The rest of the arguments describe the options and default values.
 
    Option name becomes variable name in proc, and
    variables are set to the default values:
      $dog => Fluffy, $cat => PurrBall, $dogfood => 53, $catfood => 21

    The proc is called with command line input and
    option variables are set to new values:
      % Test -catfood 128 -cat FurBall
      % puts "Yikes! '$mycat''s food costs \$'$catfood'/month now!" 
        Yikes! 'FurBall''s food costs $'128'/month now!

    Options NOT used on cmd line contain their initial defaults
      % puts "But '$mydog' still eats kibble worth \$'$dogfood'/month."     
        But 'Fluffy' still eats kibble worth $'53'/month.

That's most of what you need to know! For all the gory details, here's the Documentation. ;)

Source and binaries are available for Download.