From f122e2a64bcb5a1390f06a72aa028986ee9a5819 Mon Sep 17 00:00:00 2001 From: lash Date: Fri, 25 Feb 2022 11:05:56 +0000 Subject: [PATCH] Implement no-target flag --- chainlib/cli/arg.py | 3 ++- chainlib/cli/base.py | 8 ++++---- chainlib/cli/config.py | 2 +- chainlib/cli/man.py | 11 ++++++++--- scripts/chainlib-man.py | 25 +++++++++++++++++++++++-- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/chainlib/cli/arg.py b/chainlib/cli/arg.py index c140b15..382d9d8 100644 --- a/chainlib/cli/arg.py +++ b/chainlib/cli/arg.py @@ -186,7 +186,8 @@ class ArgumentParser(argparse.ArgumentParser): if arg_flags & Flag.PROVIDER: self.add_argument('-p', '--rpc-provider', dest='p', type=str, help='RPC HTTP(S) provider url') self.add_argument('--rpc-dialect', dest='rpc_dialect', type=str, help='RPC HTTP(S) backend dialect') - self.add_argument('--height', default='latest', help='Block height to execute against') + if arg_flags & Flag.NO_TARGET == 0: + self.add_argument('--height', default='latest', help='Block height to execute against') if arg_flags & Flag.RPC_AUTH: self.add_argument('--rpc-auth', dest='rpc_auth', type=str, help='RPC autentication scheme') self.add_argument('--rpc-credentials', dest='rpc_credentials', type=str, help='RPC autentication credential values') diff --git a/chainlib/cli/base.py b/chainlib/cli/base.py index 9c05995..bf00b41 100644 --- a/chainlib/cli/base.py +++ b/chainlib/cli/base.py @@ -40,10 +40,10 @@ class Flag(enum.IntEnum): # upper bound MAX = 1048576 -argflag_std_read = 0x23ff -argflag_std_write = 0x1731ff -argflag_std_base = 0x200f -argflag_std_base_read = 0xbf +argflag_std_read = 0x000023ff +argflag_std_write = 0x001731ff +argflag_std_base = 0x0000200f +argflag_std_base_read = 0x000000bf argflag_std_target = 0x0000e000 argflag_all = 0x0317f7ff diff --git a/chainlib/cli/config.py b/chainlib/cli/config.py index 430a588..2f82c31 100644 --- a/chainlib/cli/config.py +++ b/chainlib/cli/config.py @@ -224,7 +224,7 @@ class Config(confini.Config): config.censor('PASSPHRASE', 'WALLET') config.dict_override(args_override, 'cli args', allow_empty=True) - if arg_flags & Flag.PROVIDER: + if arg_flags & (Flag.PROVIDER | Flag.NO_TARGET) == Flag.PROVIDER: config.add(getattr(args, 'height'), '_HEIGHT') if arg_flags & Flag.UNSAFE: config.add(getattr(args, 'u'), '_UNSAFE') diff --git a/chainlib/cli/man.py b/chainlib/cli/man.py index 2ed5d47..cfecdce 100644 --- a/chainlib/cli/man.py +++ b/chainlib/cli/man.py @@ -203,9 +203,10 @@ class DocGenerator: self.docs['rpcdialect'] = o self.envs['rpcdialect'] = 'RPC_DIALECT' - o = DocEntry('--height') - o.set_groff('Block height at which to query state for. Does not apply to transactions.') - self.docs['height'] = o + if self.arg_flags & Flag.NO_TARGET == 0: + o = DocEntry('--height') + o.set_groff('Block height at which to query state for. Does not apply to transactions.') + self.docs['height'] = o if self.arg_flags & Flag.RPC_AUTH: o = DocEntry('--rpc-auth') @@ -343,6 +344,10 @@ class EnvDocGenerator: self.__add(k) + def __len__(self): + return len(self.envs) + + def __str__(self): s = '' ks = list(self.envs.keys()) diff --git a/scripts/chainlib-man.py b/scripts/chainlib-man.py index c6cad70..245dd28 100644 --- a/scripts/chainlib-man.py +++ b/scripts/chainlib-man.py @@ -172,6 +172,20 @@ def get_custom(tool_name, source_dir): return custom +def get_seealso(tool_name, source_dir): + seealso_file = os.path.join(source_dir, tool_name + '.seealso.groff') + f = None + try: + f = open(seealso_file, 'r') + except FileNotFoundError: + logg.debug('no seealso file found for {}'.format(tool_name)) + return None + logg.info('seealso file {} found for {}'.format(seealso_file, tool_name)) + seealso = f.read() + f.close() + return seealso + + g = apply_override(g, args.source_dir) ge = EnvDocGenerator(flags, override=args.overrides_env_dir) @@ -180,6 +194,7 @@ ge.process() head = get_head(toolname, args.source_dir) examples = get_examples(toolname, args.source_dir) custom = get_custom(toolname, args.source_dir) +seealso = get_seealso(toolname, args.source_dir) if args.overrides_config_file != None: f = open(args.overrides_config_file, 'r') @@ -199,8 +214,14 @@ if examples != None: f.write(".SH EXAMPLES\n\n") f.write(examples) -f.write(".SH ENVIRONMENT\n\n") -f.write(str(ge)) + +if seealso != None: + seealso_description = seealso + +if len(ge) > 0: + f.write(".SH ENVIRONMENT\n\n") + f.write(str(ge)) + f.write(legal_description) f.write(source_description) f.write(seealso_description)