commit a3ddc31bfe182b93781f5d0eabe4edeb3674ba7d
parent b88758e48e4e916af3119f2de248d1222505d29c
Author: nolash <dev@holbrook.no>
Date: Mon, 13 Sep 2021 08:47:00 +0200
Add dumpconfig command flag
Diffstat:
4 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/chainlib/cli/arg.py b/chainlib/cli/arg.py
@@ -97,6 +97,9 @@ class ArgumentParser(argparse.ArgumentParser):
self.add_argument(arg[0], nargs='?', type=arg[1], help=arg[2])
args = super(ArgumentParser, self).parse_args(args=argv)
+ if args.dumpconfig:
+ return args
+
if len(self.pos_args) == 1:
arg = self.pos_args[0]
argname = arg[0]
@@ -131,6 +134,7 @@ class ArgumentParser(argparse.ArgumentParser):
if arg_flags & Flag.CONFIG:
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('--dumpconfig', action='store_true', help='Output configuration and quit. Use with --raw to omit values and output schema only.')
if arg_flags & Flag.WAIT:
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')
diff --git a/chainlib/cli/config.py b/chainlib/cli/config.py
@@ -1,6 +1,7 @@
# standard imports
import logging
import os
+import sys
# external imports
import confini
@@ -35,7 +36,7 @@ class Config(confini.Config):
default_fee_limit = 0
@classmethod
- def from_args(cls, args, arg_flags=0x0f, env=os.environ, extra_args={}, base_config_dir=None, default_config_dir=None, user_config_dir=None, default_fee_limit=None, logger=None, load_callback=logcallback):
+ def from_args(cls, args, arg_flags=0x0f, env=os.environ, extra_args={}, base_config_dir=None, default_config_dir=None, user_config_dir=None, default_fee_limit=None, logger=None, load_callback=logcallback, dump_writer=sys.stdout):
"""Parses arguments in argparse.ArgumentParser instance, then match and override configuration values that match them.
The method processes all known argument flags from chainlib.cli.Flag passed in the "args" argument.
@@ -155,6 +156,9 @@ class Config(confini.Config):
config = confini.Config(config_dir, env_prefix=env_prefix, override_dirs=override_config_dirs)
config.process()
+ config.add(getattr(args, 'raw'), '_RAW')
+
+
args_override = {}
if arg_flags & Flag.PROVIDER:
@@ -205,8 +209,6 @@ class Config(confini.Config):
if arg_flags & Flag.EXEC:
config.add(getattr(args, 'executable_address'), '_EXEC_ADDRESS')
- config.add(getattr(args, 'raw'), '_RAW')
-
if arg_flags & Flag.CONFIG:
config.add(getattr(args, 'namespace'), 'CONFIG_USER_NAMESPACE')
@@ -227,6 +229,21 @@ class Config(confini.Config):
if existing_r == None or r != None:
config.add(r, v, exists_ok=True)
+ if getattr(args, 'dumpconfig'):
+ config_keys = config.all()
+ with_values = not config.get('_RAW')
+ for k in config_keys:
+ 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)
+
if load_callback != None:
load_callback(config)
diff --git a/chainlib/cli/rpc.py b/chainlib/cli/rpc.py
@@ -47,6 +47,9 @@ class Rpc:
:rtype: chainlib.connection.RPCConnection
:returns: An established rpc connection
"""
+ if config.get('RPC_SCHEME') != 'http':
+ raise NotImplementedError('Only http(s) scheme is implemented for RPC connections at this time')
+
auth = None
if config.get('RPC_AUTH') == 'basic':
from chainlib.auth import BasicAuth
@@ -58,7 +61,7 @@ class Rpc:
self.id_generator = IntSequenceGenerator()
self.chain_spec = config.get('CHAIN_SPEC')
- self.conn = self.constructor(url=config.get('RPC_HTTP_PROVIDER'), chain_spec=self.chain_spec, auth=auth)
+ self.conn = self.constructor(url=config.get('RPC_PROVIDER'), chain_spec=self.chain_spec, auth=auth)
return self.conn
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = chainlib
-version = 0.0.9a7
+version = 0.0.9a9
description = Generic blockchain access library and tooling
author = Louis Holbrook
author_email = dev@holbrook.no