cli

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cli holds what the command packages share.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompleteFirstVaultName added in v0.2.0

func CompleteFirstVaultName(c *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

CompleteFirstVaultName offers vault names for the first operand only, for a command whose later operands name no vault, as rename's target is a name that no vault has yet.

func CompleteVaultNames added in v0.2.0

func CompleteVaultNames(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective)

CompleteVaultNames offers the names of the vaults that exist, for an operand or a flag that names one. A shell asks for completions on every Tab, so a failure offers nothing rather than putting an error on the command line. Filenames are never offered alongside: a vault is named, not pathed.

func NeedsCommand

func NeedsCommand(c *cobra.Command, args []string) error

NeedsCommand refuses a command group invoked with no command, and an argument that names none. Both are wrong invocations: naming a command is how anything happens, and --help is how help is asked for. It validates arguments rather than running, so that the failure comes before usage is silenced and the reader is shown the commands they could have named.

func NoArgs

func NoArgs(c *cobra.Command, args []string) error

NoArgs refuses operands. cobra.NoArgs reports them as an unknown command, which misdescribes a command that takes no operands at all rather than one that was misspelled.

func Plural

func Plural(n int, word string) string

Plural returns word, pluralised for n.

func RequireArgs

func RequireArgs(minArgs, maxArgs int, want string) cobra.PositionalArgs

RequireArgs validates an operand count, naming the command and what it wanted. Cobra's own message ("accepts between 1 and 2 arg(s), received 0") names neither. A maxArgs below zero means there is no upper bound.

func Usage

func Usage(err error) error

Usage marks an existing error as a wrong invocation.

func Usagef

func Usagef(format string, a ...any) error

Usagef reports a wrong invocation, as an argument validator does.

Types

type UsageError

type UsageError struct {
	// contains filtered or unexported fields
}

UsageError marks a wrong invocation: an unknown command, an unknown flag, or an argument a command does not take. mrs exits 2 for these and 1 for a command that ran and failed, so that a script can tell them apart.

func (UsageError) Error

func (e UsageError) Error() string

func (UsageError) Unwrap

func (e UsageError) Unwrap() error

Jump to

Keyboard shortcuts

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