klattimer / LGWebOSRemote

Command line webOS remote for LGTVs
MIT License
490 stars 97 forks source link

Reimplement CLI using Click #150

Closed Tenzer closed 2 weeks ago

Tenzer commented 6 months ago

It has felt awkward every time I've tried to add a new command to the CLI, and the current help output doesn't show all available sub-commands because the commands are handled in different ways depending on if they are part of LGTVRemote or not.

To alleviate this situation, I tried to work on implementing the CLI using Click instead, and so far, I think it's been pretty good.

It currently implements the "auth", "scan", and "set-default" commands from the existing CLI, plus handles the config file centrally to make it easier for the sub-commands to work with.

The new code is also fully typed.

If this looks decent, I'll continue to work on getting the rest of the commands implemented. I'm thinking for the LGTVRemote and LGTVCursor commands that, it might be easier to implement them programmatically via a dictionary lookup rather than having separate functions for each of them since the difference mainly is which URI the call results in.

Tenzer commented 6 months ago

I should perhaps mention that it in the current configuration gives pretty nice help output:

~/git/LGWebOSRemote % python LGTV/cli.py
Usage: cli.py [OPTIONS] COMMAND [ARGS]...

  Command line webOS remote for LG TVs.

Options:
  -d, --debug      Enable debug output.
  -n, --name TEXT  Name of the TV to manage.
  --help           Show this message and exit.

Commands:
  auth         Connect to a new TV.
  scan         Scan the local network for LG TVs.
  set-default  Change the default TV to interact with.

and also --help output for individual sub-commands.

klattimer commented 6 months ago

@Tenzer y'know I spent about 2 days making this code work for me years ago when I needed it... Now I feel like I'm not really that involved anymore but to push a button :)

Looks good btw, turning into a real thing not just a weekend hack like my repos usually are, which is sort of what I hoped for all along.

Tenzer commented 2 weeks ago

I've ended up instead working on a separate project from scratch which uses Typer as the CLI library, which is why there's been no more work on this.