Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement CLI using Click #150

Closed
wants to merge 6 commits into from
Closed

Reimplement CLI using Click #150

wants to merge 6 commits into from

Conversation

Tenzer
Copy link
Collaborator

@Tenzer Tenzer commented Dec 12, 2023

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.

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.
@Tenzer
Copy link
Collaborator Author

Tenzer commented Dec 12, 2023

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
Copy link
Owner

@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.

This allows us to add custom logic, such as dynamically generating extra
commands which will be needed for the LGTVRemote commands.
I incorrectly used `click.MultiCommand` instead of `click.Group`, although both
works, but `click.MultiCommand` is being deprecated from the next Click version
anyways. This also fixes a type annotation error since the `cls` argument to
`@click.group()` only takes a `click.Group` class.
@Tenzer
Copy link
Collaborator Author

Tenzer commented Jun 15, 2024

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.

@Tenzer Tenzer closed this Jun 15, 2024
@Tenzer Tenzer deleted the click-cli branch June 15, 2024 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants