| 27 | ) |
| 28 | |
| 29 | func RegisterRecorderCommand() *cobra.Command { |
| 30 | recorder := &cobra.Command{ |
| 31 | Use: "recorder", |
| 32 | Short: "debug recorder service commands", |
| 33 | Run: func(cmd *cobra.Command, args []string) { |
| 34 | fmt.Printf("please run with 'cache'.\n") |
| 35 | }, |
| 36 | } |
| 37 | |
| 38 | var onlyDiffBase bool |
| 39 | var onlyToolMap bool |
| 40 | var subDomain string |
| 41 | var resourceType string |
| 42 | var field string |
| 43 | cache := &cobra.Command{ |
| 44 | Use: "cache domain-lcuuid", |
| 45 | Short: "get recorder cache of one domain by lcuuid", |
| 46 | Example: "deepflow-ctl recorder cache bcb21453-0833-5d94-b4cf-adb3879400c9", |
| 47 | Run: func(cmd *cobra.Command, args []string) { |
| 48 | getCache(cmd, args, subDomain, onlyDiffBase, onlyToolMap, resourceType, field) |
| 49 | }, |
| 50 | } |
| 51 | cache.Flags().StringVarP( |
| 52 | &subDomain, "subdomain-lcuuid", "s", "", fmt.Sprintf("get resource cache of specified subdomain"), |
| 53 | ) |
| 54 | cache.Flags().BoolVarP( |
| 55 | &onlyDiffBase, "diff-base", "b", false, fmt.Sprintf("if set, only get diff base cache"), |
| 56 | ) |
| 57 | cache.Flags().BoolVarP( |
| 58 | &onlyToolMap, "tool-map", "t", false, fmt.Sprintf("if set, only get tool map cache"), |
| 59 | ) |
| 60 | cache.Flags().StringVarP( |
| 61 | &resourceType, "resource-type", "r", "", fmt.Sprintf("only applies to diff-base. Get resource cache of specified resources, split by comma.Supported choices: %v", common.RESOURCE_TYPES), |
| 62 | ) |
| 63 | cache.Flags().StringVarP( |
| 64 | &field, "field", "f", "", fmt.Sprintf("only applies to tool-map. Get resource cache of specified fields, split by comma."), |
| 65 | ) |
| 66 | |
| 67 | recorder.AddCommand(cache) |
| 68 | |
| 69 | return recorder |
| 70 | } |
| 71 | |
| 72 | func getCache(cmd *cobra.Command, args []string, subDomain string, onlyDiffBase, onlyToolMap bool, resourceType, field string) { |
| 73 | if len(args) == 0 { |