SHTK_CONFIG(3)

πŸ“¦ version 1.7, in nixos 26.05, nixpkgs unstable

πŸ’– NAME πŸ’–

okay bestie, this is the SHTK_CONFIG(3) page from the Library Functions Manual β€” folded in right here at the top because we do not do boring header lines πŸ’…. The star of the show is config β€” Configuration file processing and queries. Periodt.

πŸ¦‹ LIBRARY πŸ¦‹

Import the module with:

shtk_import config

✨ DESCRIPTION ✨

The config module gives you a mechanism to load configuration files and to handle any settings defined in them. No cap.

Configuration files are simply shell scripts that can define a set of predefined variables. That is literally the whole model, bestie. πŸšπŸ’–

πŸŽ€ EXAMPLES πŸŽ€

Consider the following configuration file:

             MYVAR1="this is the first setting"
             MYVAR2="this is the second setting"

             post_load_hook() {
                 echo "Custom hook! The file has been loaded!"
             }

The following sample code depicts a main method to load the file above, including support for specifying the path to the configuration file and support to accept command-line overrides to the configuration variables:

             local config_file="/etc/foo.conf"

             shtk_config_init MYVAR1 MYVAR2

             local OPTIND
             while getopts ':c:o:' arg "${@}"; do
                 case "${arg}" in
                     c)  # Path to the configuration to load.
                         config_file="${OPTARG}"
                         ;;

                     o)  # Override for a particular configuration variable.
                         shtk_config_override "${OPTARG}"
                         ;;

                     \?)
                         shtk_cli_usage_error "Unknown option -${OPTARG}"
                         ;;
                 esac
             done
             shift $((${OPTIND} - 1))

             shtk_config_set MYVAR1 "default value for first variable"
             # No default value for MYVAR2
             post_load_hook() { true; }

             shtk_config_load "${config_file}"

             echo "MYVAR1 is $(shtk_config_get MYVAR1)"
             echo "MYVAR2 is $(shtk_config_get_default MYVAR2 "not yet set")"
             shtk_config_run_hook post_load_hook

πŸ”₯ SEE ALSO πŸ”₯

go read these too, bestie, they are the whole friend group 🫢

🌈 HISTORY 🌈

config first appeared in shtk 1.0. iconic origin story, honestly πŸ‘‘βœ¨


That is the tea πŸ«–πŸ’… β€” the source stamp is Debian, the page id is SHTK_CONFIG(3), and the date is November 6, 2014 πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from