Skip to content

Commit

Permalink
Merge pull request #489 from languitar/feature/version-argument
Browse files Browse the repository at this point in the history
feat(cli): provide a version subcommand
  • Loading branch information
languitar authored Feb 11, 2024
2 parents 6ee72e6 + d51d836 commit c63ed33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/autosuspend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import configparser
from contextlib import suppress
from datetime import datetime, timedelta, timezone
from importlib.metadata import version
import functools
import logging
import logging.config
Expand Down Expand Up @@ -553,6 +554,11 @@ def parse_arguments(args: Optional[Sequence[str]]) -> argparse.Namespace:
subparsers = parser.add_subparsers(title="subcommands", dest="subcommand")
subparsers.required = True

parser_version = subparsers.add_parser(
"version", help="Outputs the program version"
)
parser_version.set_defaults(func=main_version)

parser_daemon = subparsers.add_parser(
"daemon", help="Execute the continuously operating daemon"
)
Expand Down Expand Up @@ -736,6 +742,12 @@ def hook(
)


def main_version(
args: argparse.Namespace, config: configparser.ConfigParser # noqa: ARG001
) -> None:
print(version("autosuspend")) # noqa: T201


def main_hook(
args: argparse.Namespace, config: configparser.ConfigParser # noqa: ARG001
) -> None:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,13 @@ def test_hook_call_wakeup(tmp_path: Path, datadir: Path) -> None:
assert int((tmp_path / SCHEDULED_FILE).read_text()) == int(
round((wakeup_at - timedelta(seconds=30)).timestamp())
)


def test_version(tmp_path: Path, datadir: Path) -> None:
autosuspend.main(
[
"-c",
str(configure_config("would_schedule.conf", datadir, tmp_path)),
"version",
]
)

0 comments on commit c63ed33

Please sign in to comment.