github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/flagutil.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "github.com/containerd/nerdctl/pkg/api/types" 21 "github.com/spf13/cobra" 22 ) 23 24 func processImageSignOptions(cmd *cobra.Command) (opt types.ImageSignOptions, err error) { 25 if opt.Provider, err = cmd.Flags().GetString("sign"); err != nil { 26 return 27 } 28 if opt.CosignKey, err = cmd.Flags().GetString("cosign-key"); err != nil { 29 return 30 } 31 if opt.NotationKeyName, err = cmd.Flags().GetString("notation-key-name"); err != nil { 32 return 33 } 34 return 35 } 36 37 func processImageVerifyOptions(cmd *cobra.Command) (opt types.ImageVerifyOptions, err error) { 38 if opt.Provider, err = cmd.Flags().GetString("verify"); err != nil { 39 return 40 } 41 if opt.CosignKey, err = cmd.Flags().GetString("cosign-key"); err != nil { 42 return 43 } 44 if opt.CosignCertificateIdentity, err = cmd.Flags().GetString("cosign-certificate-identity"); err != nil { 45 return 46 } 47 if opt.CosignCertificateIdentityRegexp, err = cmd.Flags().GetString("cosign-certificate-identity-regexp"); err != nil { 48 return 49 } 50 if opt.CosignCertificateOidcIssuer, err = cmd.Flags().GetString("cosign-certificate-oidc-issuer"); err != nil { 51 return 52 } 53 if opt.CosignCertificateOidcIssuerRegexp, err = cmd.Flags().GetString("cosign-certificate-oidc-issuer-regexp"); err != nil { 54 return 55 } 56 return 57 } 58 59 func processSociOptions(cmd *cobra.Command) (opt types.SociOptions, err error) { 60 if opt.SpanSize, err = cmd.Flags().GetInt64("soci-span-size"); err != nil { 61 return 62 } 63 if opt.MinLayerSize, err = cmd.Flags().GetInt64("soci-min-layer-size"); err != nil { 64 return 65 } 66 return 67 } 68 69 func processRootCmdFlags(cmd *cobra.Command) (types.GlobalCommandOptions, error) { 70 debug, err := cmd.Flags().GetBool("debug") 71 if err != nil { 72 return types.GlobalCommandOptions{}, err 73 } 74 debugFull, err := cmd.Flags().GetBool("debug-full") 75 if err != nil { 76 return types.GlobalCommandOptions{}, err 77 } 78 address, err := cmd.Flags().GetString("address") 79 if err != nil { 80 return types.GlobalCommandOptions{}, err 81 } 82 namespace, err := cmd.Flags().GetString("namespace") 83 if err != nil { 84 return types.GlobalCommandOptions{}, err 85 } 86 snapshotter, err := cmd.Flags().GetString("snapshotter") 87 if err != nil { 88 return types.GlobalCommandOptions{}, err 89 } 90 cniPath, err := cmd.Flags().GetString("cni-path") 91 if err != nil { 92 return types.GlobalCommandOptions{}, err 93 } 94 cniConfigPath, err := cmd.Flags().GetString("cni-netconfpath") 95 if err != nil { 96 return types.GlobalCommandOptions{}, err 97 } 98 dataRoot, err := cmd.Flags().GetString("data-root") 99 if err != nil { 100 return types.GlobalCommandOptions{}, err 101 } 102 cgroupManager, err := cmd.Flags().GetString("cgroup-manager") 103 if err != nil { 104 return types.GlobalCommandOptions{}, err 105 } 106 insecureRegistry, err := cmd.Flags().GetBool("insecure-registry") 107 if err != nil { 108 return types.GlobalCommandOptions{}, err 109 } 110 hostsDir, err := cmd.Flags().GetStringSlice("hosts-dir") 111 if err != nil { 112 return types.GlobalCommandOptions{}, err 113 } 114 experimental, err := cmd.Flags().GetBool("experimental") 115 if err != nil { 116 return types.GlobalCommandOptions{}, err 117 } 118 hostGatewayIP, err := cmd.Flags().GetString("host-gateway-ip") 119 if err != nil { 120 return types.GlobalCommandOptions{}, err 121 } 122 return types.GlobalCommandOptions{ 123 Debug: debug, 124 DebugFull: debugFull, 125 Address: address, 126 Namespace: namespace, 127 Snapshotter: snapshotter, 128 CNIPath: cniPath, 129 CNINetConfPath: cniConfigPath, 130 DataRoot: dataRoot, 131 CgroupManager: cgroupManager, 132 InsecureRegistry: insecureRegistry, 133 HostsDir: hostsDir, 134 Experimental: experimental, 135 HostGatewayIP: hostGatewayIP, 136 }, nil 137 }