From a3eb147494b43b5cd762c56419d772c65877c8e0 Mon Sep 17 00:00:00 2001 From: Satoru SATOH Date: Sun, 26 Oct 2014 00:00:26 +0900 Subject: [PATCH] update 'anyconfig_cli --help' output and add an example of ignore_missing use case in REAMDE --- README.rst | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/README.rst b/README.rst index 7b35d4a1..e8940194 100644 --- a/README.rst +++ b/README.rst @@ -113,12 +113,16 @@ To load multiple config files:: # Specify config files by list of paths: data1 = anyconfig.load(["/etc/foo.d/a.json", "/etc/foo.d/b.json"]) + # Similar to the above but all or one of config files are missing: + data2 = anyconfig.load(["/etc/foo.d/a.json", "/etc/foo.d/b.json"], + ignore_missing=True) + # Specify config files by glob path pattern: - data2 = anyconfig.load("/etc/foo.d/*.json") + data3 = anyconfig.load("/etc/foo.d/*.json") - # Similar to above, but parameters in the former config file will be simply + # Similar to the above, but parameters in the former config file will be simply # overwritten by the later ones: - data3 = anyconfig.load("/etc/foo.d/*.json", merge=anyconfig.MS_REPLACE) + data4 = anyconfig.load("/etc/foo.d/*.json", merge=anyconfig.MS_REPLACE) On loading multiple config files, you can choose 'strategy' to merge configurations from the followings: @@ -208,12 +212,12 @@ There is a CLI frontend 'anyconfig_cli' to demonstrate the power of this library It can process various config files and output a merged config file:: - $ anyconfig_cli -h + ssato@localhost% anyconfig_cli -h Usage: anyconfig_cli [Options...] CONF_PATH_OR_PATTERN_0 [CONF_PATH_OR_PATTERN_1 ..] Examples: anyconfig_cli --list - anyconfig_cli -I yaml /etc/xyz/conf.d/a.conf + anyconfig_cli -I yaml -O yaml /etc/xyz/conf.d/a.conf anyconfig_cli -I yaml '/etc/xyz/conf.d/*.conf' -o xyz.conf --otype json anyconfig_cli '/etc/xyz/conf.d/*.json' -o xyz.yml \ --atype json -A '{"obsoletes": "sysdata", "conflicts": "sysdata-old"}' @@ -221,38 +225,45 @@ It can process various config files and output a merged config file:: -A obsoletes:sysdata;conflicts:sysdata-old anyconfig_cli /etc/foo.json /etc/foo/conf.d/x.json /etc/foo/conf.d/y.json anyconfig_cli '/etc/foo.d/*.json' -M noreplace + anyconfig_cli '/etc/foo.d/*.json' --get a.b.c + anyconfig_cli '/etc/foo.d/*.json' --set a.b.c=1 Options: + --version show program's version number and exit -h, --help show this help message and exit -L, --list List supported config types -o OUTPUT, --output=OUTPUT Output file path -I ITYPE, --itype=ITYPE - Select type of Input config files from ini, json, - yaml, xml [Automatically detected by file ext] + Select type of Input config files from ini, json, xml, + yaml [Automatically detected by file ext] -O OTYPE, --otype=OTYPE Select type of Output config files from ini, json, - yaml, xml [Automatically detected by file ext] + xml, yaml [Automatically detected by file ext] -M MERGE, --merge=MERGE Select strategy to merge multiple configs from - noreplace, merge_dicts_and_lists, merge_dicts, replace + replace, noreplace, merge_dicts, merge_dicts_and_lists [merge_dicts] -A ARGS, --args=ARGS Argument configs to override - --atype=ATYPE Explicitly select type of argument config from ini, - json, yaml, xml. If this option is not set, original - parser is used: 'K:V' will become {K: V}, + --atype=ATYPE Explicitly select type of argument to provide configs + from ini, json, xml, yaml. If this option is not set, + original parser is used: 'K:V' will become {K: V}, 'K:V_0,V_1,..' will become {K: [V_0, V_1, ...]}, and 'K_0:V_0;K_1:V_1' will become {K_0: V_0, K_1: V_1} (where the tyep of K is str, type of V is one of Int, str, etc. - --get=GET Specify key path to get part of config, for example, - if a config {'a': {'b': {'c': 0, 'd': 1}}} '--get - a.b.c' gives 0 and '--get a.b' gives {'c': 0, 'd': 1}. + --get=GET Specify key path to get part of config, for example, ' + --get a.b.c' to config {'a': {'b': {'c': 0, 'd': 1}}} + gives 0 and '--get a.b' to the same config gives {'c': + 0, 'd': 1}. + --set=SET Specify key path to set (update) part of config, for + example, '--set a.b.c=1' to a config {'a': {'b': {'c': + 0, 'd': 1}}} gives {'a': {'b': {'c': 1, 'd': 1}}}. + -x, --ignore-missing Ignore missing input files -s, --silent Silent or quiet mode -q, --quiet Same as --silent option -v, --verbose Verbose mode - $ - + ssato@localhost% Build & Install ================