commit 6bbcc6961751cb345867c1c1fb1f9ec38b3b7030
parent 7619b954b7b983d86dc5d9679cc63ecdad9de55a
Author: lash <dev@holbrook.no>
Date:   Thu,  3 Nov 2022 10:37:35 +0000
Reenable pipe args, alias raw with r
Diffstat:
6 files changed, 32 insertions(+), 102 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,7 @@
+- 0.3.3
+	* Reinstate stdin_arg
+	* Add -r alias to --raw
+	* Remove old dead arg selector code
 - 0.3.2
 	* Add missing "confirmed" arg to nonce oracle, expected by chainlib-eth test
 - 0.3.1
diff --git a/chainlib/cli/__init__.py b/chainlib/cli/__init__.py
@@ -1,12 +1,3 @@
-from .base import (
-        Flag,
-        argflag_std_read,
-        argflag_std_write,
-        argflag_std_base,
-        argflag_std_base_read,
-        flag_reset,
-        flag_set,
-        )
 from .arg import ArgumentParser
 from .config import Config
 from .rpc import Rpc
diff --git a/chainlib/cli/arg.py b/chainlib/cli/arg.py
@@ -1,9 +1,8 @@
 # standard imports
 import logging
-import argparse
-#import enum
+import argparse #import enum
 #import os
-#import select
+import select
 import sys
 #import re
 
@@ -17,26 +16,34 @@ from aiee.arg import (
 logg = logging.getLogger(__name__)
 
 
-#def stdin_arg():
-#    """Retreive input arguments from stdin if they exist.
-#
-#    Method does not block, and expects arguments to be ready on stdin before being called.
-#
-#    :rtype: str
-#    :returns: Input arguments string
-#    """
-#    h = select.select([sys.stdin], [], [], 0)
-#    if len(h[0]) > 0:
-#        v = h[0][0].read()
-#        return v.rstrip()
-#    return None
+def stdin_arg():
+    """Retreive input arguments from stdin if they exist.
+
+    Method does not block, and expects arguments to be ready on stdin before being called.
+
+    :rtype: str
+    :returns: Input arguments string
+    """
+    h = select.select([sys.stdin], [], [])
+    if len(h[0]) > 0:
+        v = h[0][0].read()
+        return v.rstrip()
+    return None
+
 
 class ArgumentParser(argparse.ArgumentParser):
 
     def parse_args(self, argv=sys.argv[1:]):
         if '--dumpconfig' in argv:
             argv = [argv[0], '--dumpconfig']
-        return super(ArgumentParser, self).parse_args(args=argv)
+        arg = super(ArgumentParser, self).parse_args(args=argv)
+        return arg
+
+
+    def add_argument(self, *args, **kwargs):
+        if args[0][0] != '-':
+            kwargs['nargs'] = '*'
+        super(ArgumentParser, self).add_argument(*args, **kwargs)
 
 
 class ArgFlag(BaseArgFlag):
@@ -131,7 +138,8 @@ class Arg(BaseArg):
         self.add('s', 'send', typ=bool, help='Send to network')
         self.set_long('s', 'send')
 
-        self.add_long('raw', 'raw', typ=bool, help='Do not decode output')
+        self.add('r', 'raw', typ=bool, help='Do not decode output')
+        self.set_long('r', 'raw')
         self.add('0', 'raw', typ=bool, help='Omit newline to output')
 
         self.add_long('nonce', 'nonce', typ=int, help='override nonce')
diff --git a/chainlib/cli/base.py b/chainlib/cli/base.py
@@ -1,72 +0,0 @@
-# standard imports
-import enum
-import os
-
-script_dir = os.path.dirname(os.path.realpath(__file__))
-
-default_config_dir = os.path.join(script_dir, '..', 'data', 'config')
-
-
-# powers of two
-class Flag(enum.IntEnum):
-    # read - nibble 1-2
-    VERBOSE = 1
-    CONFIG = 2
-    RAW = 4
-    ENV_PREFIX = 8
-    PROVIDER = 16
-    CHAIN_SPEC = 32
-    UNSAFE = 64
-    SEQ = 128
-    # read/write - nibble 3
-    KEY_FILE = 256
-    FEE = 512 # this must be defined separately now since some rpcs demand minimum base fee price
-    NONCE = 1024
-    # write - nibble 4
-    SIGN = 4096
-    NO_TARGET = 8192
-    EXEC = 16384
-    WALLET = 32768
-    # network - nibble 5
-    WAIT = 65536
-    WAIT_ALL = 131072
-    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
-
-argflag_std_read = 0x000023ff
-argflag_std_write = 0x001731ff
-argflag_std_base = 0x0000200f
-argflag_std_base_read = 0x000000bf
-argflag_std_target = 0x0000e000
-argflag_all = 0x0317f7ff
-
-
-def flag_reset(flags, v):
-    mask = ~(argflag_all & v)
-    r = flags & mask
-    return r
-
-
-def flag_set(flags, v):
-    return flags | v
-
-
-def flag_names(flags):
-    flags_debug = []
-    i = Flag.MAX
-    while True:
-        if flags & i > 0:
-            v = Flag(i)
-            flags_debug.append(v.name)
-        i >>= 1
-        if i == 0:
-            break
-    flags_debug.reverse()
-    return flags_debug
diff --git a/chainlib/cli/config.py b/chainlib/cli/config.py
@@ -61,7 +61,7 @@ def process_config(config, arg, args, flags):
     args_override = {}
 
     if arg.match('raw', flags):
-        config.add(getattr(args, 'raw', None), '_RAW')
+        config.add(getattr(args, 'r', None), '_RAW')
  
     if arg.match('provider', flags):
         args_override['RPC_PROVIDER'] = getattr(args, 'p')
@@ -133,5 +133,4 @@ def process_config(config, arg, args, flags):
         config.add(getattr(args, 'rpc_auth'), 'RPC_AUTH')
         config.add(getattr(args, 'rpc_credentials'), 'RPC_CREDENTIALS')
 
-
     return config
diff --git a/setup.cfg b/setup.cfg
@@ -3,7 +3,7 @@ name=chainlib
 license=WTFPL2
 author_email=dev@holbrook.no
 description=Generic blockchain access library and tooling
-version=0.3.2
+version=0.3.3
 url=https://gitlab.com/chaintools/chainlib
 author=Louis Holbrook