Skip to content

Commit

Permalink
fix: Ensure readme image is updated and works.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCardin committed Oct 23, 2023
1 parent e3c039b commit 6664783
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ lint:
format:
ruff --fix src tests
black src tests

readme-image:
FORCE_COLOR=true python readme.py --help | ansitoimg --title '' docs/source/_static/example.svg

19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,30 @@ inspiration from the "Derive" API from the
[Clap](https://docs.rs/clap/latest/clap/_derive/index.html) written in Rust.

```python
from dataclasses import dataclass
from dataclasses import dataclass, field
import cappa
from typing import Literal
from typing_extensions import Annotated


@dataclass
class Example:
positional_arg: str
boolean_flag: bool
single_option: Annotated[
int | None,
cappa.Arg(short=True, long=True, help="consectetur adipiscing elit"),
]
positional_arg: str = "optional"
boolean_flag: bool = False
single_option: Annotated[int | None, cappa.Arg(short=True, help="A number")] = None
multiple_option: Annotated[
list[Literal["one", "two", "three"]],
cappa.Arg(short=True, long=True, help="Lorem ipsum dolor sit amet"),
]
cappa.Arg(long=True, help="Pick one!"),
] = field(default_factory=list)


args: Example = cappa.parse(Example, backend=cappa.backend)
print(args)
```

Produces the following CLI:

![help text](./docs/source/_static/example.png)
![help text](./docs/source/_static/example.svg)

In this way, you can turn any dataclass-like object (with some additional
annotations, depending on what you're looking for) into a CLI.
Expand Down
Binary file removed docs/source/_static/example.png
Binary file not shown.
130 changes: 130 additions & 0 deletions docs/source/_static/example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6664783

Please sign in to comment.