tclmain - Run Tcl application via the package name.


DDG 2023-01-26: tclmain is a standalone application which allows you to run applications directly from the package instead of creating separate executables placed in directories belonging to the PATH variable. This approach is based on Python's syntax "python3 -m modulename" which will execute the file "__main.py__" in the package directory.



These examples require the to place the files in the examples directory from the Github repository into a folder ~/.config/tclmain.

$ tclmain -i dummy
usage: tclmain [-h] [-m pkgname command ?arg1 arg2 ...?]
               [-i pkgname]

Error: package dummy does not exists!

$ tclmain -m Markdown 
Missing command for package Markdown.
Available commands are: main
$  tclmain -m Markdown main
Usage: tclmain -m Markdown main mdfile|- ?htmlfile|-?
       instead of filenames as well - can be used to indicate stdin and stdout

   echo '**Hello World!**' |  tclmain -m Markdown main - out.html
$  echo '**Hello world!**'  | tclmain -m Markdown main -
<p><strong>Hello world!</strong></p>

$ tclmain -i ctext
package:  ctext
version:  3.2
location: /usr/share/tcl8.6/tklib0.5/ctext

$ tclmain -m ctext                                                     
Package ctext provides no commands.

$ tclmain -i Tk
package:  Tk
version:  8.6.12
location: /usr/lib64

$ tclmain -m Tk                                                       
Missing command for package Tk.
Available commands are: demo

$ tclmain -m Tk demo
# should run the Tk demo

Below is the file Tk_demo.tcl which is the code required for the last example. This code must be placed in a file: ~/config/tclmain/Tk_demo.tcl and then the example below should work.

#!/usr/bin/env tclsh

foreach folder $auto_path {
    set demo [file join $folder demos widget]
    if {[file exists $demo]} {
        source $demo


DDG 2023-01-26: The principal idea is to simplify development of packages and applications and providing a standard interface for the user to run the application, to get help or to execute some demos. The package developer just place files like pkgname_main.tcl, pkgname_demo.tcl, pkgname_help.tcl in the package folder. Which would allow to run commands main, demo or help for the package or the command line application. There is as well a facility to add such files to a config folder in its own home directory to add these unified syntax to packages which does not (yet) provide this functionality.