Implement special flags for dump and reset db
This commit is contained in:
31
main.go
31
main.go
@@ -62,6 +62,15 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
workdone, err := HandleSpecialArgs(args, err, db)
|
||||
if err != nil {
|
||||
logger.Error("Failed to handle special args: %v", err)
|
||||
return
|
||||
}
|
||||
if workdone {
|
||||
return
|
||||
}
|
||||
|
||||
// The plan is:
|
||||
// Load all commands
|
||||
commands, err := utils.LoadCommands(args)
|
||||
@@ -268,6 +277,28 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func HandleSpecialArgs(args []string, err error, db utils.DB) (bool, error) {
|
||||
switch args[0] {
|
||||
case "reset":
|
||||
err = utils.ResetAllFiles(db)
|
||||
if err != nil {
|
||||
logger.Error("Failed to reset all files: %v", err)
|
||||
return true, err
|
||||
}
|
||||
logger.Info("All files reset")
|
||||
return true, nil
|
||||
case "dump":
|
||||
err = db.RemoveAllFiles()
|
||||
if err != nil {
|
||||
logger.Error("Failed to remove all files from database: %v", err)
|
||||
return true, err
|
||||
}
|
||||
logger.Info("All files removed from database")
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func CreateExampleConfig() {
|
||||
commands := []utils.ModifyCommand{
|
||||
{
|
||||
|
Reference in New Issue
Block a user