Merge pull request #2922 from freqtrade/config_userdir
default to loading config.json from userdir if it exists
This commit is contained in:
@@ -6,8 +6,8 @@ from functools import partial
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from freqtrade import constants
|
||||
from freqtrade.commands.cli_options import AVAILABLE_CLI_OPTIONS
|
||||
from freqtrade.constants import DEFAULT_CONFIG
|
||||
|
||||
ARGS_COMMON = ["verbosity", "logfile", "version", "config", "datadir", "user_data_dir"]
|
||||
|
||||
@@ -107,10 +107,23 @@ class Arguments:
|
||||
# Workaround issue in argparse with action='append' and default value
|
||||
# (see https://bugs.python.org/issue16399)
|
||||
# Allow no-config for certain commands (like downloading / plotting)
|
||||
if ('config' in parsed_arg and parsed_arg.config is None and
|
||||
((Path.cwd() / constants.DEFAULT_CONFIG).is_file() or
|
||||
not ('command' in parsed_arg and parsed_arg.command in NO_CONF_REQURIED))):
|
||||
parsed_arg.config = [constants.DEFAULT_CONFIG]
|
||||
if ('config' in parsed_arg and parsed_arg.config is None):
|
||||
conf_required = ('command' in parsed_arg and parsed_arg.command in NO_CONF_REQURIED)
|
||||
|
||||
if 'user_data_dir' in parsed_arg and parsed_arg.user_data_dir is not None:
|
||||
user_dir = parsed_arg.user_data_dir
|
||||
else:
|
||||
# Default case
|
||||
user_dir = 'user_data'
|
||||
# Try loading from "user_data/config.json"
|
||||
cfgfile = Path(user_dir) / DEFAULT_CONFIG
|
||||
if cfgfile.is_file():
|
||||
parsed_arg.config = [str(cfgfile)]
|
||||
else:
|
||||
# Else use "config.json".
|
||||
cfgfile = Path.cwd() / DEFAULT_CONFIG
|
||||
if cfgfile.is_file() or not conf_required:
|
||||
parsed_arg.config = [DEFAULT_CONFIG]
|
||||
|
||||
return parsed_arg
|
||||
|
||||
|
@@ -59,7 +59,8 @@ AVAILABLE_CLI_OPTIONS = {
|
||||
),
|
||||
"config": Arg(
|
||||
'-c', '--config',
|
||||
help=f'Specify configuration file (default: `{constants.DEFAULT_CONFIG}`). '
|
||||
help=f'Specify configuration file (default: `userdir/{constants.DEFAULT_CONFIG}` '
|
||||
f'or `config.json` whichever exists). '
|
||||
f'Multiple --config options may be used. '
|
||||
f'Can be set to `-` to read config from stdin.',
|
||||
action='append',
|
||||
|
Reference in New Issue
Block a user