diff --git a/cmd/cli/cli.go b/cmd/cli/cli.go index 1cdd9b810..042bb07be 100644 --- a/cmd/cli/cli.go +++ b/cmd/cli/cli.go @@ -15,6 +15,8 @@ func init() { // subcommands CliCmd.AddCommand(migrateCmd) CliCmd.AddCommand(cafeCmd) + CliCmd.AddCommand(debugCmd) + // local flags } diff --git a/cmd/cli/debug.go b/cmd/cli/debug.go new file mode 100644 index 000000000..e5dc82459 --- /dev/null +++ b/cmd/cli/debug.go @@ -0,0 +1,69 @@ +package main + +import ( + "github.com/anytypeio/go-anytype-middleware/core/anytype" + "github.com/anytypeio/go-anytype-middleware/core/debug" + "github.com/anytypeio/go-anytype-middleware/core/event" + "github.com/anytypeio/go-anytype-middleware/pb" + "github.com/anytypeio/go-anytype-middleware/util/console" + "github.com/spf13/cobra" + "os" +) + +var debugCmd = &cobra.Command{ + Use: "debug", + Short: "Debug commands", +} + +var ( + debugRepoPath string + debugAccount string + debugThread string + debugOutputFile string + +) + +var dumpTree = &cobra.Command{ + Use: "dump-tree", + Short: "Dumps anonymized tree of changes for specific thread", + Run: func(c *cobra.Command, args []string) { + if debugAccount == "" { + console.Fatal("please specify account") + } + if debugThread == "" { + console.Fatal("please specify thread") + } + + comps, err := anytype.BootstrapConfigAndWallet(false, debugRepoPath, debugAccount) + if err != nil { + console.Fatal("failed to bootstrap anytype: %s", err.Error()) + } + + comps = append(comps, event.NewCallbackSender(func(event *pb.Event) {})) + + app, err := anytype.StartNewApp(comps...) + if err != nil { + console.Fatal("failed to start anytype: %s", err.Error()) + } + + dbg := app.MustComponent(debug.CName).(debug.Debug) + + filename, err := dbg.DumpTree(debugThread, debugOutputFile) + if err != nil { + console.Fatal("failed to dump tree: %s", err.Error()) + } + console.Success("file saved: %s", filename) + }, +} + + +func init() { + // subcommands + homeDir, _ := os.UserHomeDir() + + debugCmd.AddCommand(dumpTree) + debugCmd.PersistentFlags().StringVarP(&debugRepoPath, "repo", "r", homeDir+"/.config/anytype2/data", "path to dir with accounts folder") + debugCmd.PersistentFlags().StringVarP(&debugAccount, "account", "a", "", "id of account in the repo folder") + debugCmd.PersistentFlags().StringVarP(&debugThread, "thread", "t", "", "id of thread to debug") + debugCmd.PersistentFlags().StringVarP(&debugOutputFile, "out", "o", "./", "folder to save file") +}