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

Add a way to do command line completion in sanssh. #186

Merged
merged 3 commits into from
Mar 9, 2023
Merged

Add a way to do command line completion in sanssh. #186

merged 3 commits into from
Mar 9, 2023

Conversation

sfc-gh-srhodes
Copy link
Collaborator

See steps in the readme for how to enable this. It relies on invoking sanssh for suggestions. Downstream clients can use client.AddCommandLineCompletion to take advantage of this.

This completion automatically registers subcommand packages and their flags. To register subcommands of subcommands, the parent subcommand needs to implement HasSubpackage. I've updated all the services to implement that interface.

There's also a PredictArgs interface that can be used to predict command line arguments of subcommands. I've experimented with adding this to some of the fdb subcommands.

Finally, I've tweaked the default fail-early behavior so that there's help text from running a command like sanssh or sanssh exec insted of a cryptic "Must set a target or a proxy" error.

@sfc-gh-srhodes
Copy link
Collaborator Author

I ended up adding a more comprehensive unit test.

Copy link
Collaborator

@sfc-gh-jallie sfc-gh-jallie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

See steps in the readme for how to enable this. It relies on invoking sanssh for suggestions. Downstream clients can use `client.AddCommandLineCompletion` to take advantage of this.

This completion automatically registers subcommand packages and their flags. To register subcommands of subcommands, the parent subcommand needs to implement HasSubpackage. I've updated all the services to implement that interface.

There's also a PredictArgs interface that can be used to predict command line arguments of subcommands. I've experimented with adding this to some of the fdb subcommands.

Finally, I've tweaked the default fail-early behavior so that there's help text from running a command like `sanssh` or `sanssh exec` insted of a cryptic "Must set a target or a proxy" error.
The tests helped catch that I wasn't always handling the final args after a subcommand correctly. The flag handling now autocompletes --foo= in addition to --foo.
@sfc-gh-srhodes sfc-gh-srhodes enabled auto-merge (squash) March 9, 2023 17:23
@sfc-gh-srhodes sfc-gh-srhodes merged commit 0638313 into Snowflake-Labs:main Mar 9, 2023
@sfc-gh-srhodes sfc-gh-srhodes deleted the srhodes-command-line-completion branch March 9, 2023 18:01
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