allow reading config from stdin

This commit is contained in:
hroff-1902 2019-06-20 00:04:11 +03:00
parent 38712f8120
commit 0866b5f29f
3 changed files with 8 additions and 4 deletions

View File

@ -26,7 +26,8 @@ optional arguments:
--version show program's version number and exit --version show program's version number and exit
-c PATH, --config PATH -c PATH, --config PATH
Specify configuration file (default: None). Multiple Specify configuration file (default: None). Multiple
--config options may be used. --config options may be used. Can be set to '-' to
read config from stdin.
-d PATH, --datadir PATH -d PATH, --datadir PATH
Path to backtest data. Path to backtest data.
-s NAME, --strategy NAME -s NAME, --strategy NAME

View File

@ -85,8 +85,9 @@ class Arguments(object):
) )
self.parser.add_argument( self.parser.add_argument(
'-c', '--config', '-c', '--config',
help='Specify configuration file (default: %(default)s). ' help="Specify configuration file (default: %(default)s). "
'Multiple --config options may be used.', "Multiple --config options may be used. "
"Can be set to '-' to read config from stdin.",
dest='config', dest='config',
action='append', action='append',
type=str, type=str,

View File

@ -79,6 +79,7 @@ class Configuration(object):
# Now expecting a list of config filenames here, not a string # Now expecting a list of config filenames here, not a string
for path in self.args.config: for path in self.args.config:
logger.info('Using config: %s ...', path) logger.info('Using config: %s ...', path)
# Merge config options, overwriting old values # Merge config options, overwriting old values
config = deep_merge_dicts(self._load_config_file(path), config) config = deep_merge_dicts(self._load_config_file(path), config)
@ -118,7 +119,8 @@ class Configuration(object):
:return: configuration as dictionary :return: configuration as dictionary
""" """
try: try:
with open(path) as file: # Read config from stdin if requested in the options
with open(path) if path != '-' else sys.stdin as file:
conf = json.load(file) conf = json.load(file)
except FileNotFoundError: except FileNotFoundError:
raise OperationalException( raise OperationalException(