Skip to content

Instantly share code, notes, and snippets.

@afarid
Created October 2, 2022 13:12
Show Gist options
  • Select an option

  • Save afarid/d12e2ff4b723459020d36c89dd4e7d6c to your computer and use it in GitHub Desktop.

Select an option

Save afarid/d12e2ff4b723459020d36c89dd4e7d6c to your computer and use it in GitHub Desktop.
var removeCmd = &cobra.Command{
....
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 1 {
todoName := args[0]
for i := 0; i < len(todos.Todos); i++ {
if todos.Todos[i].Name == todoName {
todos.Todos = append(todos.Todos[0:i], todos.Todos[i+1:]...)
break
}
}
viper.Set("todos", todos.Todos)
err := viper.WriteConfig()
if err != nil {
fmt.Println(err)
return
}
}
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment