Skip to content

Commit db0ac44

Browse files
committed
credentials: Serve(): simplify error-handling logic
Don't use an err if we can print the error immediately :) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 0dbcdb6 commit db0ac44

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

credentials/credentials.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ func SetCredsLabel(label string) {
4949
// It uses os.Stdin as input and os.Stdout as output.
5050
// This function terminates the program with os.Exit(1) if there is an error.
5151
func Serve(helper Helper) {
52-
var err error
5352
if len(os.Args) != 2 {
54-
err = fmt.Errorf("Usage: %s <store|get|erase|list|version>", Name)
55-
}
56-
57-
if err == nil {
58-
err = HandleCommand(helper, os.Args[1], os.Stdin, os.Stdout)
53+
_, _ = fmt.Fprintln(os.Stdout, usage())
54+
os.Exit(1)
5955
}
6056

61-
if err != nil {
57+
if err := HandleCommand(helper, os.Args[1], os.Stdin, os.Stdout); err != nil {
6258
_, _ = fmt.Fprintln(os.Stdout, err)
6359
os.Exit(1)
6460
}
6561
}
6662

63+
func usage() string {
64+
return fmt.Sprintf("Usage: %s <store|get|erase|list|version>", Name)
65+
}
66+
6767
// HandleCommand uses a helper and a key to run a credential action.
6868
func HandleCommand(helper Helper, key string, in io.Reader, out io.Writer) error {
6969
switch key {

0 commit comments

Comments
 (0)