-
-
Notifications
You must be signed in to change notification settings - Fork 9
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 #110 from DanCardin/dc/default_long_short
feat: Add `default_short=False` and `default_long=False` options to command for ease of definining option-heavy commands.
- Loading branch information
Showing
9 changed files
with
180 additions
and
26 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 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,49 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
|
||
import cappa | ||
import pytest | ||
from typing_extensions import Annotated | ||
|
||
from tests.utils import backends, parse | ||
|
||
|
||
@backends | ||
def test_valid(backend): | ||
@cappa.command(default_long=True) | ||
@dataclass | ||
class Command: | ||
foo: int = 4 | ||
bar: int = 5 | ||
|
||
test = parse(Command, backend=backend) | ||
assert test == Command(4, 5) | ||
|
||
test = parse(Command, "--foo", "1", "--bar", "2", backend=backend) | ||
assert test == Command(1, 2) | ||
|
||
|
||
@backends | ||
def test_override(backend): | ||
@cappa.command(default_long=True) | ||
@dataclass | ||
class Command: | ||
foo: int | ||
far: Annotated[int, cappa.Arg(long="--kar")] | ||
|
||
test = parse(Command, "--foo", "1", "--kar", "2", backend=backend) | ||
assert test == Command(1, 2) | ||
|
||
|
||
@backends | ||
def test_invalid(backend): | ||
@cappa.command(default_long=True) | ||
@dataclass | ||
class Command: | ||
foo: int | ||
far: Annotated[int, cappa.Arg(long="--foo")] | ||
|
||
with pytest.raises(Exception) as e: | ||
parse(Command, backend=backend) | ||
assert "conflicting option string: --f" in str(e.value).lower() |
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 | ||
|
||
import cappa | ||
import pytest | ||
from typing_extensions import Annotated | ||
|
||
from tests.utils import backends, parse | ||
|
||
|
||
@backends | ||
def test_valid(backend): | ||
@cappa.command(default_short=True) | ||
@dataclass | ||
class Command: | ||
foo: int = 4 | ||
bar: int = 5 | ||
|
||
test = parse(Command, backend=backend) | ||
assert test == Command(4, 5) | ||
|
||
test = parse(Command, "-f", "1", "-b", "2", backend=backend) | ||
assert test == Command(1, 2) | ||
|
||
|
||
@backends | ||
def test_override(backend): | ||
@cappa.command(default_short=True) | ||
@dataclass | ||
class Command: | ||
foo: int | ||
far: Annotated[int, cappa.Arg(short="-k")] | ||
|
||
test = parse(Command, "-f", "1", "-k", "2", backend=backend) | ||
assert test == Command(1, 2) | ||
|
||
|
||
@backends | ||
def test_invalid(backend): | ||
@cappa.command(default_short=True) | ||
@dataclass | ||
class Command: | ||
foo: int | ||
far: int | ||
|
||
with pytest.raises(Exception) as e: | ||
parse(Command, backend=backend) | ||
assert "conflicting option string: -f" in str(e.value).lower() |
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