2015-05-01 23:02:21 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2016-01-07 22:59:38 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2015-12-11 03:35:48 +00:00
|
|
|
"github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/spf13/cobra"
|
2015-05-01 23:02:21 +00:00
|
|
|
|
2015-12-11 03:35:48 +00:00
|
|
|
"github.com/khlieng/dispatch/storage"
|
2015-05-01 23:02:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var clearCmd = &cobra.Command{
|
|
|
|
Use: "clear",
|
2016-01-07 22:59:38 +00:00
|
|
|
Short: "Clear database and message logs",
|
2015-05-01 23:02:21 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2016-01-07 22:59:38 +00:00
|
|
|
err := os.Remove(storage.Path.Database())
|
|
|
|
if err == nil || os.IsNotExist(err) {
|
|
|
|
log.Println("Database cleared")
|
|
|
|
} else {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = os.RemoveAll(storage.Path.Logs())
|
|
|
|
if err == nil {
|
|
|
|
log.Println("Logs cleared")
|
|
|
|
} else {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2015-05-01 23:02:21 +00:00
|
|
|
},
|
|
|
|
}
|