From 576e62507b6eb32e66415d74001865bf9b1a0968 Mon Sep 17 00:00:00 2001 From: lash Date: Fri, 13 May 2022 10:33:26 +0000 Subject: [PATCH] Make arg and flag preparations stateless --- chainsyncer/cli/__init__.py | 20 ++++++++++---------- chainsyncer/cli/arg.py | 25 ++++++++++++------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/chainsyncer/cli/__init__.py b/chainsyncer/cli/__init__.py index 0caa7c5..bc95c07 100644 --- a/chainsyncer/cli/__init__.py +++ b/chainsyncer/cli/__init__.py @@ -1,12 +1,12 @@ -# standard imports -import os - -# local imports -from .base import * -from .arg import process_flags -from .config import process_config +## standard imports +#import os +# +## local imports +#from .base import * +#from .arg import process_flags +#from .config import process_config -__script_dir = os.path.dirname(os.path.realpath(__file__)) -data_dir = os.path.join(os.path.dirname(__script_dir), 'data') -config_dir = os.path.join(data_dir, 'config') +#__script_dir = os.path.dirname(os.path.realpath(__file__)) +#data_dir = os.path.join(os.path.dirname(__script_dir), 'data') +#config_dir = os.path.join(data_dir, 'config') diff --git a/chainsyncer/cli/arg.py b/chainsyncer/cli/arg.py index 3884b25..5852f77 100644 --- a/chainsyncer/cli/arg.py +++ b/chainsyncer/cli/arg.py @@ -1,15 +1,14 @@ -# local imports -from .base import SyncFlag +def apply_flag(flag): + flag.add('range') + flag.add('head') + flag.alias('sync_range_ext', 'range', 'head') + return flag -def process_flags(argparser, flags): - - if flags & SyncFlag.RANGE > 0: - argparser.add_argument('--offset', type=int, help='Block to start sync from. Default is start of history (0).') - argparser.add_argument('--until', type=int, default=-1, help='Block to stop sync on. Default is stop at block height of first run.') - argparser.add_argument('--single', action='store_true', help='Execute a single sync, regardless of previous states') - if flags & SyncFlag.HEAD > 0: - argparser.add_argument('--head', action='store_true', help='Start from latest block as offset') - argparser.add_argument('--keep-alive', action='store_true', help='Do not stop syncing when caught up') - - argparser.add_argument('--backend', type=str, help='Backend to use for state store') +def apply_arg(arg): + arg.add_long('offset', 'range', typ=int, help='Block to start sync from. Default is start of history (0).') + arg.add_long('until', 'range', typ=int, default=-1, help='Block to stop sync on. Default is stop at block height of first run.') + arg.add_long('single', 'range', typ=bool, help='Execute a single sync, regardless of previous states') + arg.add_long('head', 'head', typ=bool, help='Start from latest block as offset') + arg.add_long('keep-alive', 'head', typ=bool, help='Do not stop syncing when caught up') + return arg