Skip to content

Commit

Permalink
purge logs command
Browse files Browse the repository at this point in the history
  • Loading branch information
sambukowski committed Aug 7, 2024
1 parent 9720f76 commit b095c44
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions modules/cli/cmd/devrunner/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,42 @@ func purgeAllCmdHandler(c *cobra.Command, _ []string) {
log.Infof("Successfully deleted instance '%s'", instance)
}

// purgeLogsCmd represents the 'purge logs' command
var purgeLogsCmd = &cobra.Command{
Use: "logs",
Short: "Delete all logs for a given instance. Re-initializing is NOT required after using this command.",
Run: purgeLogsCmdHandler,
}

func purgeLogsCmdHandler(c *cobra.Command, _ []string) {
flagHandler := cmd.CreateCliFlagHandler(c, cmd.EnvPrefix)

instance := flagHandler.GetValue("instance")
config.IsInstanceNameValidOrPanic(instance)

homeDir := cmd.GetUserHomeDirOrPanic()
logDir := filepath.Join(homeDir, ".astria", instance, config.LogsDirName)

log.Infof("Deleting logs for instance '%s'", instance)

// remove the state files for sequencer and Cometbft
err := os.RemoveAll(logDir)
if err != nil {
fmt.Println("Error removing file:", err)
return
}
cmd.CreateDirOrPanic(logDir)

log.Infof("Successfully deleted logs for instance '%s'", instance)

}

func init() {
// top level command
devCmd.AddCommand(purgeCmd)

// subcommands
purgeCmd.AddCommand(purgeBinariesCmd)
purgeCmd.AddCommand(purgeAllCmd)
purgeCmd.AddCommand(purgeLogsCmd)
}

0 comments on commit b095c44

Please sign in to comment.