-
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.
Shift archive and settings commands to cli package
Update esak to v2
- Loading branch information
1 parent
61651dc
commit c20d4b6
Showing
8 changed files
with
131 additions
and
79 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ on: | |
paths: | ||
- README.md | ||
- perdoo/__main__.py | ||
- perdoo/cli/** | ||
workflow_dispatch: | ||
|
||
permissions: | ||
|
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,4 @@ | ||
__all__ = ["archive_app", "settings_app"] | ||
|
||
from perdoo.cli.archive import app as archive_app | ||
from perdoo.cli.settings import app as settings_app |
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,34 @@ | ||
__all__ = ["app"] | ||
|
||
from pathlib import Path | ||
from typing import Annotated | ||
|
||
from typer import Argument, Option, Typer | ||
|
||
from perdoo.archives import get_archive | ||
from perdoo.console import CONSOLE | ||
from perdoo.metadata import get_metadata | ||
|
||
app = Typer() | ||
|
||
|
||
@app.command(help="View the ComicInfo/MetronInfo inside a Comic archive.") | ||
def view( | ||
target: Annotated[ | ||
Path, | ||
Argument(dir_okay=False, exists=True, show_default=False, help="Comic to view details of."), | ||
], | ||
hide_comic_info: Annotated[ | ||
bool, Option("--hide-comic-info", help="Don't show the ComicInfo details.") | ||
] = False, | ||
hide_metron_info: Annotated[ | ||
bool, Option("--hide-metron-info", help="Don't show the MetronInfo details.") | ||
] = False, | ||
) -> None: | ||
archive = get_archive(path=target) | ||
CONSOLE.print(f"Archive format: '{type(archive).__name__[:3]}'") | ||
metron_info, comic_info = get_metadata(archive=archive) | ||
if not hide_comic_info: | ||
comic_info.display() | ||
if not hide_metron_info: | ||
metron_info.display() |
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,56 @@ | ||
__all__ = ["app"] | ||
|
||
from argparse import SUPPRESS | ||
from typing import Annotated | ||
|
||
from typer import Argument, Option, Typer | ||
|
||
from perdoo.console import CONSOLE | ||
from perdoo.settings import Settings | ||
from perdoo.utils import flatten_dict | ||
|
||
app = Typer() | ||
|
||
|
||
@app.command() | ||
def view() -> None: | ||
settings = Settings.load() | ||
settings.display() | ||
|
||
|
||
@app.command(name="locate") | ||
def locate() -> None: | ||
CONSOLE.print(Settings._file) # noqa: SLF001 | ||
|
||
|
||
@app.command(name="update") | ||
def update( | ||
key: Annotated[str | None, Argument(show_default=False, help="The setting to update.")] = None, | ||
value: Annotated[ | ||
str | None, Argument(show_default=False, help="The value to update the setting to.") | ||
] = SUPPRESS, | ||
reset: Annotated[ | ||
bool, | ||
Option( | ||
"--reset", | ||
help="Reset the specified setting to its default value. If no key is provided, reset all settings.", # noqa: E501 | ||
), | ||
] = False, | ||
) -> None: | ||
if reset: | ||
Settings().save() | ||
CONSOLE.print("Settings reset") | ||
elif key: | ||
settings = Settings.load() | ||
if reset: | ||
settings_dict = flatten_dict(content=Settings().model_dump()) | ||
if key in settings_dict: | ||
settings.update(key=key, value=settings_dict[key]) | ||
settings.save() | ||
CONSOLE.print(f"'{key}' Reset") | ||
else: | ||
CONSOLE.print(f"No Config key: '{key}'", style="logging.level.critical") | ||
elif value is not SUPPRESS: | ||
settings.update(key=key, value=value) | ||
settings.save() | ||
CONSOLE.print(f"Updated '{key}' to {value}") |
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