chainlib

Generic blockchain access library and tooling
Log | Files | Refs | README | LICENSE

commit 6900c4f9a187918b73b936d6423a6321791e6656
parent 91bd428c22d3b608d8a40e5f86bdfa5591d69f7a
Author: lash <dev@holbrook.no>
Date:   Thu, 24 Feb 2022 19:00:28 +0000

Allow adding of new args through overrides in man generator

Diffstat:
Mchainlib/cli/man.py | 37++++++++++++++++++++++++++++---------
Mscripts/chainlib-man.py | 20++++++++++++++------
2 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/chainlib/cli/man.py b/chainlib/cli/man.py @@ -39,12 +39,12 @@ def format_groff(k, v, arg=None, typ='arg'): class DocEntry: - def __init__(self, *args, argvalue=None, typ='arg'): + def __init__(self, *args, typ='arg'): self.flags = args - self.v = argvalue self.render = self.get_empty self.groff = None self.typ = typ + self.v = None def __check_line_default(self, m): @@ -68,6 +68,10 @@ class DocEntry: self.groff = v + def set_groff_argvalue(self, argvalue): + self.v = '\\fI' + argvalue + '\\fP' + + def get_groff(self): v = self.groff if v == None: @@ -113,10 +117,19 @@ class DocGenerator: return s - def override_arg(self, k, v, args): + def set_arg(self, k, v, flags, argvalue=None): + o = DocEntry(*flags) + o.set_groff_argvalue(argvalue) + o.set_groff(v) + self.docs[k] = o + + + def override_arg(self, k, v, args, argvalue=None): o = self.docs[k] #g.docs[v[0]].groff = v[1].rstrip() o.set_groff(v) + if argvalue != None: + o.set_groff_argvalue(argvalue) l = len(args) if l > 0: o.flags = [] @@ -147,16 +160,19 @@ class DocGenerator: self.docs['vv'] = o if self.arg_flags & Flag.CONFIG: - o = DocEntry('-c', '--config', argvalue='config_dir') + o = DocEntry('-c', '--config') o.set_groff('Load configuration files from given directory. All files with an .ini extension will be loaded, of which all must contain valid ini file data.') + o.set_groff_argvalue('config_dir') self.docs['c'] = o - o = DocEntry('-n', '--namespace', argvalue='namespace') + o = DocEntry('-n', '--namespace') o.set_groff('Load given configuration namespace. Configuration will be loaded from the immediate configuration subdirectory with the same name.') + o.set_groff_argvalue('namespace') self.docs['n'] = o - o = DocEntry('--dumpconfig', argvalue='format') + o = DocEntry('--dumpconfig') o.set_groff('Output configuration settings rendered from environment and inputs. Valid arguments are \\fIini\\fP for ini file output, and \\fIenv\\fP for environment variable output. See \\fBCONFIGURATION\\fP.') + o.set_groff_argvalue('format') self.docs['dumpconfig'] = o @@ -204,8 +220,9 @@ class DocGenerator: if self.arg_flags & Flag.CHAIN_SPEC: - o = DocEntry('-i', '--chain-spec', argvalue='chain_spec') + o = DocEntry('-i', '--chain-spec') o.set_groff('Chain specification string, in the format <engine>:<fork>:<chain_id>:<common_name>. Example: "evm:london:1:ethereum".') + o.set_groff_argvalue('chain_spec') self.docs['i'] = o self.envs['i'] = 'RPC_CREDENTIALS' @@ -223,13 +240,15 @@ class DocGenerator: if self.arg_flags & Flag.KEY_FILE: - o = DocEntry('-y', '--key-path', argvalue='path') + o = DocEntry('-y', '--key-path') o.set_groff('Path to signing key.') + o.set_groff_argvalue('path') self.docs['y'] = o self.envs['y'] = 'WALLET_KEY_FILE' - o = DocEntry('--passphrase-file', argvalue='path') + o = DocEntry('--passphrase-file') o.set_groff('Path to file containing password to unlock key file') + o.set_groff_argvalue('path') self.docs['passphrasefile'] = o diff --git a/scripts/chainlib-man.py b/scripts/chainlib-man.py @@ -118,20 +118,23 @@ def apply_override(g, override_dir): s = f.readline() if len(s) == 0: break - v = s.split('\t', maxsplit=2) + v = s.split('\t', maxsplit=4) fargs = None try: fargs = v[2].rstrip().split(',') except IndexError: fargs = [] - g.override_arg(v[0], v[1], fargs) + argvalue = None + if len(v) == 4: + argvalue = v[3] + try: + g.override_arg(v[0], v[1], fargs, argvalue=argvalue) + except KeyError: + logg.info('adding not previously registered key {} flags: {}'.format(v[0], ','.join(fargs))) + g.set_arg(v[0], v[1], fargs, argvalue=argvalue) f.close() return g -g = apply_override(g, args.source_dir) - -ge = EnvDocGenerator(flags, override=args.overrides_env_dir) -ge.process() def get_head(tool_name, source_dir): header_file = os.path.join(source_dir, tool_name + '.head.groff') @@ -169,6 +172,11 @@ def get_custom(tool_name, source_dir): return custom +g = apply_override(g, args.source_dir) + +ge = EnvDocGenerator(flags, override=args.overrides_env_dir) +ge.process() + head = get_head(toolname, args.source_dir) examples = get_examples(toolname, args.source_dir) custom = get_custom(toolname, args.source_dir)