shtk_config man page on DragonFly

Man page or keyword search:  
man Server   44335 pages
apropos Keyword Search (all sections)
Output format
DragonFly logo
[printable version]

SHTK_CONFIG(3)		 BSD Library Functions Manual		SHTK_CONFIG(3)

NAME
     config — Configuration file processing and queries

LIBRARY
     shtk_import config

DESCRIPTION
     The config module provides a mechanism to load configuration files and to
     handle any settings defined in them.

     Configuration files are simply shell scripts that can define a set of
     predefined variables.

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
     shtk(3), shtk_config_get(3), shtk_config_get_bool(3),
     shtk_config_get_default(3), shtk_config_has(3), shtk_config_include(3),
     shtk_config_init(3), shtk_config_load(3), shtk_config_override(3),
     shtk_config_run_hook(3), shtk_config_set(3), shtk_config_unset(3)

HISTORY
     config first appeared in shtk 1.0.

BSD			       November 6, 2014				   BSD
[top]

List of man pages available for DragonFly

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net