Allow pre-parser to read the yaml, in case user wants to include env-file: option there

This commit is contained in:
Paul Gauthier 2024-06-22 14:01:01 -07:00
parent ecc21517ee
commit 95a4ed47e6
2 changed files with 19 additions and 3 deletions

View file

@ -20,14 +20,30 @@ def default_env_file(git_root):
return os.path.join(git_root, ".env") if git_root else ".env"
def get_preparser(git_root):
parser = configargparse.ArgumentParser(add_help=False)
def get_preparser(default_config_files, git_root):
parser = configargparse.ArgumentParser(
description="aider is GPT powered coding in your terminal",
add_config_file_help=True,
default_config_files=default_config_files,
config_file_parser_class=configargparse.YAMLConfigFileParser,
auto_env_var_prefix="AIDER_",
)
parser.add_argument(
"--env-file",
metavar="ENV_FILE",
default=default_env_file(git_root),
help="Specify the .env file to load (default: .env in git root)",
)
parser.add_argument(
"-c",
"--config",
is_config_file=True,
metavar="CONFIG_FILE",
help=(
"Specify the config file (default: search for .aider.conf.yml in git root, cwd"
" or home directory)"
),
)
return parser

View file

@ -281,7 +281,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
default_config_files.append(Path.home() / conf_fname) # homedir
default_config_files = list(map(str, default_config_files))
preparser = get_preparser(git_root)
preparser = get_preparser(default_config_files, git_root)
pre_args, _ = preparser.parse_known_args(argv)
# Load the .env file specified in the arguments