mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 17:44:59 +09:00
cli debug dump-tree
This commit is contained in:
parent
52f0ffe3b7
commit
6a226216ca
2 changed files with 71 additions and 0 deletions
|
@ -15,6 +15,8 @@ func init() {
|
|||
// subcommands
|
||||
CliCmd.AddCommand(migrateCmd)
|
||||
CliCmd.AddCommand(cafeCmd)
|
||||
CliCmd.AddCommand(debugCmd)
|
||||
|
||||
// local flags
|
||||
}
|
||||
|
||||
|
|
69
cmd/cli/debug.go
Normal file
69
cmd/cli/debug.go
Normal file
|
@ -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")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue