-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from DanCardin/dc/prettier-parse-errors
feat: Improve parse error formatting. Include short help by default.
- Loading branch information
Showing
15 changed files
with
172 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from rich.theme import Theme | ||
|
||
default_theme: Theme = Theme( | ||
{ | ||
"cappa.prog": "grey50", | ||
"cappa.group": "dark_orange bold", | ||
"cappa.arg": "cyan", | ||
"cappa.arg.name": "dark_cyan", | ||
"cappa.subcommand": "dark_cyan", | ||
"cappa.help": "", | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import Union | ||
|
||
import cappa | ||
import pytest | ||
from typing_extensions import Annotated | ||
|
||
from tests.utils import parse | ||
|
||
|
||
@dataclass | ||
class RequiredMissingOne: | ||
foo: Annotated[Union[str, None], cappa.Arg(long=True)] = None | ||
|
||
|
||
@dataclass | ||
class RequiredMissingTwo: | ||
foo: Annotated[Union[str, None], cappa.Arg(long=True)] = None | ||
|
||
|
||
@dataclass | ||
class RequiredMissing: | ||
subcommand: Annotated[ | ||
Union[RequiredMissingOne, RequiredMissingTwo], cappa.Subcommand | ||
] | ||
|
||
|
||
def test_has_possible_values(): | ||
with pytest.raises(cappa.Exit) as e: | ||
parse(RequiredMissing, "req", backend=None) | ||
assert isinstance(e.value.message, str) | ||
|
||
expected_message = ( | ||
"Invalid command 'req' (Did you mean: " | ||
"[cappa.subcommand]required-missing-one[/cappa.subcommand], " | ||
"[cappa.subcommand]required-missing-two[/cappa.subcommand])" | ||
) | ||
assert expected_message == e.value.message | ||
|
||
|
||
def test_no_possible_values(): | ||
with pytest.raises(cappa.Exit) as e: | ||
parse(RequiredMissing, "bad", backend=None) | ||
assert isinstance(e.value.message, str) | ||
|
||
expected_message = "Invalid command 'bad'" | ||
assert expected_message == e.value.message |