Add omit sections for config exporter

This commit is contained in:
nolash 2021-11-10 09:56:51 +01:00
parent 39478d9c3c
commit 1067c8494e
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 23 additions and 15 deletions

View File

@ -15,4 +15,4 @@ url = https://gitlab.com/chaintools/chainlib
url=https://holbrook.no url=https://holbrook.no
[license] [license]
WTFPL=2 GPL=3+

View File

@ -144,7 +144,7 @@ class ArgumentParser(argparse.ArgumentParser):
if arg_flags & Flag.CONFIG: if arg_flags & Flag.CONFIG:
self.add_argument('-c', '--config', type=str, default=env.get('CONFINI_DIR'), help='Configuration directory') self.add_argument('-c', '--config', type=str, default=env.get('CONFINI_DIR'), help='Configuration directory')
self.add_argument('-n', '--namespace', type=str, help='Configuration namespace') self.add_argument('-n', '--namespace', type=str, help='Configuration namespace')
self.add_argument('--dumpconfig', action='store_true', help='Output configuration and quit. Use with --raw to omit values and output schema only.') self.add_argument('--dumpconfig', type=str, choices=['env', 'ini'], help='Output configuration and quit. Use with --raw to omit values and output schema only.')
if arg_flags & Flag.WAIT: if arg_flags & Flag.WAIT:
self.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed') self.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
self.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed') self.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')

View File

@ -239,18 +239,26 @@ class Config(confini.Config):
logg.debug('added {} to {}'.format(r, v)) logg.debug('added {} to {}'.format(r, v))
if getattr(args, 'dumpconfig', None): if getattr(args, 'dumpconfig', None):
config_keys = config.all() if args.dumpconfig == 'ini':
with_values = not config.get('_RAW') from confini.export import ConfigExporter
for k in config_keys: exporter = ConfigExporter(config, target=sys.stdout, doc=False)
if k[0] == '_': exporter.export(exclude_sections=[config])
continue elif args.dumpconfig == 'env':
s = k + '=' from confini.env import export_env
if with_values: export_env(config)
v = config.get(k)
if v != None: # config_keys = config.all()
s += str(v) # with_values = not config.get('_RAW')
s += '\n' # for k in config_keys:
dump_writer.write(s) # if k[0] == '_':
# continue
# s = k + '='
# if with_values:
# v = config.get(k)
# if v != None:
# s += str(v)
# s += '\n'
# dump_writer.write(s)
sys.exit(0) sys.exit(0)
if load_callback != None: if load_callback != None:

View File

@ -6,7 +6,7 @@ name=chainlib
license=WTFPL2 license=WTFPL2
author_email=dev@holbrook.no author_email=dev@holbrook.no
description=Generic blockchain access library and tooling description=Generic blockchain access library and tooling
version=0.0.10 version=0.0.11
url=https://gitlab.com/chaintools/chainlib url=https://gitlab.com/chaintools/chainlib
author=Louis Holbrook author=Louis Holbrook