cmd: don't alias context package, and use cliContext for cli.Context
Unfortunately, this is a rather large diff, but perhaps worth a one-time "rip off the bandaid" for v2. This patch removes the use of "gocontext" as alias for stdLib's "context", and uses "cliContext" for uses of cli.context. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"context"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
@@ -33,18 +33,18 @@ import (
|
||||
//
|
||||
// This will ensure the namespace is picked up and set the timeout, if one is
|
||||
// defined.
|
||||
func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc) {
|
||||
func AppContext(cliContext *cli.Context) (context.Context, context.CancelFunc) {
|
||||
var (
|
||||
ctx = gocontext.Background()
|
||||
timeout = context.Duration("timeout")
|
||||
namespace = context.String("namespace")
|
||||
cancel gocontext.CancelFunc
|
||||
ctx = context.Background()
|
||||
timeout = cliContext.Duration("timeout")
|
||||
namespace = cliContext.String("namespace")
|
||||
cancel context.CancelFunc
|
||||
)
|
||||
ctx = namespaces.WithNamespace(ctx, namespace)
|
||||
if timeout > 0 {
|
||||
ctx, cancel = gocontext.WithTimeout(ctx, timeout)
|
||||
ctx, cancel = context.WithTimeout(ctx, timeout)
|
||||
} else {
|
||||
ctx, cancel = gocontext.WithCancel(ctx)
|
||||
ctx, cancel = context.WithCancel(ctx)
|
||||
}
|
||||
if tm, err := epoch.SourceDateEpoch(); err != nil {
|
||||
log.L.WithError(err).Warn("Failed to read SOURCE_DATE_EPOCH")
|
||||
@@ -56,14 +56,14 @@ func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc)
|
||||
}
|
||||
|
||||
// NewClient returns a new containerd client
|
||||
func NewClient(context *cli.Context, opts ...containerd.Opt) (*containerd.Client, gocontext.Context, gocontext.CancelFunc, error) {
|
||||
timeoutOpt := containerd.WithTimeout(context.Duration("connect-timeout"))
|
||||
func NewClient(cliContext *cli.Context, opts ...containerd.Opt) (*containerd.Client, context.Context, context.CancelFunc, error) {
|
||||
timeoutOpt := containerd.WithTimeout(cliContext.Duration("connect-timeout"))
|
||||
opts = append(opts, timeoutOpt)
|
||||
client, err := containerd.New(context.String("address"), opts...)
|
||||
client, err := containerd.New(cliContext.String("address"), opts...)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
ctx, cancel := AppContext(context)
|
||||
ctx, cancel := AppContext(cliContext)
|
||||
var suppressDeprecationWarnings bool
|
||||
if s := os.Getenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS"); s != "" {
|
||||
suppressDeprecationWarnings, err = strconv.ParseBool(s)
|
||||
|
Reference in New Issue
Block a user