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

feat: standalone cli #235

Merged
merged 14 commits into from
Mar 17, 2020
Merged

feat: standalone cli #235

merged 14 commits into from
Mar 17, 2020

Conversation

sh0rez
Copy link
Member

@sh0rez sh0rez commented Mar 9, 2020

Big PR implementing the parts of spf13/cobra we actually use ... turns out not that much after all.

Motivation behind this was that spf13/cobra is a big library with many dependencies, that we don't use altogether. Furthermore, we want native completion using posener/complete, which I hacked upon cobra in an ugly way.

The new package pkg/cli has clearly defined interfaces for all tasks we need, a simple cli.Command struct with only the most basic features (enough for 90% of the cases) which fits exactly what Tanka needs.

I expect to move this package out of Tanka in the long run, especially if we need it in other projects. For the time being it seems simplest to leave it here until it matures.

Fixes #191

@sh0rez sh0rez added kind/enhancement Improve something existing component/cli Command Line Interface labels Mar 9, 2020
@sh0rez sh0rez requested review from rfratto and mplzik March 9, 2020 17:47
@sh0rez sh0rez self-assigned this Mar 9, 2020
Takes the required parts from `spf13/cobra` in a heavily simplified way
and adds these to `pkg/cli` so that we can become independent of that
massive library, which we use only a small subset from.

In the future, this new package is supposed to integrate more tightly
with `posener/complete`, so we have a fully integrated cli package that
fits our needs:
- command parsing
- arbitrary flag position
- native (non-script) suggestions
- struct based API
Works without, no need to clutter that type
Adds native support for CLI argument and flag completion, but also
validation of arguments.
Migrates from `spf13/cobra` to our very own implementation in `pkg/cli`,
which is much simpler (less features, only the ones we need) and
contains native support for CLI completions.
Adds a command to each app to install the CLI completions
Causes formatting changes, which we do not want.
Copy link
Member

@rfratto rfratto left a comment

Choose a reason for hiding this comment

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

LGTM, have one nit.

I do want to say that I only validated this for correctness. I put off reviewing this for so long because introducing more internal complexity that we have to maintain ourselves makes me a little nervous. I shared these thoughts with @sh0rez and he agrees.

Overall, I don't think this is a lot of code we're adding, so I don't think it's that much of an issue, and I trust the judgment on making the call to replace Cobra with something slimmer. I personally would like to see this brought out of the repository though and made into its own project.

pkg/cli/command.go Outdated Show resolved Hide resolved
pkg/cli/command.go Outdated Show resolved Hide resolved
Copy link
Member

@rfratto rfratto left a comment

Choose a reason for hiding this comment

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

🚀

@sh0rez sh0rez merged commit fdf0ca1 into master Mar 17, 2020
@sh0rez sh0rez deleted the standalone-cli branch March 17, 2020 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/cli Command Line Interface kind/enhancement Improve something existing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tk completion breaks for partial flags
2 participants