-
Notifications
You must be signed in to change notification settings - Fork 175
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
Assorted improvements, and add "--version, -v", and "--help, -h" flags #284
Conversation
Don't set Env if not set; the default is already handled if it's nil; from the documentation: https://pkg.go.dev/os/exec@go1.20.4#Cmd.Env // If Env is nil, the new process uses the current process's // environment. Use `os/exec/Cmd.Environ()` instead of `os.Environ()`, which was added in go1.19, and handles additional environment variables, such as `PWD` on POSIX systems, and `SYSTEMROOT` on Windows. https://pkg.go.dev/os/exec@go1.20.4#Cmd.Environ Also remove a redundant `fmt.Sprintf()`, as we're only concatenating strings. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- Explicitly suppress some unhandled errors - Use "pass" credentials helper in examples, which is available on more platforms than "secretservice" (only supporte on Linux) - Update domain and username in examples. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
GNU guidelines describes; https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion The program’s name should be a constant string; don’t compute it from argv[0]. The idea is to state the standard or canonical name for the program, not its file name. Although the above recommendation is for `--version` output, it probably makes sense to do the same for the "usage" output. Before this change: /usr/local/bin/docker-credential-osxkeychain invalid command Usage: /usr/local/bin/docker-credential-osxkeychain <store|get|erase|list|version> /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain invalid command Usage: /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain <store|get|erase|list|version> With this patch: /usr/local/bin/docker-credential-osxkeychain invalid command Usage: docker-credential-osxkeychain <store|get|erase|list|version> /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain invalid command Usage: docker-credential-osxkeychain <store|get|erase|list|version> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Don't use an err if we can print the error immediately :) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- renamed the "key" variable, which was slightly confusing - include the name of the binary in the error Before this change: docker-credential-osxkeychain nosuchaction Unknown credential action `nosuchaction` After this change: docker-credential-osxkeychain nosuchaction docker-credential-osxkeychain: unknown action: nosuchaction Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
As recommended in the GNU documentation; - https://www.gnu.org/prep/standards/standards.html#g_t_002d_002dversion - https://www.gnu.org/prep/standards/standards.html#g_t_002d_002dhelp With this patch: $ docker-credential-osxkeychain --version docker-credential-osxkeychain (github.com/docker/docker-credential-helpers) v0.7.0-51-g26c426e.m $ docker-credential-osxkeychain -v docker-credential-osxkeychain (github.com/docker/docker-credential-helpers) v0.7.0-51-g26c426e.m $ docker-credential-osxkeychain --help Usage: docker-credential-osxkeychain <store|get|erase|list|version> $ docker-credential-osxkeychain -h Usage: docker-credential-osxkeychain <store|get|erase|list|version> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #284 +/- ##
==========================================
- Coverage 55.23% 54.68% -0.56%
==========================================
Files 9 9
Lines 668 673 +5
==========================================
- Hits 369 368 -1
- Misses 256 262 +6
Partials 43 43
☔ View full report in Codecov by Sentry. |
case "--version", "-v": | ||
_ = PrintVersion(os.Stdout) | ||
os.Exit(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need an extra version flag as we already have the version
action?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly making them a bit more standard; GNU (and POSIX) define --help and --version as the minimum; https://www.gnu.org/prep/standards/standards.html#Command_002dLine-Interfaces
All programs should support two standard options: ‘--version’ and ‘--help’. CGI programs should accept these as command-line options, and also if given as the PATH_INFO; for instance, visiting ‘http://example.org/p.cgi/--help’ in a browser should output the same information as invoking ‘p.cgi --help’ from the command line.
I could omit the shorthand ones though
See individual commits for details. Some outlined below:
client: use os/exec/Cmd.Environ() instead of os.Environ()
Don't set Env if not set; the default is already handled if it's nil; from
the documentation: https://pkg.go.dev/os/exec@go1.20.4#Cmd.Env
Use
os/exec/Cmd.Environ()
instead ofos.Environ()
, which was added ingo1.19, and handles additional environment variables, such as
PWD
on POSIXsystems, and
SYSTEMROOT
on Windows. https://pkg.go.dev/os/exec@go1.20.4#Cmd.EnvironAlso remove a redundant
fmt.Sprintf()
, as we're only concatenating strings.credentials: Serve(): use "Name instead of "os.Args[0]" for usage output
GNU guidelines describes; https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion
Although the above recommendation is for
--version
output, it probably makessense to do the same for the "usage" output.
Before this change:
With this patch:
credentials: Serve(): simplify error-handling logic
Don't use an err if we can print the error immediately :)
credentials: HandleCommand(): improve error for unknown command/action
Before this change:
After this change:
credentials: Serve(): implement "--version, -v", and "--help, -h" flags
As recommended in the GNU documentation;
With this patch:
credentials: define consts for supported actions (sub-commands)