Skip to content

Commit

Permalink
refactor: validate config during parse args (#2334)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 23, 2024
1 parent 8a689b2 commit 86118f2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ape/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import click
import rich
import yaml
from click import Context

from ape.cli import ape_cli_context
from ape.exceptions import Abort, ApeException, ConfigError, handle_ape_exception
Expand Down Expand Up @@ -49,11 +50,14 @@ class ApeCLI(click.MultiCommand):
_commands: Optional[dict] = None
_CLI_GROUP_NAME = "ape_cli_subcommands"

def __init__(self, *args, **kwargs):
def parse_args(self, ctx: Context, args: list[str]) -> list[str]:
# Validate the config before any argument parsing,
# as arguments may utilize config.
_validate_config()
super().__init__(*args, **kwargs)
if "--help" not in args and args != []:
# perf: don't bother w/ config if only doing --help.
_validate_config()

return super().parse_args(ctx, args)

def format_commands(self, ctx, formatter) -> None:
commands = []
Expand Down

0 comments on commit 86118f2

Please sign in to comment.