Return non-zero exit code on node sub-commands
Signed-off-by: xu yang <xyang@ciq.com>
This commit is contained in:
@@ -23,12 +23,10 @@ import (
|
||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
canWrite, err := apiutil.CanWriteConfig()
|
||||
if err != nil {
|
||||
wwlog.Error("While checking whether can write config, err: %w", err)
|
||||
os.Exit(1)
|
||||
return fmt.Errorf("while checking whether can write config, err: %w", err)
|
||||
}
|
||||
if !canWrite.CanWriteConfig {
|
||||
wwlog.Error("Can't write to config exiting")
|
||||
os.Exit(1)
|
||||
return fmt.Errorf("can not write to config exiting")
|
||||
}
|
||||
editor := os.Getenv("EDITOR")
|
||||
if editor == "" {
|
||||
@@ -46,7 +44,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
_ = yaml.Unmarshal([]byte(nodeListMsg.NodeConfMapYaml), nodeMap)
|
||||
file, err := os.CreateTemp(os.TempDir(), "ww4NodeEdit*.yaml")
|
||||
if err != nil {
|
||||
wwlog.Error("Could not create temp file:%s \n", err)
|
||||
return fmt.Errorf("could not create temp file: %s", err)
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
yamlTemplate := node.UnmarshalConf(node.NodeConf{}, []string{"tagsdel", "default", "profiles"})
|
||||
@@ -65,8 +63,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
sum1 := hex.EncodeToString(hasher.Sum(nil))
|
||||
err = util.ExecInteractive(editor, file.Name())
|
||||
if err != nil {
|
||||
wwlog.Error("Editor process existed with non-zero\n")
|
||||
os.Exit(1)
|
||||
return fmt.Errorf("editor process existed with non-zero")
|
||||
}
|
||||
_, _ = file.Seek(0, 0)
|
||||
hasher.Reset()
|
||||
@@ -125,8 +122,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
Hash: newHash.Hash,
|
||||
})
|
||||
if err != nil {
|
||||
wwlog.Error("Got following problem when writing back yaml: %s", err)
|
||||
os.Exit(1)
|
||||
return fmt.Errorf("got following problem when writing back yaml: %s", err)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user