Migrate the CLI from the standard library to Cobra #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a proposal in the form of a PR to migrate the CLI from the standard library to the Cobra package under the Apache License 2.0. Cobra is used by Kubernetes, the GitHub CLI, GoReleaser and many other popular projects.
I can think of several benefits for this project with this migration:
--ssid
) and short (-s
) option formats.A couple of reasons why you may not want to migrate:
Command Options
To transition to the combined long and short options, I've changed some of the options. These are simply my suggestions and should be carefully reviewed to ensure it's what you want. I can make any changes here that you'd like.
Flag usage from the CLI changes a bit because of the long and short options.
The changes are:
-file
is now--output
and-o
which seems to be consistent with other utilities-enc
is now--protocol
and-p
because it is the protocol being specified--ssid
is-i
for ID so it doesn't interfere with the-s
(size) short optionI'm personally not chained to any of this, so if you want the Cobra implementation but with different option names, let me know and I can change it, or you can approve and merge then change to your liking, etc.
The No Password Edge Case
When the user presents an empty key/password via the CLI (
--enc ""
), the user would still be prompted for password input instead of enabling no enryption protocol (NONE
) which is what the user probably wants. This could probably be resolved using the old standard library but would require more than a couple lines of code. Cobra's pflag library makes this easy with theChanged
method which has been implemented in this PR.README
It has been updated with the new automatically generated Cobra help and the example command incantation updated with the new option names. For this PR, the new help output is:
And the version output example:
Why?
I'm submitting all these PRs because I use this utility every week to connect to a protected wifi network. I'm a software developer that enjoys coding in Go. Put them together and I just wanted to give back. I also have the opinion that Cobra should be used to process user input for nearly every Go application. Thanks for accepting my previous PRs.