Add formatting options for cli
This commit is contained in:
parent
1db7f3f8c8
commit
91bd428c22
@ -5,6 +5,7 @@ from .base import (
|
||||
argflag_std_base,
|
||||
argflag_std_base_read,
|
||||
flag_reset,
|
||||
flag_set,
|
||||
)
|
||||
from .arg import ArgumentParser
|
||||
from .config import Config
|
||||
|
@ -43,6 +43,10 @@ _default_dest = {
|
||||
'-e': 'executable_address',
|
||||
}
|
||||
|
||||
|
||||
_default_fmt = 'human'
|
||||
|
||||
|
||||
class ArgumentParser(argparse.ArgumentParser):
|
||||
"""Extends the standard library argument parser to construct arguments based on configuration flags.
|
||||
|
||||
@ -66,12 +70,13 @@ class ArgumentParser(argparse.ArgumentParser):
|
||||
:type epilog: str
|
||||
"""
|
||||
|
||||
def __init__(self, arg_flags=0x0f, arg_long={}, env=os.environ, usage=None, description=None, epilog=None, *args, **kwargs):
|
||||
def __init__(self, arg_flags=0x0f, arg_long={}, env=os.environ, usage=None, description=None, epilog=None, default_format=_default_fmt, *args, **kwargs):
|
||||
super(ArgumentParser, self).__init__(usage=usage, description=description, epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter, *args, **kwargs)
|
||||
|
||||
self.pos_args = []
|
||||
self.long_args = _default_long_args
|
||||
self.arg_dest = _default_dest
|
||||
self.default_format = default_format
|
||||
|
||||
re_long = r'^--[a-z\-]+$'
|
||||
for k in arg_long.keys():
|
||||
@ -210,3 +215,12 @@ class ArgumentParser(argparse.ArgumentParser):
|
||||
self.add_argument('-e', self.long_args['-e'], dest=self.arg_dest['-e'], type=str, help='contract address')
|
||||
if arg_flags & Flag.WALLET:
|
||||
self.add_argument('-a', self.long_args['-a'], dest=self.arg_dest['-a'], type=str, help='recipient address')
|
||||
if arg_flags & (Flag.FMT_HUMAN | Flag.FMT_WIRE | Flag.FMT_RPC):
|
||||
format_choices = []
|
||||
if arg_flags & Flag.FMT_HUMAN:
|
||||
format_choices.append('human')
|
||||
if arg_flags & Flag.FMT_WIRE:
|
||||
format_choices.append('bin')
|
||||
if arg_flags & Flag.FMT_RPC:
|
||||
format_choices.append('rpc')
|
||||
self.add_argument('-f', '--format', type=str, choices=format_choices, help='output formatting (default: {})'.format(self.default_format))
|
||||
|
@ -33,6 +33,10 @@ class Flag(enum.IntEnum):
|
||||
SEND = 262144
|
||||
# rpc extras - nibble 6
|
||||
RPC_AUTH = 1048576
|
||||
# formatting - nibble 7
|
||||
FMT_HUMAN = 16777216
|
||||
FMT_WIRE = 33554432
|
||||
FMT_RPC = 67108864
|
||||
# upper bound
|
||||
MAX = 1048576
|
||||
|
||||
@ -40,8 +44,8 @@ argflag_std_read = 0x23ff
|
||||
argflag_std_write = 0x1731ff
|
||||
argflag_std_base = 0x200f
|
||||
argflag_std_base_read = 0xbf
|
||||
argflag_std_target = 0x00e000
|
||||
argflag_all = 0x17f7ff
|
||||
argflag_std_target = 0x0000e000
|
||||
argflag_all = 0x0317f7ff
|
||||
|
||||
|
||||
def flag_reset(flags, v):
|
||||
@ -50,6 +54,10 @@ def flag_reset(flags, v):
|
||||
return r
|
||||
|
||||
|
||||
def flag_set(flags, v):
|
||||
return flags | v
|
||||
|
||||
|
||||
def flag_names(flags):
|
||||
flags_debug = []
|
||||
i = Flag.MAX
|
||||
|
@ -222,7 +222,7 @@ class Config(confini.Config):
|
||||
args_override['WALLET_PASSPHRASE'] = f.read()
|
||||
f.close()
|
||||
config.censor('PASSPHRASE', 'WALLET')
|
||||
config.dict_override(args_override, 'cli args')
|
||||
config.dict_override(args_override, 'cli args', allow_empty=True)
|
||||
|
||||
if arg_flags & Flag.PROVIDER:
|
||||
config.add(getattr(args, 'height'), '_HEIGHT')
|
||||
|
@ -1,4 +1,4 @@
|
||||
funga~=0.5.1
|
||||
funga~=0.5.2
|
||||
pysha3==1.0.2
|
||||
hexathon~=0.1.3
|
||||
confini~=0.5.3
|
||||
hexathon~=0.1.5
|
||||
confini~=0.5.7
|
||||
|
Loading…
Reference in New Issue
Block a user