From ae1d1ec0137667ce817f7c662f20a407e35bc641 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 28 May 2023 13:32:34 +0200 Subject: [PATCH] credentials: HandleCommand(): improve error for unknown command/action - 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 --- credentials/credentials.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/credentials/credentials.go b/credentials/credentials.go index 92a567b..6155e49 100644 --- a/credentials/credentials.go +++ b/credentials/credentials.go @@ -64,9 +64,9 @@ func usage() string { return fmt.Sprintf("Usage: %s ", Name) } -// 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 { - switch key { +// HandleCommand runs a helper to execute a credential action. +func HandleCommand(helper Helper, action string, in io.Reader, out io.Writer) error { + switch action { case "store": return Store(helper, in) case "get": @@ -77,8 +77,9 @@ func HandleCommand(helper Helper, key string, in io.Reader, out io.Writer) error return List(helper, out) case "version": return PrintVersion(out) + default: + return fmt.Errorf("%s: unknown action: %s", Name, action) } - return fmt.Errorf("Unknown credential action `%s`", key) } // Store uses a helper and an input reader to save credentials.