Updated code for less indentation
@@ -31,17 +31,19 @@ var promptModeCmd = &cobra.Command{
// load history
promptHistory = make([]string, 0, 256)
home, err := homedir.Dir()
- if err == nil {
+ if err != nil {
+ return err
+ }
content, err := ioutil.ReadFile(home + "/.gnmic.history")
- if err == nil {
+ if err != nil {
+ return err
+ }
history := strings.Split(string(content), "\n")
for i := range history {
if history[i] != "" {
promptHistory = append(promptHistory, history[i])
}
}
- }
- }
return err
},
PostRun: func(cmd *cobra.Command, args []string) {
@@ -57,9 +59,13 @@ var promptQuitCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
// save history
home, err := homedir.Dir()
- if err == nil {
+ if err != nil {
+ os.Exit(0)
+ }
f, err := os.Create(home + "/.gnmic.history")
- if err == nil {
+ if err != nil {
+ os.Exit(0)
+ }
l := len(promptHistory)
if l > 128 {
promptHistory = promptHistory[l-128:]
@@ -68,8 +74,6 @@ var promptQuitCmd = &cobra.Command{
f.WriteString(promptHistory[i] + "\n")
}
f.Close()
- }
- }
os.Exit(0)
},
}
