Convert CLI to urfave v2
Followed the Migration Guide at https://cli.urfave.org/migrate-v1-to-v2/ The major changes not pointed out in the migration guide are: - context.Args() no longer produces a []slice, so context.Args().Slice() in substitued - All cli.Global***** are deprecated (the migration guide is somewhat unclear on this) Signed-off-by: Derek Nola <derek.nola@suse.com> Vendor in urfave cli/v2 Signed-off-by: Derek Nola <derek.nola@suse.com> Fix NewStringSlice calls Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
@@ -24,7 +24,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/v2/defaults"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
type pprofDialer struct {
|
||||
@@ -33,17 +33,18 @@ type pprofDialer struct {
|
||||
}
|
||||
|
||||
// Command is the cli command for providing golang pprof outputs for containerd
|
||||
var Command = cli.Command{
|
||||
var Command = &cli.Command{
|
||||
Name: "pprof",
|
||||
Usage: "Provide golang pprof outputs for containerd",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "debug-socket, d",
|
||||
Usage: "Socket path for containerd's debug server",
|
||||
Value: defaults.DefaultDebugAddress,
|
||||
&cli.StringFlag{
|
||||
Name: "debug-socket",
|
||||
Aliases: []string{"d"},
|
||||
Usage: "Socket path for containerd's debug server",
|
||||
Value: defaults.DefaultDebugAddress,
|
||||
},
|
||||
},
|
||||
Subcommands: []cli.Command{
|
||||
Subcommands: []*cli.Command{
|
||||
pprofBlockCommand,
|
||||
pprofGoroutinesCommand,
|
||||
pprofHeapCommand,
|
||||
@@ -53,11 +54,11 @@ var Command = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var pprofGoroutinesCommand = cli.Command{
|
||||
var pprofGoroutinesCommand = &cli.Command{
|
||||
Name: "goroutines",
|
||||
Usage: "Dump goroutine stack dump",
|
||||
Flags: []cli.Flag{
|
||||
cli.UintFlag{
|
||||
&cli.UintFlag{
|
||||
Name: "debug",
|
||||
Usage: "Debug pprof args",
|
||||
Value: 2,
|
||||
@@ -77,11 +78,11 @@ var pprofGoroutinesCommand = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var pprofHeapCommand = cli.Command{
|
||||
var pprofHeapCommand = &cli.Command{
|
||||
Name: "heap",
|
||||
Usage: "Dump heap profile",
|
||||
Flags: []cli.Flag{
|
||||
cli.UintFlag{
|
||||
&cli.UintFlag{
|
||||
Name: "debug",
|
||||
Usage: "Debug pprof args",
|
||||
Value: 0,
|
||||
@@ -101,16 +102,17 @@ var pprofHeapCommand = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var pprofProfileCommand = cli.Command{
|
||||
var pprofProfileCommand = &cli.Command{
|
||||
Name: "profile",
|
||||
Usage: "CPU profile",
|
||||
Flags: []cli.Flag{
|
||||
cli.DurationFlag{
|
||||
Name: "seconds,s",
|
||||
Usage: "Duration for collection (seconds)",
|
||||
Value: 30 * time.Second,
|
||||
&cli.DurationFlag{
|
||||
Name: "seconds",
|
||||
Aliases: []string{"s"},
|
||||
Usage: "Duration for collection (seconds)",
|
||||
Value: 30 * time.Second,
|
||||
},
|
||||
cli.UintFlag{
|
||||
&cli.UintFlag{
|
||||
Name: "debug",
|
||||
Usage: "Debug pprof args",
|
||||
Value: 0,
|
||||
@@ -131,16 +133,17 @@ var pprofProfileCommand = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var pprofTraceCommand = cli.Command{
|
||||
var pprofTraceCommand = &cli.Command{
|
||||
Name: "trace",
|
||||
Usage: "Collect execution trace",
|
||||
Flags: []cli.Flag{
|
||||
cli.DurationFlag{
|
||||
Name: "seconds,s",
|
||||
Usage: "Trace time (seconds)",
|
||||
Value: 5 * time.Second,
|
||||
&cli.DurationFlag{
|
||||
Name: "seconds",
|
||||
Aliases: []string{"s"},
|
||||
Usage: "Trace time (seconds)",
|
||||
Value: 5 * time.Second,
|
||||
},
|
||||
cli.UintFlag{
|
||||
&cli.UintFlag{
|
||||
Name: "debug",
|
||||
Usage: "Debug pprof args",
|
||||
Value: 0,
|
||||
@@ -162,11 +165,11 @@ var pprofTraceCommand = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var pprofBlockCommand = cli.Command{
|
||||
var pprofBlockCommand = &cli.Command{
|
||||
Name: "block",
|
||||
Usage: "Goroutine blocking profile",
|
||||
Flags: []cli.Flag{
|
||||
cli.UintFlag{
|
||||
&cli.UintFlag{
|
||||
Name: "debug",
|
||||
Usage: "Debug pprof args",
|
||||
Value: 0,
|
||||
@@ -186,11 +189,11 @@ var pprofBlockCommand = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var pprofThreadcreateCommand = cli.Command{
|
||||
var pprofThreadcreateCommand = &cli.Command{
|
||||
Name: "threadcreate",
|
||||
Usage: "Goroutine thread creating profile",
|
||||
Flags: []cli.Flag{
|
||||
cli.UintFlag{
|
||||
&cli.UintFlag{
|
||||
Name: "debug",
|
||||
Usage: "Debug pprof args",
|
||||
Value: 0,
|
||||
@@ -211,7 +214,7 @@ var pprofThreadcreateCommand = cli.Command{
|
||||
}
|
||||
|
||||
func getPProfClient(context *cli.Context) *http.Client {
|
||||
dialer := getPProfDialer(context.GlobalString("debug-socket"))
|
||||
dialer := getPProfDialer(context.String("debug-socket"))
|
||||
|
||||
tr := &http.Transport{
|
||||
Dial: dialer.pprofDial,
|
||||
|
||||
Reference in New Issue
Block a user