From f54251cc630241818955cabb825418c435c6c801 Mon Sep 17 00:00:00 2001 From: "Zheao.Li" Date: Tue, 10 Jan 2023 18:11:57 +0800 Subject: [PATCH] [Refactor] Refactor all the GlobalCommandOptions from pointer to value reference Signed-off-by: Zheao.Li --- cmd/nerdctl/container_prune.go | 4 ++-- cmd/nerdctl/create.go | 2 +- cmd/nerdctl/flagutil.go | 28 ++++++++++++++-------------- cmd/nerdctl/image_convert.go | 8 ++++---- cmd/nerdctl/image_inspect.go | 2 +- cmd/nerdctl/images.go | 2 +- cmd/nerdctl/info.go | 4 ++-- cmd/nerdctl/load.go | 2 +- cmd/nerdctl/login.go | 2 +- cmd/nerdctl/network_prune.go | 2 +- cmd/nerdctl/pull.go | 4 ++-- cmd/nerdctl/rm.go | 2 +- cmd/nerdctl/run.go | 14 +++++++------- cmd/nerdctl/run_cgroup_linux.go | 2 +- cmd/nerdctl/run_freebsd.go | 2 +- cmd/nerdctl/run_linux.go | 2 +- cmd/nerdctl/run_mount.go | 2 +- cmd/nerdctl/run_network.go | 4 ++-- cmd/nerdctl/run_runtime.go | 2 +- cmd/nerdctl/run_windows.go | 2 +- cmd/nerdctl/stats.go | 2 +- cmd/nerdctl/system_prune.go | 2 +- cmd/nerdctl/update.go | 2 +- cmd/nerdctl/version.go | 2 +- cmd/nerdctl/volume.go | 2 +- cmd/nerdctl/volume_ls.go | 2 +- pkg/api/types/build_types.go | 2 +- pkg/api/types/volume_types.go | 10 +++++----- pkg/cmd/compose/compose.go | 2 +- 29 files changed, 59 insertions(+), 59 deletions(-) diff --git a/cmd/nerdctl/container_prune.go b/cmd/nerdctl/container_prune.go index e8e15f431e5..09d0bc7452e 100644 --- a/cmd/nerdctl/container_prune.go +++ b/cmd/nerdctl/container_prune.go @@ -70,10 +70,10 @@ func containerPruneAction(cmd *cobra.Command, _ []string) error { } defer cancel() - return containerPrune(ctx, cmd, globalOptions, client) + return containerPrune(ctx, cmd, client, globalOptions) } -func containerPrune(ctx context.Context, cmd *cobra.Command, globalOptions *types.GlobalCommandOptions, client *containerd.Client) error { +func containerPrune(ctx context.Context, cmd *cobra.Command, client *containerd.Client, globalOptions types.GlobalCommandOptions) error { containers, err := client.Containers(ctx) if err != nil { return err diff --git a/cmd/nerdctl/create.go b/cmd/nerdctl/create.go index ab2e7f00307..4c47c2dae98 100644 --- a/cmd/nerdctl/create.go +++ b/cmd/nerdctl/create.go @@ -73,7 +73,7 @@ func createAction(cmd *cobra.Command, args []string) error { return err } - container, gc, err := createContainer(ctx, cmd, globalOptions, client, args, platform, false, flagT, true) + container, gc, err := createContainer(ctx, cmd, client, globalOptions, args, platform, false, flagT, true) if err != nil { if gc != nil { gc() diff --git a/cmd/nerdctl/flagutil.go b/cmd/nerdctl/flagutil.go index 6e232cdfc8c..54a035201bc 100644 --- a/cmd/nerdctl/flagutil.go +++ b/cmd/nerdctl/flagutil.go @@ -21,56 +21,56 @@ import ( "github.com/spf13/cobra" ) -func processRootCmdFlags(cmd *cobra.Command) (*types.GlobalCommandOptions, error) { +func processRootCmdFlags(cmd *cobra.Command) (types.GlobalCommandOptions, error) { debug, err := cmd.Flags().GetBool("debug") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } debugFull, err := cmd.Flags().GetBool("debug-full") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } address, err := cmd.Flags().GetString("address") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } namespace, err := cmd.Flags().GetString("namespace") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } snapshotter, err := cmd.Flags().GetString("snapshotter") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } cniPath, err := cmd.Flags().GetString("cni-path") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } cniConfigPath, err := cmd.Flags().GetString("cni-netconfpath") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } dataRoot, err := cmd.Flags().GetString("data-root") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } cgroupManager, err := cmd.Flags().GetString("cgroup-manager") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } insecureRegistry, err := cmd.Flags().GetBool("insecure-registry") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } hostsDir, err := cmd.Flags().GetStringSlice("hosts-dir") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } experimental, err := cmd.Flags().GetBool("experimental") if err != nil { - return nil, err + return types.GlobalCommandOptions{}, err } - return &types.GlobalCommandOptions{ + return types.GlobalCommandOptions{ Debug: debug, DebugFull: debugFull, Address: address, diff --git a/cmd/nerdctl/image_convert.go b/cmd/nerdctl/image_convert.go index ccd45d5e911..a305eba2b6f 100644 --- a/cmd/nerdctl/image_convert.go +++ b/cmd/nerdctl/image_convert.go @@ -311,7 +311,7 @@ func imageConvertAction(cmd *cobra.Command, args []string) error { return printConvertedImage(cmd, res) } -func getESGZConverter(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions) (convertFunc converter.ConvertFunc, finalize func(ctx context.Context, cs content.Store, ref string, desc *ocispec.Descriptor) (*images.Image, error), _ error) { +func getESGZConverter(cmd *cobra.Command, globalOptions types.GlobalCommandOptions) (convertFunc converter.ConvertFunc, finalize func(ctx context.Context, cs content.Store, ref string, desc *ocispec.Descriptor) (*images.Image, error), _ error) { externalTOC, err := cmd.Flags().GetBool("estargz-external-toc") if err != nil { return nil, nil, err @@ -362,7 +362,7 @@ func getESGZConverter(cmd *cobra.Command, globalOptions *types.GlobalCommandOpti return convertFunc, finalize, nil } -func getESGZConvertOpts(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions) ([]estargz.Option, error) { +func getESGZConvertOpts(cmd *cobra.Command, globalOptions types.GlobalCommandOptions) ([]estargz.Option, error) { estargzCompressionLevel, err := cmd.Flags().GetInt("estargz-compression-level") if err != nil { return nil, err @@ -403,7 +403,7 @@ func getESGZConvertOpts(cmd *cobra.Command, globalOptions *types.GlobalCommandOp return esgzOpts, nil } -func getZstdchunkedConverter(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions) (converter.ConvertFunc, error) { +func getZstdchunkedConverter(cmd *cobra.Command, globalOptions types.GlobalCommandOptions) (converter.ConvertFunc, error) { zstdchunkedCompressionLevel, err := cmd.Flags().GetInt("zstdchunked-compression-level") if err != nil { return nil, err @@ -438,7 +438,7 @@ func getZstdchunkedConverter(cmd *cobra.Command, globalOptions *types.GlobalComm return zstdchunkedconvert.LayerConvertFuncWithCompressionLevel(zstd.EncoderLevelFromZstd(zstdchunkedCompressionLevel), esgzOpts...), nil } -func getNydusConvertOpts(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions) (*nydusconvert.PackOption, error) { +func getNydusConvertOpts(cmd *cobra.Command, globalOptions types.GlobalCommandOptions) (*nydusconvert.PackOption, error) { builderPath, err := cmd.Flags().GetString("nydus-builder-path") if err != nil { return nil, err diff --git a/cmd/nerdctl/image_inspect.go b/cmd/nerdctl/image_inspect.go index 908d3e548a5..384339216c7 100644 --- a/cmd/nerdctl/image_inspect.go +++ b/cmd/nerdctl/image_inspect.go @@ -73,7 +73,7 @@ func imageInspectAction(cmd *cobra.Command, args []string) error { return imageInspectActionWithPlatform(cmd, args, platform, globalOptions) } -func imageInspectActionWithPlatform(cmd *cobra.Command, args []string, platform string, globalOptions *types.GlobalCommandOptions) error { +func imageInspectActionWithPlatform(cmd *cobra.Command, args []string, platform string, globalOptions types.GlobalCommandOptions) error { var clientOpts []containerd.ClientOpt if platform != "" { diff --git a/cmd/nerdctl/images.go b/cmd/nerdctl/images.go index abca7e2bdbd..c6af23e2140 100644 --- a/cmd/nerdctl/images.go +++ b/cmd/nerdctl/images.go @@ -109,7 +109,7 @@ func processImagesFlag(cmd *cobra.Command, args []string) (types.ImageListComman return types.ImageListCommandOptions{}, err } return types.ImageListCommandOptions{ - GOptions: *globalOptions, + GOptions: globalOptions, Quiet: quiet, NoTrunc: noTrunc, Format: format, diff --git a/cmd/nerdctl/info.go b/cmd/nerdctl/info.go index 8a16aacffcf..b76f5d1f8af 100644 --- a/cmd/nerdctl/info.go +++ b/cmd/nerdctl/info.go @@ -134,7 +134,7 @@ func infoAction(cmd *cobra.Command, args []string) error { return nil } -func fulfillNativeInfo(cmd *cobra.Command, di *native.DaemonInfo, globalOptions *types.GlobalCommandOptions) (*native.Info, error) { +func fulfillNativeInfo(cmd *cobra.Command, di *native.DaemonInfo, globalOptions types.GlobalCommandOptions) (*native.Info, error) { info := &native.Info{ Daemon: di, } @@ -178,7 +178,7 @@ func prettyPrintInfoNative(w io.Writer, info *native.Info) error { return nil } -func prettyPrintInfoDockerCompat(cmd *cobra.Command, info *dockercompat.Info, globalOptions *types.GlobalCommandOptions) error { +func prettyPrintInfoDockerCompat(cmd *cobra.Command, info *dockercompat.Info, globalOptions types.GlobalCommandOptions) error { w := cmd.OutOrStdout() debug := globalOptions.Debug fmt.Fprintf(w, "Client:\n") diff --git a/cmd/nerdctl/load.go b/cmd/nerdctl/load.go index b2fb4753930..5ae637f5025 100644 --- a/cmd/nerdctl/load.go +++ b/cmd/nerdctl/load.go @@ -63,7 +63,7 @@ func processLoadCommandFlags(cmd *cobra.Command) (types.LoadCommandOptions, erro return types.LoadCommandOptions{}, err } return types.LoadCommandOptions{ - GOptions: *globalOptions, + GOptions: globalOptions, Input: input, Platform: platform, AllPlatforms: allPlatforms, diff --git a/cmd/nerdctl/login.go b/cmd/nerdctl/login.go index cc99ef4247a..254acd9748b 100644 --- a/cmd/nerdctl/login.go +++ b/cmd/nerdctl/login.go @@ -206,7 +206,7 @@ func GetDefaultAuthConfig(checkCredStore bool, serverAddress string, isDefaultRe return &res, nil } -func loginClientSide(ctx context.Context, cmd *cobra.Command, globalOptions *ncTypes.GlobalCommandOptions, auth types.AuthConfig) (string, error) { +func loginClientSide(ctx context.Context, cmd *cobra.Command, globalOptions ncTypes.GlobalCommandOptions, auth types.AuthConfig) (string, error) { host, err := convertToHostname(auth.ServerAddress) if err != nil { return "", err diff --git a/cmd/nerdctl/network_prune.go b/cmd/nerdctl/network_prune.go index e1190b51a3f..43d87865ad9 100644 --- a/cmd/nerdctl/network_prune.go +++ b/cmd/nerdctl/network_prune.go @@ -76,7 +76,7 @@ func networkPruneAction(cmd *cobra.Command, _ []string) error { return networkPrune(ctx, cmd, client, globalOptions) } -func networkPrune(ctx context.Context, cmd *cobra.Command, client *containerd.Client, globalOptions *types.GlobalCommandOptions) error { +func networkPrune(ctx context.Context, cmd *cobra.Command, client *containerd.Client, globalOptions types.GlobalCommandOptions) error { e, err := netutil.NewCNIEnv(globalOptions.CNIPath, globalOptions.CNINetConfPath) if err != nil { return err diff --git a/cmd/nerdctl/pull.go b/cmd/nerdctl/pull.go index 20301bdd112..6b28c760456 100644 --- a/cmd/nerdctl/pull.go +++ b/cmd/nerdctl/pull.go @@ -111,7 +111,7 @@ func pullAction(cmd *cobra.Command, args []string) error { return err } - _, err = ensureImage(ctx, cmd, globalOptions, client, rawRef, ocispecPlatforms, "always", unpack, quiet) + _, err = ensureImage(ctx, cmd, client, globalOptions, rawRef, ocispecPlatforms, "always", unpack, quiet) if err != nil { return err } @@ -119,7 +119,7 @@ func pullAction(cmd *cobra.Command, args []string) error { return nil } -func ensureImage(ctx context.Context, cmd *cobra.Command, globalOptions *types.GlobalCommandOptions, client *containerd.Client, rawRef string, ocispecPlatforms []v1.Platform, pull string, unpack *bool, quiet bool) (*imgutil.EnsuredImage, error) { +func ensureImage(ctx context.Context, cmd *cobra.Command, client *containerd.Client, globalOptions types.GlobalCommandOptions, rawRef string, ocispecPlatforms []v1.Platform, pull string, unpack *bool, quiet bool) (*imgutil.EnsuredImage, error) { var ensured *imgutil.EnsuredImage diff --git a/cmd/nerdctl/rm.go b/cmd/nerdctl/rm.go index b07677642c0..9d5d7cfe59d 100644 --- a/cmd/nerdctl/rm.go +++ b/cmd/nerdctl/rm.go @@ -106,7 +106,7 @@ func rmAction(cmd *cobra.Command, args []string) error { return nil } -func removeContainer(ctx context.Context, cmd *cobra.Command, globalOptions *types.GlobalCommandOptions, container containerd.Container, force bool, removeAnonVolumes bool) (retErr error) { +func removeContainer(ctx context.Context, cmd *cobra.Command, globalOptions types.GlobalCommandOptions, container containerd.Container, force bool, removeAnonVolumes bool) (retErr error) { ns, err := namespaces.NamespaceRequired(ctx) if err != nil { return err diff --git a/cmd/nerdctl/run.go b/cmd/nerdctl/run.go index d9305fa1657..e4fad7523ce 100644 --- a/cmd/nerdctl/run.go +++ b/cmd/nerdctl/run.go @@ -316,7 +316,7 @@ func runAction(cmd *cobra.Command, args []string) error { return errors.New("flags -d and --rm cannot be specified together") } - container, gc, err := createContainer(ctx, cmd, globalOptions, client, args, platform, flagI, flagT, flagD) + container, gc, err := createContainer(ctx, cmd, client, globalOptions, args, platform, flagI, flagT, flagD) if err != nil { if gc != nil { defer gc() @@ -397,7 +397,7 @@ func runAction(cmd *cobra.Command, args []string) error { } // FIXME: split to smaller functions -func createContainer(ctx context.Context, cmd *cobra.Command, globalOptions *types.GlobalCommandOptions, client *containerd.Client, args []string, platform string, flagI, flagT, flagD bool) (containerd.Container, func(), error) { +func createContainer(ctx context.Context, cmd *cobra.Command, client *containerd.Client, globalOptions types.GlobalCommandOptions, args []string, platform string, flagI, flagT, flagD bool) (containerd.Container, func(), error) { // simulate the behavior of double dash newArg := []string{} if len(args) >= 2 && args[1] == "--" { @@ -443,7 +443,7 @@ func createContainer(ctx context.Context, cmd *cobra.Command, globalOptions *typ oci.WithDefaultSpec(), ) - platformOpts, err := setPlatformOptions(ctx, cmd, globalOptions, client, id, &internalLabels) + platformOpts, err := setPlatformOptions(ctx, cmd, client, globalOptions, id, &internalLabels) if err != nil { return nil, nil, err } @@ -488,7 +488,7 @@ func createContainer(ctx context.Context, cmd *cobra.Command, globalOptions *typ opts = append(opts, oci.WithTTY) } - mountOpts, anonVolumes, mountPoints, err := generateMountOpts(ctx, cmd, globalOptions, client, ensuredImage) + mountOpts, anonVolumes, mountPoints, err := generateMountOpts(ctx, cmd, client, globalOptions, ensuredImage) if err != nil { return nil, nil, err } @@ -728,7 +728,7 @@ func createContainer(ctx context.Context, cmd *cobra.Command, globalOptions *typ return container, nil, nil } -func generateRootfsOpts(ctx context.Context, client *containerd.Client, platform string, cmd *cobra.Command, globalOptions *types.GlobalCommandOptions, args []string, id string) ([]oci.SpecOpts, []containerd.NewContainerOpts, *imgutil.EnsuredImage, error) { +func generateRootfsOpts(ctx context.Context, client *containerd.Client, platform string, cmd *cobra.Command, globalOptions types.GlobalCommandOptions, args []string, id string) ([]oci.SpecOpts, []containerd.NewContainerOpts, *imgutil.EnsuredImage, error) { var ( ensured *imgutil.EnsuredImage err error @@ -751,7 +751,7 @@ func generateRootfsOpts(ctx context.Context, client *containerd.Client, platform return nil, nil, nil, err } rawRef := args[0] - ensured, err = ensureImage(ctx, cmd, globalOptions, client, rawRef, ocispecPlatforms, pull, nil, false) + ensured, err = ensureImage(ctx, cmd, client, globalOptions, rawRef, ocispecPlatforms, pull, nil, false) if err != nil { return nil, nil, nil, err } @@ -948,7 +948,7 @@ func withNerdctlOCIHook(cmd *cobra.Command, id string) (oci.SpecOpts, error) { }, nil } -func getContainerStateDirPath(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions, dataStore, id string) (string, error) { +func getContainerStateDirPath(cmd *cobra.Command, globalOptions types.GlobalCommandOptions, dataStore, id string) (string, error) { if globalOptions.Namespace == "" { return "", errors.New("namespace is required") diff --git a/cmd/nerdctl/run_cgroup_linux.go b/cmd/nerdctl/run_cgroup_linux.go index 492ade2550a..c5430aeeb77 100644 --- a/cmd/nerdctl/run_cgroup_linux.go +++ b/cmd/nerdctl/run_cgroup_linux.go @@ -40,7 +40,7 @@ type customMemoryOptions struct { disableOOMKiller *bool } -func generateCgroupOpts(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions, id string) ([]oci.SpecOpts, error) { +func generateCgroupOpts(cmd *cobra.Command, globalOptions types.GlobalCommandOptions, id string) ([]oci.SpecOpts, error) { cpus, err := cmd.Flags().GetFloat64("cpus") if err != nil { return nil, err diff --git a/cmd/nerdctl/run_freebsd.go b/cmd/nerdctl/run_freebsd.go index 41471036ad9..8832661dee7 100644 --- a/cmd/nerdctl/run_freebsd.go +++ b/cmd/nerdctl/run_freebsd.go @@ -43,8 +43,8 @@ func runShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]s func setPlatformOptions( ctx context.Context, cmd *cobra.Command, - _ *types.GlobalCommandOptions, client *containerd.Client, + _ types.GlobalCommandOptions, id string, internalLabels *internalLabels, ) ([]oci.SpecOpts, error) { diff --git a/cmd/nerdctl/run_linux.go b/cmd/nerdctl/run_linux.go index 0cc2bd3b4e5..60d0148e2e7 100644 --- a/cmd/nerdctl/run_linux.go +++ b/cmd/nerdctl/run_linux.go @@ -58,7 +58,7 @@ func runShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]s return nil, cobra.ShellCompDirectiveNoFileComp } -func setPlatformOptions(ctx context.Context, cmd *cobra.Command, globalOptions *types.GlobalCommandOptions, client *containerd.Client, id string, internalLabels *internalLabels) ([]oci.SpecOpts, error) { +func setPlatformOptions(ctx context.Context, cmd *cobra.Command, client *containerd.Client, globalOptions types.GlobalCommandOptions, id string, internalLabels *internalLabels) ([]oci.SpecOpts, error) { var opts []oci.SpecOpts opts = append(opts, oci.WithDefaultUnixDevices, diff --git a/cmd/nerdctl/run_mount.go b/cmd/nerdctl/run_mount.go index 6c46c8937ea..e2c026e06cd 100644 --- a/cmd/nerdctl/run_mount.go +++ b/cmd/nerdctl/run_mount.go @@ -121,7 +121,7 @@ func parseMountFlags(cmd *cobra.Command, volStore volumestore.VolumeStore) ([]*m // generateMountOpts generates volume-related mount opts. // Other mounts such as procfs mount are not handled here. -func generateMountOpts(ctx context.Context, cmd *cobra.Command, globalOptions *types.GlobalCommandOptions, client *containerd.Client, ensuredImage *imgutil.EnsuredImage) ([]oci.SpecOpts, []string, []*mountutil.Processed, error) { +func generateMountOpts(ctx context.Context, cmd *cobra.Command, client *containerd.Client, globalOptions types.GlobalCommandOptions, ensuredImage *imgutil.EnsuredImage) ([]oci.SpecOpts, []string, []*mountutil.Processed, error) { volStore, err := getVolumeStore(globalOptions) if err != nil { return nil, nil, nil, err diff --git a/cmd/nerdctl/run_network.go b/cmd/nerdctl/run_network.go index d2f6bba7bb7..d1dfaf32a63 100644 --- a/cmd/nerdctl/run_network.go +++ b/cmd/nerdctl/run_network.go @@ -113,7 +113,7 @@ func withCustomHosts(src string) func(context.Context, oci.Client, *containers.C } } -func generateNetOpts(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions, dataStore, stateDir, ns, id string) ([]oci.SpecOpts, []string, string, []gocni.PortMapping, string, error) { +func generateNetOpts(cmd *cobra.Command, globalOptions types.GlobalCommandOptions, dataStore, stateDir, ns, id string) ([]oci.SpecOpts, []string, string, []gocni.PortMapping, string, error) { opts := []oci.SpecOpts{} portSlice, err := cmd.Flags().GetStringSlice("publish") if err != nil { @@ -266,7 +266,7 @@ func getContainerNetNSPath(ctx context.Context, c containerd.Container) (string, return fmt.Sprintf("/proc/%d/ns/net", task.Pid()), nil } -func verifyCNINetwork(cmd *cobra.Command, netSlice []string, macAddress string, globalOptions *types.GlobalCommandOptions) error { +func verifyCNINetwork(cmd *cobra.Command, netSlice []string, macAddress string, globalOptions types.GlobalCommandOptions) error { e, err := netutil.NewCNIEnv(globalOptions.CNIPath, globalOptions.CNINetConfPath, netutil.WithDefaultNetwork()) if err != nil { return err diff --git a/cmd/nerdctl/run_runtime.go b/cmd/nerdctl/run_runtime.go index ab5ff66872c..4ed9b92d1a9 100644 --- a/cmd/nerdctl/run_runtime.go +++ b/cmd/nerdctl/run_runtime.go @@ -31,7 +31,7 @@ import ( "github.com/spf13/cobra" ) -func generateRuntimeCOpts(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions) ([]containerd.NewContainerOpts, error) { +func generateRuntimeCOpts(cmd *cobra.Command, globalOptions types.GlobalCommandOptions) ([]containerd.NewContainerOpts, error) { runtime := plugin.RuntimeRuncV2 var ( runcOpts runcoptions.Options diff --git a/cmd/nerdctl/run_windows.go b/cmd/nerdctl/run_windows.go index e6cffe0a9cc..ec8f69513f6 100644 --- a/cmd/nerdctl/run_windows.go +++ b/cmd/nerdctl/run_windows.go @@ -45,8 +45,8 @@ func runShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]s func setPlatformOptions( ctx context.Context, cmd *cobra.Command, - _ *types.GlobalCommandOptions, client *containerd.Client, + _ types.GlobalCommandOptions, id string, internalLabels *internalLabels, ) ([]oci.SpecOpts, error) { diff --git a/cmd/nerdctl/stats.go b/cmd/nerdctl/stats.go index e1f6136d268..40eebc571f8 100644 --- a/cmd/nerdctl/stats.go +++ b/cmd/nerdctl/stats.go @@ -379,7 +379,7 @@ func statsAction(cmd *cobra.Command, args []string) error { return err } -func collect(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions, s *statsutil.Stats, waitFirst *sync.WaitGroup, id string, noStream bool) { +func collect(cmd *cobra.Command, globalOptions types.GlobalCommandOptions, s *statsutil.Stats, waitFirst *sync.WaitGroup, id string, noStream bool) { logrus.Debugf("collecting stats for %s", s.Container) var ( getFirst = true diff --git a/cmd/nerdctl/system_prune.go b/cmd/nerdctl/system_prune.go index 13e158f3016..762630c5588 100644 --- a/cmd/nerdctl/system_prune.go +++ b/cmd/nerdctl/system_prune.go @@ -97,7 +97,7 @@ func systemPruneAction(cmd *cobra.Command, args []string) error { } defer cancel() - if err := containerPrune(ctx, cmd, globalOptions, client); err != nil { + if err := containerPrune(ctx, cmd, client, globalOptions); err != nil { return err } if err := networkPrune(ctx, cmd, client, globalOptions); err != nil { diff --git a/cmd/nerdctl/update.go b/cmd/nerdctl/update.go index 6a4d7158d4e..3efce9cd72a 100644 --- a/cmd/nerdctl/update.go +++ b/cmd/nerdctl/update.go @@ -121,7 +121,7 @@ func updateAction(cmd *cobra.Command, args []string) error { return nil } -func getUpdateOption(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions) (updateResourceOptions, error) { +func getUpdateOption(cmd *cobra.Command, globalOptions types.GlobalCommandOptions) (updateResourceOptions, error) { var options updateResourceOptions cpus, err := cmd.Flags().GetFloat64("cpus") if err != nil { diff --git a/cmd/nerdctl/version.go b/cmd/nerdctl/version.go index d557a94905a..d74444a2e4b 100644 --- a/cmd/nerdctl/version.go +++ b/cmd/nerdctl/version.go @@ -103,7 +103,7 @@ func versionAction(cmd *cobra.Command, args []string) error { } // versionInfo may return partial VersionInfo on error -func versionInfo(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions) (dockercompat.VersionInfo, error) { +func versionInfo(cmd *cobra.Command, globalOptions types.GlobalCommandOptions) (dockercompat.VersionInfo, error) { v := dockercompat.VersionInfo{ Client: infoutil.ClientVersion(), diff --git a/cmd/nerdctl/volume.go b/cmd/nerdctl/volume.go index ec4bd0fbe51..efbccf6d402 100644 --- a/cmd/nerdctl/volume.go +++ b/cmd/nerdctl/volume.go @@ -44,6 +44,6 @@ func newVolumeCommand() *cobra.Command { // getVolumeStore returns a volume store // that corresponds to a directory like `/var/lib/nerdctl/1935db59/volumes/default` -func getVolumeStore(globalOptions *types.GlobalCommandOptions) (volumestore.VolumeStore, error) { +func getVolumeStore(globalOptions types.GlobalCommandOptions) (volumestore.VolumeStore, error) { return volume.Store(globalOptions.Namespace, globalOptions.DataRoot, globalOptions.Address) } diff --git a/cmd/nerdctl/volume_ls.go b/cmd/nerdctl/volume_ls.go index 44550ec6933..34516f8a07a 100644 --- a/cmd/nerdctl/volume_ls.go +++ b/cmd/nerdctl/volume_ls.go @@ -75,7 +75,7 @@ func volumeLsAction(cmd *cobra.Command, args []string) error { }, cmd.OutOrStdout()) } -func getVolumes(cmd *cobra.Command, globalOptions *types.GlobalCommandOptions) (map[string]native.Volume, error) { +func getVolumes(cmd *cobra.Command, globalOptions types.GlobalCommandOptions) (map[string]native.Volume, error) { volumeSize, err := cmd.Flags().GetBool("size") if err != nil { return nil, err diff --git a/pkg/api/types/build_types.go b/pkg/api/types/build_types.go index 7784f2527f2..739d97e2b1b 100644 --- a/pkg/api/types/build_types.go +++ b/pkg/api/types/build_types.go @@ -18,7 +18,7 @@ package types type BuildCommandOptions struct { // GOptions is the global options - GOptions *GlobalCommandOptions + GOptions GlobalCommandOptions // BuildKitHost is the buildkit host BuildKitHost string // Tag is the tag of the image diff --git a/pkg/api/types/volume_types.go b/pkg/api/types/volume_types.go index ba26af5a586..9b02018f2b3 100644 --- a/pkg/api/types/volume_types.go +++ b/pkg/api/types/volume_types.go @@ -17,7 +17,7 @@ package types type VolumeCreateCommandOptions struct { - GOptions *GlobalCommandOptions + GOptions GlobalCommandOptions // Name is the volume name Name string // Labels are the volume labels @@ -25,7 +25,7 @@ type VolumeCreateCommandOptions struct { } type VolumeInspectCommandOptions struct { - GOptions *GlobalCommandOptions + GOptions GlobalCommandOptions // Format the output using the given go template Format string // Display the disk usage of volumes. Can be slow with volumes having loads of directories. @@ -35,7 +35,7 @@ type VolumeInspectCommandOptions struct { } type VolumeLsCommandOptions struct { - GOptions *GlobalCommandOptions + GOptions GlobalCommandOptions // Only display volume names Quiet bool // Format the output using the given go template @@ -47,13 +47,13 @@ type VolumeLsCommandOptions struct { } type VolumePruneCommandOptions struct { - GOptions *GlobalCommandOptions + GOptions GlobalCommandOptions // Do not prompt for confirmation Force bool } type VolumeRmCommandOptions struct { - GOptions *GlobalCommandOptions + GOptions GlobalCommandOptions // Volumes are the volumes to be removed Volumes []string } diff --git a/pkg/cmd/compose/compose.go b/pkg/cmd/compose/compose.go index 7f97c0c4159..1f42250a34d 100644 --- a/pkg/cmd/compose/compose.go +++ b/pkg/cmd/compose/compose.go @@ -40,7 +40,7 @@ import ( "github.com/sirupsen/logrus" ) -func New(client *containerd.Client, globalOptions *types.GlobalCommandOptions, options composer.Options, stdout, stderr io.Writer) (*composer.Composer, error) { +func New(client *containerd.Client, globalOptions types.GlobalCommandOptions, options composer.Options, stdout, stderr io.Writer) (*composer.Composer, error) { cniEnv, err := netutil.NewCNIEnv(globalOptions.CNIPath, globalOptions.CNINetConfPath, netutil.WithDefaultNetwork()) if err != nil { return nil, err