Implement special flags for dump and reset db

This commit is contained in:
2025-07-20 11:47:11 +02:00
parent 774ac0f0ca
commit 9ecbbff6fa
3 changed files with 76 additions and 0 deletions

31
main.go
View File

@@ -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{
{