command

package module
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 11 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Reusable Command Line Options

for spf13/cobra-based CLI tools

This package provides reusable command line options and configuration patterns for Carabiner CLI tools. It defines the OptionsSet interface for composable CLI flag management and provides common option sets that can be shared across multiple commands and applications.

Available OptionsSets

log - Logging Configuration

Package: github.com/carabiner-dev/command/log

Provides structured logging configuration with --log-level flag supporting debug, info, warn, and error levels. Includes WithLogger(ctx) method to initialize and inject logger into context.

Usage:

import "github.com/carabiner-dev/command/log"

logOpts := &log.Options{}

rootCmd := &cobra.Command{
    Use: "myapp",
    PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
        ctx, err := logOpts.WithLogger(cmd.Context())
        if err != nil {
            return err
        }
        cmd.SetContext(ctx)
        return nil
    },
}

logOpts.AddFlags(rootCmd)
keys - Public Key File Management

Package: github.com/carabiner-dev/command/keys

Provides public key file path configuration with --key/-k flag. Validates key file existence and parses keys into key.PublicKeyProvider instances.

Usage:

import "github.com/carabiner-dev/command/keys"

keyOpts := &keys.Options{}

verifyCmd := &cobra.Command{
    Use: "verify",
    RunE: func(cmd *cobra.Command, args []string) error {
        providers, err := keyOpts.ParseKeys()
        if err != nil {
            return err
        }
        // Use providers for verification...
        return nil
    },
}

keyOpts.AddFlags(verifyCmd)
output - Output File Management

Package: github.com/carabiner-dev/command/output

Provides output file path configuration with --output/-o flag. Returns an io.Writer that writes to the specified file or defaults to STDOUT.

Usage:

import "github.com/carabiner-dev/command/output"

outOpts := &output.Options{}

exportCmd := &cobra.Command{
    Use: "export",
    RunE: func(cmd *cobra.Command, args []string) error {
        writer, err := outOpts.GetWriter()
        if err != nil {
            return err
        }
        // Write output to file or STDOUT...
        fmt.Fprintln(writer, "data")
        return nil
    },
}

outOpts.AddFlags(exportCmd)
subject - Attestation Subjects

Package: github.com/carabiner-dev/command/subject

Provides the --subject/-s flag to read attestation subjects from the command line. Each value is either a digest in algorithm:value form or the path to a file, which gets hashed. Every algorithm name from the in-toto DigestSet spec is accepted (sha256, sha1, sha512, sha3_256, gitCommit, gitTree, gitBlob, gitTag, dirHash, ...), matched case-insensitively and normalized to the canonical spelling. Strings shaped like a digest are never looked up as files, so a malformed digest is reported instead of being mistaken for a path.

subject.ParseDigest can also be used on its own to parse a single algorithm:value string.

Usage:

import "github.com/carabiner-dev/command/subject"

subjectOpts := &subject.Options{}

attestCmd := &cobra.Command{
    Use: "attest",
    PreRunE: func(cmd *cobra.Command, args []string) error {
        return subjectOpts.Validate()
    },
    RunE: func(cmd *cobra.Command, args []string) error {
        descriptors, err := subjectOpts.ResourceDescriptors()
        if err != nil {
            return err
        }
        // Use the in-toto resource descriptors as subjects...
        return nil
    },
}

subjectOpts.AddFlags(attestCmd)

Contributing

This goal of this package is to to keep reusable sets of flags that have a high reuse incidence. We try to keep the dependency tree as small as possible. It is expected to mature slowly.

Feel free to file issues or suggestions if you find it useful.

This software is released under the Apache-2.0 license, paches are also welcome.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FlagConfig added in v0.2.0

type FlagConfig struct {
	Short string
	Long  string
	Help  string
}

FlagConfig holds the configuration of a flag

type KeyOptions deprecated

type KeyOptions struct {
	PublicKeyPaths []string
	// contains filtered or unexported fields
}

KeyOptions provides key file configuration for Carabiner applications.

Deprecated: Use github.com/carabiner-dev/command/keys.Options instead.

func (*KeyOptions) AddFlags deprecated

func (ko *KeyOptions) AddFlags(cmd *cobra.Command)

AddFlags adds the options flags to a command.

Deprecated: Use github.com/carabiner-dev/command/keys.Options instead.

func (*KeyOptions) Config deprecated added in v0.2.0

func (ko *KeyOptions) Config() *OptionsSetConfig

Config returns the flag configuration for key options.

Deprecated: Use github.com/carabiner-dev/command/keys.Options instead.

func (*KeyOptions) ParseKeys deprecated

func (ko *KeyOptions) ParseKeys() ([]key.PublicKeyProvider, error)

ParseKeys parses the key files and returns a slice of public key providers.

Deprecated: Use github.com/carabiner-dev/command/keys.Options instead.

func (*KeyOptions) Validate deprecated added in v0.1.1

func (ko *KeyOptions) Validate() error

Validate checks the options. Key files are verified to check if they exist.

Deprecated: Use github.com/carabiner-dev/command/keys.Options instead.

type OptionsSet

type OptionsSet interface {
	AddFlags(*cobra.Command)
	Validate() error
	Config() *OptionsSetConfig
}

OptionsSet is an interface that defines the functions options set need to implement to make them reusable.

type OptionsSetConfig added in v0.2.0

type OptionsSetConfig struct {
	FlagPrefix string
	Flags      map[string]FlagConfig
}

OptionsSetConfig configures a flag

func (*OptionsSetConfig) HelpText added in v0.2.0

func (c *OptionsSetConfig) HelpText(id string) string

func (*OptionsSetConfig) LongFlag added in v0.2.0

func (c *OptionsSetConfig) LongFlag(id string) string

func (*OptionsSetConfig) ShortFlag added in v0.2.0

func (c *OptionsSetConfig) ShortFlag(id string) string

type OutputFile deprecated added in v0.2.0

type OutputFile struct {
	OutputPath string
	// contains filtered or unexported fields
}

OutputFile provides output file configuration for Carabiner applications.

Deprecated: Use github.com/carabiner-dev/command/output.Options instead.

func (*OutputFile) AddFlags deprecated added in v0.2.0

func (oo *OutputFile) AddFlags(cmd *cobra.Command)

AddFlags adds the options flags to a command.

Deprecated: Use github.com/carabiner-dev/command/output.Options instead.

func (*OutputFile) Config deprecated added in v0.2.0

func (oo *OutputFile) Config() *OptionsSetConfig

Config returns the flag configuration for output options.

Deprecated: Use github.com/carabiner-dev/command/output.Options instead.

func (*OutputFile) GetWriter deprecated added in v0.2.0

func (oo *OutputFile) GetWriter() (io.Writer, error)

GetWriter returns a writer for the output.

Deprecated: Use github.com/carabiner-dev/command/output.Options instead.

func (*OutputFile) Validate deprecated added in v0.2.0

func (oo *OutputFile) Validate() error

Validate checks the output options.

Deprecated: Use github.com/carabiner-dev/command/output.Options instead.

Directories

Path Synopsis
Package subject provides a reusable options set to read attestation subjects from the command line.
Package subject provides a reusable options set to read attestation subjects from the command line.

Jump to

Keyboard shortcuts

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