shorthand

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package shorthand implements support for shorthand commands for the git-spice CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expand

func Expand(src Source, args []string) []string

Expand expands the given arguments using the given source repeatedly until there's nothing left to expand.

A single pattern is expanded only once. That is, if "commit" is declared as shorthand for "commit --amend", we will expand the "commit" shorthand only once.

Types

type BuiltinSource

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

BuiltinSource is a source of shorthand expansions built into a Kong CLI based on command aliases.

The shorthand for each command is built by joining the first alias at each level of the command hierarchy. For example, for:

branch (b) create (c)

The shorthand would be "bc".

func NewBuiltin

func NewBuiltin(app *kong.Application) (*BuiltinSource, error)

NewBuiltin builds a new BuiltinSource from the given Kong application. It extracts the shorthands from the command aliases.

func (*BuiltinSource) ExpandShorthand

func (s *BuiltinSource) ExpandShorthand(cmd string) ([]string, bool)

ExpandShorthand expands the given shorthand command.

func (*BuiltinSource) Keys

func (s *BuiltinSource) Keys() iter.Seq[string]

Keys returns the list of shorthand keys in the source.

func (*BuiltinSource) Node

func (s *BuiltinSource) Node(key string) *kong.Node

Node returns the command node for the given shorthand key or nil if it doesn't exist.

type Source

type Source interface {
	// ExpandShorthand expands the given shorthand command
	// into a list of arguments.
	//
	// If the command is not a shorthand, it returns false.
	ExpandShorthand(string) ([]string, bool)
}

Source is a source of shorthand expansions.

type Sources

type Sources []Source

Sources is a list of shorthand sources composed together. These are tried in order repeatedly until there's nothing left to expand.

func (Sources) ExpandShorthand

func (ss Sources) ExpandShorthand(orig string) ([]string, bool)

ExpandShorthand expands the given shorthand command.

Jump to

Keyboard shortcuts

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