Fixing cmdline for Non-Terminal Usage

Working with TCL at FlightAware, I've run into more than a few frustrating bugs in the standard library packages. One that was particularly annoying was in the cmdline package, which is used for parsing command-line arguments. So I made a fork.

The problem was that the original relies on the global argv0 variable to determine the application name for error messages. This works fine when TCL is running as a standalone script from the command line, but fails completely when TCL is embedded in other applications or used in non-terminal contexts where argv0 doesn't exist. That's exactly what we do at FlightAware, where TCL runs in a server context.

Rather than go through the painful process of contributing back to the original project (which uses Fossil for version control, a tool I'd rather avoid), I created a fork that fixes this specific issue. The fix was simple but effective: remove the dependency on argv0 entirely and strip out the getArgv0 function that was causing the problem.

The result is a drop-in replacement for the standard cmdline package that works in all contexts, not just terminal applications. You can find it at github.com/thornjad/cmdline.

This is exactly the kind of bug that makes working with TCL packages frustrating. The ecosystem has been stagnant for years, and we're stuck with these kinds of limitations until the language gets off of Fossil and into the modern world..