From 3691f75f81b720e93762e6a13189b9a91ab6c8e0 Mon Sep 17 00:00:00 2001 From: lash Date: Tue, 22 Feb 2022 12:11:38 +0000 Subject: [PATCH] Add heading file argument to generator script --- CHANGELOG | 2 ++ chainlib/cli/man.py | 2 +- scripts/man.py | 42 ++++++++++++++++++++++++++++++++++++++---- setup.py | 3 +++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 514f656..d890211 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +- 0.0.22 + * Add man page generator script - 0.0.21 * Log rpc reply before json parse - 0.0.20 diff --git a/chainlib/cli/man.py b/chainlib/cli/man.py index b7c4b6f..cfc0fdf 100644 --- a/chainlib/cli/man.py +++ b/chainlib/cli/man.py @@ -193,7 +193,7 @@ class DocGenerator: self.docs['feeprice'] = o o = DocEntry('--fee-limit') - o.set_groff('Set the limit of execution units for the transaction. If used with \\fB-s\fP this may incur actual network token cost. If \\fB--fee-price\\fP is not explicitly set, the price \\fImay\\fP be retrieved from the network, and multiplied with this value to define the cost.') + o.set_groff('Set the limit of execution units for the transaction. If used with \\fB-s\\fP this may incur actual network token cost. If \\fB--fee-price\\fP is not explicitly set, the price \\fImay\\fP be retrieved from the network, and multiplied with this value to define the cost.') self.docs['feelimit'] = o # TODO: this manipulation should be DRYd diff --git a/scripts/man.py b/scripts/man.py index 52beafe..fef2ee9 100644 --- a/scripts/man.py +++ b/scripts/man.py @@ -1,8 +1,42 @@ +import os import sys -from hexathon import strip_0x -from chainlib.cli.man import DocGenerator +import argparse +import tempfile +import shutil -b = bytes.fromhex(strip_0x(sys.argv[1])) +from hexathon import strip_0x, add_0x + +from chainlib.cli.man import DocGenerator +from chainlib.cli.base import argflag_std_base + +argparser = argparse.ArgumentParser() +argparser.add_argument('-b', default=add_0x(hex(argflag_std_base)), help='argument flag bitmask') +argparser.add_argument('-n', help='tool name to use for man filename') +argparser.add_argument('-d', default='.', help='output directory') +argparser.add_argument('header_file', help='groff file containing heading, synopsis and description') +args = argparser.parse_args(sys.argv[1:]) + +#b = bytes.fromhex(strip_0x(sys.argv[1])) +b = bytes.fromhex(strip_0x(args.b)) g = DocGenerator(int.from_bytes(b, byteorder='little')) g.process() -print(g) + +f = open(args.header_file) +head = f.read() +f.close() + +toolname = args.n +if toolname == None: + parts = os.path.splitext(os.path.basename(args.header_file)) + toolname = parts[0] + +(fd, fp) = tempfile.mkstemp() +f = os.fdopen(fd, 'w') +f.write(head) +f.write(str(g)) +f.close() + +dest = os.path.join(args.d, toolname + '.1') +shutil.copyfile(fp, dest) + +os.unlink(fp) diff --git a/setup.py b/setup.py index 4e9c807..993ed72 100644 --- a/setup.py +++ b/setup.py @@ -24,4 +24,7 @@ setup( 'chainlib', 'chainlib.cli', ], + scripts = [ + 'scripts/man.py', + ], )