Skip to content

Commit

Permalink
Remove workaround for Typer apps with only a single command (#77)
Browse files Browse the repository at this point in the history
It's no longer needed with Typer 0.15.0, so this bumps that to be the minimum
Typer version to require with Alga going forward.
  • Loading branch information
Tenzer authored Dec 3, 2024
1 parent 835b59b commit ccc6dc5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 45 deletions.
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ python = "^3.9"
cfgs = ">= 0.13.0"
getmac = ">= 0.9.0"
rich = ">= 13.0.0"
typer = ">= 0.12.0"
typer = ">= 0.15.0"
wakeonlan = ">= 2.0.0"
websocket-client = ">= 1.0.0"

Expand Down
9 changes: 3 additions & 6 deletions src/alga/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@


app = Typer(no_args_is_help=True)
app.add_typer(cli_adhoc.app)
app.add_typer(cli_app.app, name="app")
app.add_typer(cli_channel.app, name="channel")
app.add_typer(cli_input.app, name="input")
app.add_typer(cli_media.app, name="media")
app.add_typer(cli_power.app, name="power")
app.add_typer(cli_remote.app, name="remote")
app.add_typer(cli_setup.app)
app.add_typer(cli_sound_output.app, name="sound-output")
app.add_typer(cli_version.app)
app.add_typer(cli_volume.app, name="volume")

# Commands that only has a single sub-command
# https://github.com/tiangolo/typer/issues/243
app.command()(cli_adhoc.adhoc)
app.command()(cli_setup.setup)
app.command()(cli_version.version)


if __name__ == "__main__":
app()
6 changes: 5 additions & 1 deletion src/alga/cli_adhoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
from typing import Annotated, Optional

from rich import print
from typer import Argument
from typer import Argument, Typer

from alga import client


app = Typer()


@app.command()
def adhoc(path: str, data: Annotated[Optional[str], Argument()] = None) -> None:
"""Send raw request to the TV"""

Expand Down
6 changes: 5 additions & 1 deletion src/alga/cli_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
from getmac import get_mac_address
from rich import print
from rich.console import Console
from typer import Argument, Exit
from typer import Argument, Exit, Typer

from alga import client, config
from alga.payloads import get_hello_data


app = Typer()


def _ip_from_hostname(hostname: str) -> Optional[str]:
try:
results = getaddrinfo(host=hostname, port=None)
Expand All @@ -21,6 +24,7 @@ def _ip_from_hostname(hostname: str) -> Optional[str]:
return None


@app.command()
def setup(
hostname: Annotated[str, Argument()] = "lgwebostv",
) -> None: # pragma: no cover
Expand Down
5 changes: 5 additions & 0 deletions src/alga/cli_version.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from rich import print
from typer import Typer

from alga import __version__


app = Typer()


@app.command()
def version() -> None:
"""Print Alga version"""

Expand Down
68 changes: 34 additions & 34 deletions usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ $ alga [OPTIONS] COMMAND [ARGS]...
**Commands**:

* `adhoc`: Send raw request to the TV
* `setup`: Pair a new TV
* `version`: Print Alga version
* `app`: Apps installed on the TV
* `channel`: TV channels
* `input`: HDMI and similar inputs
* `media`: Control the playing media
* `power`: Turn TV (or screen) on and off
* `remote`: Remote control button presses
* `setup`: Pair a new TV
* `sound-output`: Audio output device
* `version`: Print Alga version
* `volume`: Audio volume

## `alga adhoc`
Expand All @@ -45,38 +45,6 @@ $ alga adhoc [OPTIONS] PATH [DATA]

* `--help`: Show this message and exit.

## `alga setup`

Pair a new TV

**Usage**:

```console
$ alga setup [OPTIONS] [HOSTNAME]
```

**Arguments**:

* `[HOSTNAME]`: [default: lgwebostv]

**Options**:

* `--help`: Show this message and exit.

## `alga version`

Print Alga version

**Usage**:

```console
$ alga version [OPTIONS]
```

**Options**:

* `--help`: Show this message and exit.

## `alga app`

Apps installed on the TV
Expand Down Expand Up @@ -534,6 +502,24 @@ $ alga remote send [OPTIONS] BUTTON

* `--help`: Show this message and exit.

## `alga setup`

Pair a new TV

**Usage**:

```console
$ alga setup [OPTIONS] [HOSTNAME]
```

**Arguments**:

* `[HOSTNAME]`: [default: lgwebostv]

**Options**:

* `--help`: Show this message and exit.

## `alga sound-output`

Audio output device
Expand Down Expand Up @@ -585,6 +571,20 @@ $ alga sound-output set [OPTIONS] VALUE

* `--help`: Show this message and exit.

## `alga version`

Print Alga version

**Usage**:

```console
$ alga version [OPTIONS]
```

**Options**:

* `--help`: Show this message and exit.

## `alga volume`

Audio volume
Expand Down

0 comments on commit ccc6dc5

Please sign in to comment.