Package: click-config-file
Easily add configuration file support to yourClickapplications by adding a single
no-arguments decorator.Basic usageclick-config-file is designed to be a usable by simply adding the
appropriate decorator to your command without having to supply any
mandatory arguments. It comes with a set of sensible defaults that
should just work for most cases.Given this application:@click.command()@click.option('--name',default='World',help='Who to greet.')@click_config_file.configuration_option()defhello(name):click.echo('Hello{}!'.format(name))Runninghello--helpwill give you this:Usage: hello [OPTIONS]

Options:
  --name TEXT    Who to greet.
  --config PATH  Read configuration from PATH.
  --help         Show this message and exit.If the configuration file does not exist, runninghellowill do what
you expect:Hello World!With this configuration file:name="Universe"Callinghellowill also do what you expect:Hello Universe!Callinghello--nameMultiversewill override the configuration file
setting, as it should:Hello Multiverse!The default name for the configuration file option is--config.Command line and environment options will override the configuration
file options. Configuration file options override default options. So
the resolution order for a given option is: CLI > Environment >
Configuration file > Default.OptionsAlthoughconfiguration_optionis designed to work without any mandatory
arguments, some optional parameters are supported:implicitDefault:TrueBy defaultconfiguration_optionwill look for a configuration file
even if no value for the configuration option was provided either via
a CLI argument or an environment variable. In this case the value will
be set implicitly fromcmd_nameandconfig_file_nameas
described below.If set toFalsethe configuration file settings will only be applied
when a configuration file argument is provided.cmd_nameDefault:ctx.cmd_infoThe name of the decorated command. When implicitly creating a
configuration file argument, the application directory containing the
configuration file is resolved by callingclick.get_app_dir(cmd_name).This defaults to the name of the command as determined by click.config_file_nameDefault:configWhenimplicitis set toTrue, this argument provides the name of the
configuration file inside the application directory.In addition to the arguments above, all arguments forclick.option()andclick.File()are supported.Supported file formatsBy default click-config-file supports files formatted according toConfigobj’s unrepr
mode.You can add support for additional configuration providers by setting
theproviderkeyword argument. This argument expects a callable that
will take the configuration file path and command name as arguments and
returns a dictionary with the provided configuration options.The command name is passed in order to allow for a shared configuration
file divided by sections for each command.For example, this will read the configuration options from a shared JSON
file:defmyprovider(file_path,cmd_name):withopen(file_path)asconfig_data:returnjson.load(config_data)[cmd_name]@click.command()@click.option('--name',default='World')@click_config_file.configuration_option(provider=myprovider)defhello(name):click.echo('Hello{}!'.format(name))Installationpip installclick-config-fileWhy?There are several existing implementations of config file support for
Click, however they seem to lack one or more of the following features:Sensible defaultsProper handling of resolution orderSupport for multi value options, multiple options or a combination
of bothIn contrast this module may lack some more sophisticated features of the
other implementations. This is a deliberate choice as this module is
intended to be a simple option that Just Works with sensible defaults.