Configuration -- Configuration variable management


package require Configuration

Configuration::Set configname value

Configuration::get configname ?default?

Configuration::readEnvironment confname envname ?default?

Configuration::writeConfigFile channel

Configuration::readConfigFile path


This package maintains a set of configuration variables. The configuration variables are maintained in a separate namespace so that they cannot accidently collide with other existing global variables.

In addition to simple set and get operations environment variables can be checked for existence and used to set the value of variables. Configuration files can also be read and written, however it would probably be better to use the StateManager package for that instead.


The Configuration package provides procs in the ::Configuration:: namespace:

::Configuration::readConfigfile path

The configuration file at path is read in with the namespace set to the configuration variable namespace. The file is sourced into the current interpreter (one reason that StateManager is a better choice). The source is done at the global level.

The configuration file is presumed to only contain set commands. This is not enforced however.

::Configuration::readEnvironment confname envname ?default?

If the environment variable envname is defined, the variable confname in the configuration namespace is set to the value of envname. If envname does not exist, then confname is set to default. If the default parameter is not supplied, and envname is not defined, the variable is defined, but set to the empty string.

::Configuration::Set confname value

Sets the configuration variable named confname to value. If confname has not yet been defined this will create it.

::Configuration::::get confname ?default?

If confname is already a defined configuration parameter its value is returned. If not, the value of default is returned. If not supplied default will be the empty string.

::Configuration::writeConfigFile channel

Writes the configuration out to the open channel. What this means is that a .tcl script consisting of simple set commands will be written that can be read in with ::Configuration::readConfigFile to restore the state of all defined configuration variables as they are defined at the time ::Configuration::writeConfigFile is called.