-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev'; bump version to 0.3.1
- Loading branch information
Showing
14 changed files
with
380 additions
and
195 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typed_cap import Cap | ||
|
||
|
||
class Args: | ||
"""description here""" | ||
|
||
config: str | None | ||
"""file path to config file""" | ||
|
||
depth: int | ||
"""depth of search""" | ||
|
||
dry_run: bool = True | ||
"""run without making any changes""" | ||
|
||
|
||
cap = Cap(Args) | ||
parsed = cap.parse() | ||
|
||
print(parsed.args.__dict__) | ||
print(parsed.argv) |
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,48 @@ | ||
from enum import Enum | ||
|
||
from typed_cap import Cap | ||
|
||
|
||
class CoinFlip(Enum): | ||
head = 0 | ||
tail = 1 | ||
|
||
|
||
class Args: | ||
""" | ||
docstring of T | ||
""" | ||
|
||
# @alias=a | ||
all: bool = False | ||
""" | ||
write counts for all files, not just directories | ||
""" | ||
|
||
# @alias=c | ||
total: bool = False | ||
|
||
# @alias=d @hide_default | ||
max_depth: int = -1 | ||
""" | ||
print the total for a directory (or file, with --all) only if it is N or fewer levels below the command line argument | ||
""" | ||
|
||
# @alias=h | ||
human_readable: bool | None | ||
""" | ||
print sizes in human readable format (e.g., 1K 234M 2G) | ||
""" | ||
|
||
# @alias=m @none_delimiter | ||
message: list[str] | None | ||
|
||
# @enum_on_value | ||
flip: CoinFlip | ||
|
||
|
||
cap = Cap(Args) | ||
parsed = cap.parse() | ||
|
||
print(parsed.args.__dict__) | ||
print(parsed.argv) |
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,40 @@ | ||
from PIL import Image | ||
from typed_cap import Cap | ||
from typed_cap.typing import ValidUnit, ValidRes, ValidVal | ||
|
||
|
||
class Args: | ||
image: Image.Image | ||
"""path to image wanted to be loaded""" | ||
|
||
|
||
def valid_image(vv, t, val, cvt): | ||
v = ValidRes[Image.Image]() | ||
if cvt: | ||
try: | ||
v.some(Image.open(val)) | ||
v.valid() | ||
except Exception as err: | ||
v.error(err) | ||
else: | ||
if isinstance(val, Image.Image): | ||
v.some(val) | ||
v.valid() | ||
return v | ||
|
||
|
||
cap = Cap( | ||
Args, | ||
extra_validator_units={ | ||
"image": ValidUnit( | ||
exact=Image.Image, | ||
type_of=None, | ||
class_of=None, | ||
valid_fn=valid_image, | ||
), | ||
}, | ||
) | ||
parsed = cap.parse() | ||
# python 02_custom_unit.py --image demo.jpg | ||
|
||
print(parsed.args.image) |
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
Oops, something went wrong.