cli

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cli provides utilities to work with the command-line interface.

Index

Constants

View Source
const (
	// UserAgent is the user agent string used by frizbee.
	//
	// TODO (jaosorior): Add version information to this.
	UserAgent = "frizbee"
	// GitHubTokenEnvKey is the environment variable key for the GitHub token
	//nolint:gosec // This is not a hardcoded credential
	GitHubTokenEnvKey = "GITHUB_TOKEN"

	// TokenHelpText is the help text for the GitHub token
	TokenHelpText = "NOTE: It's recommended to set the " + GitHubTokenEnvKey +
		" environment variable given that GitHub has tighter rate limits on anonymous calls."
)

Variables

View Source
var (
	// CLIVersion is the version of the frizbee CLI.
	// nolint: gochecknoglobals
	CLIVersion = "dev"
	// VerboseCLIVersion is the verbose version of the frizbee CLI.
	// nolint: gochecknoglobals
	VerboseCLIVersion = ""
)

Functions

func DeclareFrizbeeFlags

func DeclareFrizbeeFlags(cmd *cobra.Command, enableOutput bool)

DeclareFrizbeeFlags declares the flags common to all replacer commands.

func IsPath

func IsPath(pathOrRef string) bool

IsPath returns true if the given path is a file or directory.

Types

type Helper

type Helper struct {
	DryRun        bool
	Quiet         bool
	ErrOnModified bool
	Regex         string
	Cmd           *cobra.Command
}

Helper is a common struct for implementing a CLI command that replaces files.

func NewHelper

func NewHelper(cmd *cobra.Command) (*Helper, error)

NewHelper creates a new CLI Helper struct.

func (*Helper) CheckModified added in v0.1.7

func (r *Helper) CheckModified(modified map[string]string) error

CheckModified checks if any files were modified and returns an error if there were.

func (*Helper) Logf

func (r *Helper) Logf(format string, args ...interface{})

Logf logs the given message to the given command's stderr if the command is not quiet.

func (*Helper) ProcessOutput

func (r *Helper) ProcessOutput(path string, processed []string, modified map[string]string) error

ProcessOutput processes the given output files. If the command is quiet, the output is discarded. If the command is a dry run, the output is written to the command's stdout. Otherwise, the output is written to the given filesystem.

Jump to

Keyboard shortcuts

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