diff --git a/src/cranberry/fields.py b/src/cranberry/fields.py index fd0de52..be72c3e 100644 --- a/src/cranberry/fields.py +++ b/src/cranberry/fields.py @@ -93,8 +93,8 @@ def metavar(self) -> str: # Public factory functions # --------------------------------------------------------------------------- def option( - short: str, - long: str, + short: str | None, + long: str | None, *, help: str = "", default: Any = None, @@ -116,8 +116,8 @@ def option( def flag( - short: str, - long: str, + short: str | None, + long: str | None, *, help: str = "", default: bool = False, @@ -159,8 +159,8 @@ def arg( def file( - short: str, - long: str, + short: str | None, + long: str | None, *, help: str = "", default: Any = None, @@ -183,8 +183,8 @@ def file( def dir( - short: str, - long: str, + short: str | None, + long: str | None, *, help: str = "", default: Any = None, diff --git a/tests/test_fields.py b/tests/test_fields.py index c5c7888..2e75e01 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -65,6 +65,16 @@ def test_validate_stored(self): spec = cb.option("-o", "--opt", validate=v) assert spec.validate is v + def test_none_short(self): + spec = cb.option(None, "--opt") + assert spec.short is None + assert spec.long is not None + + def test_none_long(self): + spec = cb.option("--opt", None) + assert spec.short is not None + assert spec.long is None + # --------------------------------------------------------------------------- # flag() @@ -82,6 +92,22 @@ def test_default_false(self): def test_default_true(self): assert cb.flag("-f", "--flag", default=True).default is True + def test_stackable_false(self): + assert cb.flag("-f", "--flag").stackable is False + + def test_stackable_true(self): + assert cb.flag("-f", "--flag", stackable=True).stackable is True + + def test_none_short(self): + spec = cb.flag(None, "--flag") + assert spec.short is None + assert spec.long is not None + + def test_none_long(self): + spec = cb.flag("--flag", None) + assert spec.short is not None + assert spec.long is None + # --------------------------------------------------------------------------- # arg() @@ -105,6 +131,10 @@ def test_enforce_count_default_false(self): def test_enforce_count_true(self): assert cb.arg(enforce_count=True).enforce_count is True + def test_type(self): + assert cb.arg(type=int).type is int + assert cb.arg(type=str).type is str + # --------------------------------------------------------------------------- # file()