diff --git a/main.go b/main.go index 2db7938..f2f00ed 100644 --- a/main.go +++ b/main.go @@ -184,6 +184,9 @@ func main() { case "uninstall": runUninstallCommand() return + case "dump": + runDumpCommand() + return } } @@ -277,6 +280,29 @@ func runUpdateCommand() { fmt.Printf(" Successfully updated to %sv%s%s.\n\n", ansiCyan, latest, ansiReset) } +func runDumpCommand() { + if os.Getuid() != 0 { + reexecWithSudo() + return + } + + config := loadConfig() + + metrics, err := collectMetrics(config) + if err != nil { + fmt.Fprintf(os.Stderr, "%sError collecting metrics: %v%s\n", ansiRed, err, ansiReset) + os.Exit(1) + } + + out, err := json.MarshalIndent(metrics, "", " ") + if err != nil { + fmt.Fprintf(os.Stderr, "%sError marshalling metrics: %v%s\n", ansiRed, err, ansiReset) + os.Exit(1) + } + + fmt.Println(string(out)) +} + func reexecWithSudo() { self, err := os.Executable() if err != nil {