1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-13 16:01:28 +05:30

credentials: Serve(): simplify error-handling logic

Don't use an err if we can print the error immediately :)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2023-05-28 13:19:24 +02:00
parent 0dbcdb66a7
commit db0ac44c97
+7 -7
View File
@@ -49,21 +49,21 @@ func SetCredsLabel(label string) {
// It uses os.Stdin as input and os.Stdout as output. // It uses os.Stdin as input and os.Stdout as output.
// This function terminates the program with os.Exit(1) if there is an error. // This function terminates the program with os.Exit(1) if there is an error.
func Serve(helper Helper) { func Serve(helper Helper) {
var err error
if len(os.Args) != 2 { if len(os.Args) != 2 {
err = fmt.Errorf("Usage: %s <store|get|erase|list|version>", Name) _, _ = fmt.Fprintln(os.Stdout, usage())
os.Exit(1)
} }
if err == nil { if err := HandleCommand(helper, os.Args[1], os.Stdin, os.Stdout); err != nil {
err = HandleCommand(helper, os.Args[1], os.Stdin, os.Stdout)
}
if err != nil {
_, _ = fmt.Fprintln(os.Stdout, err) _, _ = fmt.Fprintln(os.Stdout, err)
os.Exit(1) os.Exit(1)
} }
} }
func usage() string {
return fmt.Sprintf("Usage: %s <store|get|erase|list|version>", Name)
}
// HandleCommand uses a helper and a key to run a credential action. // HandleCommand uses a helper and a key to run a credential action.
func HandleCommand(helper Helper, key string, in io.Reader, out io.Writer) error { func HandleCommand(helper Helper, key string, in io.Reader, out io.Writer) error {
switch key { switch key {