prompt cmd does not fail if the history file cannot be read
@@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"io/ioutil"
+ "log"
"os"
"strings"
@@ -69,11 +70,17 @@ var promptModeCmd = &cobra.Command{
promptHistory = make([]string, 0, 256)
home, err := homedir.Dir()
if err != nil {
- return err
+ if viper.GetBool("debug") {
+ log.Printf("failed to get home directory: %v", err)
+ }
+ return nil
}
content, err := ioutil.ReadFile(home + "/.gnmic.history")
if err != nil {
- return err
+ if viper.GetBool("debug") {
+ log.Printf("failed to read history file: %v", err)
+ }
+ return nil
}
history := strings.Split(string(content), "\n")
for i := range history {
@@ -81,7 +88,7 @@ var promptModeCmd = &cobra.Command{
promptHistory = append(promptHistory, history[i])
}
}
- return err
+ return nil
},
PostRun: func(cmd *cobra.Command, args []string) {
cmd.ResetFlags()
