From 45864ed624cb181df052f2baee5986210ccc92d5 Mon Sep 17 00:00:00 2001 From: namusyaka Date: Wed, 4 Nov 2020 09:24:52 +0900 Subject: [PATCH] make kompose exit with 1 if error (#1343) Old code passes -1 to os.Exit and the value is directly passed to syscall. The behavior with -1 depends on environments (most cases should convert into 255 though) This commit is to remove unnecessary the ambiguity and change it to use 1 instead of 255. --- cmd/root.go | 12 ++++-------- main.go | 11 +++++++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 6f658e73..a5d60fee 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,8 +17,6 @@ limitations under the License. package cmd import ( - "fmt" - "os" "strings" log "github.com/sirupsen/logrus" @@ -87,12 +85,10 @@ var RootCmd = &cobra.Command{ }, } -// Execute TODO: comment -func Execute() { - if err := RootCmd.Execute(); err != nil { - fmt.Println(err) - os.Exit(-1) - } +// Execute executes the root level command. +// It returns an erorr if any. +func Execute() error { + return RootCmd.Execute() } func init() { diff --git a/main.go b/main.go index 9a0df601..35b97068 100644 --- a/main.go +++ b/main.go @@ -16,8 +16,15 @@ limitations under the License. package main -import "github.com/kubernetes/kompose/cmd" +import ( + "log" + + "github.com/kubernetes/kompose/cmd" +) func main() { - cmd.Execute() + if err := cmd.Execute(); err != nil { + log.SetFlags(0) + log.Fatal(err) + } }