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:
- Standard and familiar CLI interface like those of the projects mentioned above.
- Long (
--ssid) and short (
-s) option formats.
- Built in help output.
- Automatic version option.
- A more full featured flags library in general.
A couple of reasons why you may not want to migrate:
- Dragging yet another non-standard library into this project.
- Larger executable (from about 3 mb to about 3.5 mb).
- You have a problem with the Apache License 2.0.
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
-o which seems to be consistent with other utilities
-enc is now
-p because it is the protocol being specified
- The short form of
-i for ID so it doesn't interfere with the
-s (size) short option
I'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 the
Changed method which has been implemented in this PR.
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:
$ wifiqr --help
wifiqr is a WiFi QR code generator
It is used to create a QR code containing the login details such as
the name, password, and encryption type. This QR code can be scanned
using Google Lens or other QR code reader to connect to the network.
It is Android and iOS compatible.
If the options necessary for creating the QR code are not given on
the command line, the user will be prompted for the information.
-h, --help help for wifiqr
--hidden Hidden SSID
-k, --key string Wireless password (pre-shared key / PSK)
-o, --output string PNG file for output (default stdout)
-p, --protocol string Wireless network encryption protocol (WPA2, WPA, WEP, NONE). (default "WPA2")
-s, --size int Image width and height in pixels (default 256)
-i, --ssid string Wireless network name
-v, --version version for wifiqr
And the version output example:
$ wifiqr --version
wifiqr version 0.9.9
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.