The question is not terribly clear. Is the question "what mechanisms exist?", "what are the conventions for arguments and formats?", or "how you should I mix and match?"?
There are several pretty standard ways (at least in the unix world):
- environment variables
- configuration files
- command line arguments
- as a subset of the above, config files specified on the command line
To choose what methods to use for your own program, examine many programs from the canon of accepted practice before you freeze your own choices, read some blogs, read some books...
Configuration files are probably the most portable across operating systems.
The treatment can get fairly complicated. If the command line arguments might affect the interpretation of config files or environment variable, but you still want the command line to overrule the other mechanisms (a good idea) you may need three passes:
- Parse the command line and set any variables which affect further settings (say which config file to read)
- Handle config files and environment variable (what order?)
- Re-run the command line to override all other settings.
In the unix tradition look at getopt
and getopt_long
. Also consider tools like gengetopt
You can simplify you config file problem by making them shell scripts that set environment variables (but this locks you into a unix model). Parsing plain text is easy and cross platform, but makes more code to write. Using a standard format and a library puts requirements on your user's build environment, but should save on bugs and confusion.
If your configuration environment is complicated, it is very helpful to encapsulate the configuration state in a structure which can be passed around as needed. This is the approach taken by gengetopt
, and I have found it to be useful.