mirror of
https://github.com/jimeh/rbheap.git
synced 2026-02-19 04:46:40 +00:00
Switch from kingpin to cobra
This enables easier use of sub-commands for flexibility
This commit is contained in:
66
cmd/leak.go
Normal file
66
cmd/leak.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jimeh/rbheapleak/leak"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var leakOpts = struct {
|
||||
Format string
|
||||
Verbose bool
|
||||
}{}
|
||||
|
||||
// leakCmd represents the leak command
|
||||
var leakCmd = &cobra.Command{
|
||||
Use: "leak [flags] <dump-A> <dump-B> <dump-C>",
|
||||
Short: "Find objects which are likely leaked memory.",
|
||||
Long: `Find objects which are likely leaked memory.
|
||||
|
||||
Compares the objects in three different dumps (A, B, C), to identify which
|
||||
objects are present in both B and C, and not present in A.`,
|
||||
|
||||
// Args: cobra.ExactArgs(3),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
usage_er(cmd, fmt.Sprintf("requires 3 args, received %d", len(args)))
|
||||
}
|
||||
|
||||
finder := leak.NewFinder(args[0], args[1], args[2])
|
||||
finder.Verbose = leakOpts.Verbose
|
||||
|
||||
err := finder.Process()
|
||||
if err != nil {
|
||||
er(err)
|
||||
}
|
||||
|
||||
switch leakOpts.Format {
|
||||
case "hex":
|
||||
finder.PrintLeakedAddresses()
|
||||
case "full":
|
||||
finder.PrintLeakedObjects()
|
||||
default:
|
||||
usage_er(
|
||||
cmd,
|
||||
fmt.Sprintf("\"%s\" is not a valid format", leakOpts.Format),
|
||||
)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(leakCmd)
|
||||
|
||||
leakCmd.PersistentFlags().StringVarP(
|
||||
&leakOpts.Format,
|
||||
"format", "f", "hex",
|
||||
"Output format: \"hex\" / \"full\"",
|
||||
)
|
||||
|
||||
leakCmd.PersistentFlags().BoolVarP(
|
||||
&leakOpts.Verbose,
|
||||
"verbose", "v", false,
|
||||
"print verbose information",
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user