split common command line args parsing

A new function parse_args_common() that only parses
common command line options. The returned object can
be composed to parse more arguments.
As is done by parse_args().
This commit is contained in:
kryofly
2018-01-06 07:39:05 +01:00
parent 74a708b794
commit 47675943ee
3 changed files with 44 additions and 34 deletions

View File

@@ -81,21 +81,12 @@ def throttle(func: Callable[..., Any], min_secs: float, *args, **kwargs) -> Any:
return result
def parse_args(args: List[str]):
def parse_args_common(args: List[str], description: str):
"""
Parses given arguments and returns an argparse Namespace instance.
Returns None if a sub command has been selected and executed.
Parses given common arguments and returns them as a parsed object.
"""
parser = argparse.ArgumentParser(
description='Simple High Frequency Trading Bot for crypto currencies'
)
parser.add_argument(
'-c', '--config',
help='specify configuration file (default: config.json)',
dest='config',
default='config.json',
type=str,
metavar='PATH',
description=description
)
parser.add_argument(
'-v', '--verbose',
@@ -110,6 +101,30 @@ def parse_args(args: List[str]):
action='version',
version='%(prog)s {}'.format(__version__),
)
parser.add_argument(
'-c', '--config',
help='specify configuration file (default: config.json)',
dest='config',
default='config.json',
type=str,
metavar='PATH',
)
return parser
def parse_args(args: List[str], description: str):
"""
Parses given arguments and returns an argparse Namespace instance.
Returns None if a sub command has been selected and executed.
"""
parser = parse_args_common(args, description)
parser.add_argument(
'--dry-run-db',
help='Force dry run to use a local DB "tradesv3.dry_run.sqlite" instead of memory DB. Work only if dry_run is \
enabled.', # noqa
action='store_true',
dest='dry_run_db',
)
parser.add_argument(
'--dynamic-whitelist',
help='dynamically generate and update whitelist based on 24h BaseVolume (Default 20 currencies)', # noqa
@@ -119,13 +134,7 @@ def parse_args(args: List[str]):
metavar='INT',
nargs='?',
)
parser.add_argument(
'--dry-run-db',
help='Force dry run to use a local DB "tradesv3.dry_run.sqlite" instead of memory DB. Work only if dry_run is \
enabled.', # noqa
action='store_true',
dest='dry_run_db',
)
build_subcommands(parser)
parsed_args = parser.parse_args(args)