Help us shape the future of Go! Take the 2026 Go Developer Survey

cmd

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package cmd contains common flags and routines for all CLIs.

Index

Constants

View Source
const (
	OutputPlaintext = "text"
	OutputJSON      = "json"
)

Variables

View Source
var (
	PflagKey = &pflag.Flag{
		Name:      "key",
		Shorthand: "k",
		Usage:     "signing key name, for a key previously added to notation's key list. This is mutually exclusive with the --id and --plugin flags",
	}
	SetPflagKey = func(fs *pflag.FlagSet, p *string) {
		fs.StringVarP(p, PflagKey.Name, PflagKey.Shorthand, "", PflagKey.Usage)
	}

	PflagSignatureFormat = &pflag.Flag{
		Name:  "signature-format",
		Usage: "signature envelope format, options: \"jws\", \"cose\"",
	}
	SetPflagSignatureFormat = func(fs *pflag.FlagSet, p *string) {
		config, err := configutil.LoadConfigOnce()
		if err != nil || config.SignatureFormat == "" {
			fs.StringVar(p, PflagSignatureFormat.Name, envelope.JWS, PflagSignatureFormat.Usage)
			return
		}

		fs.StringVar(p, PflagSignatureFormat.Name, config.SignatureFormat, PflagSignatureFormat.Usage)
	}

	PflagID = &pflag.Flag{
		Name:  "id",
		Usage: "key id (required if --plugin is set). This is mutually exclusive with the --key flag",
	}
	SetPflagID = func(fs *pflag.FlagSet, p *string) {
		fs.StringVar(p, PflagID.Name, "", PflagID.Usage)
	}

	PflagPlugin = &pflag.Flag{
		Name:  "plugin",
		Usage: "signing plugin name (required if --id is set). This is mutually exclusive with the --key flag",
	}
	SetPflagPlugin = func(fs *pflag.FlagSet, p *string) {
		fs.StringVar(p, PflagPlugin.Name, "", PflagPlugin.Usage)
	}

	PflagExpiry = &pflag.Flag{
		Name:      "expiry",
		Shorthand: "e",
		Usage:     "optional expiry that provides a \"best by use\" time for the artifact. The duration is specified in minutes(m) and/or hours(h). For example: 12h, 30m, 3h20m",
	}
	SetPflagExpiry = func(fs *pflag.FlagSet, p *time.Duration) {
		fs.DurationVarP(p, PflagExpiry.Name, PflagExpiry.Shorthand, time.Duration(0), PflagExpiry.Usage)
	}

	PflagReference = &pflag.Flag{
		Name:      "reference",
		Shorthand: "r",
		Usage:     "original reference",
	}
	SetPflagReference = func(fs *pflag.FlagSet, p *string) {
		fs.StringVarP(p, PflagReference.Name, PflagReference.Shorthand, "", PflagReference.Usage)
	}

	PflagPluginConfig = &pflag.Flag{
		Name:  "plugin-config",
		Usage: "{key}={value} pairs that are passed as it is to a plugin, refer plugin's documentation to set appropriate values",
	}
	SetPflagPluginConfig = func(fs *pflag.FlagSet, p *[]string) {
		fs.StringArrayVar(p, PflagPluginConfig.Name, nil, PflagPluginConfig.Usage)
	}

	PflagUserMetadata = &pflag.Flag{
		Name:      "user-metadata",
		Shorthand: "m",
	}
	PflagUserMetadataSignUsage   = "{key}={value} pairs that are added to the signature payload"
	PflagUserMetadataVerifyUsage = "user defined {key}={value} pairs that must be present in the signature for successful verification if provided"
	SetPflagUserMetadata         = func(fs *pflag.FlagSet, p *[]string, usage string) {
		fs.StringArrayVarP(p, PflagUserMetadata.Name, PflagUserMetadata.Shorthand, nil, usage)
	}

	PflagReferrersAPI = &pflag.Flag{
		Name: "allow-referrers-api",
	}
	PflagReferrersUsageFormat = "[Experimental] use the Referrers API to %s signatures, if not supported (returns 404), fallback to the Referrers tag schema"
	SetPflagReferrersAPI      = func(fs *pflag.FlagSet, p *bool, usage string) {
		fs.BoolVar(p, PflagReferrersAPI.Name, false, usage)
		fs.MarkHidden(PflagReferrersAPI.Name)
	}

	PflagReferrersTag = &pflag.Flag{
		Name: "force-referrers-tag",
	}
	SetPflagReferrersTag = func(fs *pflag.FlagSet, p *bool, usage string) {
		fs.BoolVar(p, PflagReferrersTag.Name, true, usage)
	}

	PflagOutput = &pflag.Flag{
		Name:      "output",
		Shorthand: "o",
	}
	PflagOutputUsage = fmt.Sprintf("output format, options: '%s', '%s'", OutputJSON, OutputPlaintext)
	SetPflagOutput   = func(fs *pflag.FlagSet, p *string, usage string) {
		fs.StringVarP(p, PflagOutput.Name, PflagOutput.Shorthand, OutputPlaintext, usage)
	}
)

Functions

func GetSigner

func GetSigner(ctx context.Context, opts *SignerFlagOpts) (notation.Signer, error)

GetSigner returns a signer according to the CLI context.

func ParseFlagMap

func ParseFlagMap(c []string, flagName string) (map[string]string, error)

Types

type KeyValueSlice

type KeyValueSlice interface {
	Set(value string) error
	String() string
}

KeyValueSlice is a flag with type int

type LoggingFlagOpts

type LoggingFlagOpts struct {
	Debug   bool
	Verbose bool
}

LoggingFlagOpts option struct.

func (*LoggingFlagOpts) ApplyFlags

func (opts *LoggingFlagOpts) ApplyFlags(fs *pflag.FlagSet)

ApplyFlags applies flags to a command flag set.

func (*LoggingFlagOpts) InitializeLogger

func (opts *LoggingFlagOpts) InitializeLogger(ctx context.Context) context.Context

InitializeLogger sets up the logger based on common options.

type SignerFlagOpts

type SignerFlagOpts struct {
	Key             string
	SignatureFormat string
	KeyID           string
	PluginName      string
}

SignerFlagOpts cmd opts for using cmd.GetSigner

func (*SignerFlagOpts) ApplyFlagsToCommand

func (opts *SignerFlagOpts) ApplyFlagsToCommand(command *cobra.Command)

ApplyFlags set flags and their default values for the FlagSet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL