cli

package
v2.0.5-main.4 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 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.

Documentation

Index

Constants

View Source
const (
	GroupSessions  = "sessions"
	GroupModels    = "models"
	GroupAbilities = "abilities"
	GroupSafety    = "safety"
	GroupSecrets   = "secrets"
	GroupApp       = "app"
	GroupMore      = "more"
)

Groups the root's help lists its commands under, most used first. A command that names none is listed under More

View Source
const (
	Cyan   = "\033[36m"
	Green  = "\033[32m"
	Yellow = "\033[33m"
	Red    = "\033[31m"
	Dim    = "\033[2m"
	Bold   = "\033[1m"
	Gray   = "\033[90m"
	Reset  = "\033[0m"
)

Colors of a console's lines

Variables

This section is empty.

Functions

func Completing

func Completing(words []string) bool

Whether the words are a shell asking for completions as the user presses tab, which the completion scripts do

func Completion

func Completion(shell string) ([]byte, error)

Script that lets a shell complete icebath's commands, flags and arguments as the user presses tab, asking icebath for them, as the completion command prints it: for bash (through bash-completion), zsh, fish or powershell

func Helped

func Helped(words []string) bool

Whether the words ask for help: -h or --help before any --

func OwnServer

func OwnServer(ctx context.Context) bool

Whether the command runs against the server of its own process, so nothing it leaves in that server's memory outlives the command

func Pad

func Pad(text string, n int) string

Text padded with spaces to the width shown

func Painted

func Painted(text string, codes ...string) string

Text in the colors given, for a screen that always shows them

func Picked

func Picked(set map[int]bool) []int

Indexes of a selection in ascending order

func Width

func Width(text string) int

Width of a text as shown, its escape sequences left out

func WithOwnServer

func WithOwnServer(ctx context.Context) context.Context

Context of a command that runs against the server of its own process, which ends with the command, rather than one icebath connect set

Types

type CLI

type CLI struct {
	Registry
	// contains filtered or unexported fields
}

func New

func New() *CLI

func (*CLI) Launch

func (c *CLI) Launch(flags []launch.Flag, given launch.Given)

Has the root's help list the flags a launch of the app takes, and hands the command those given ahead of it, by their first spelling

func (*CLI) Run

func (c *CLI) Run(ctx context.Context, conn *connect.Client, args []string) error

func (*CLI) Serve

func (c *CLI) Serve(serve func(ctx context.Context) error)

Has icebath server run the server, and the root's help list it

type Console

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

Terminal of one command: lines in color when it is a terminal, answers read one line at a time, secrets without echo, at most one read outstanding

func NewConsole

func NewConsole(cmd *cobra.Command) *Console

func Terminal

func Terminal(ctx context.Context) *Console

Console of this process's own terminal, for a hook that runs around a command rather than in one

func (*Console) Agree

func (c *Console) Agree(prompt string, def bool) bool

Yes or no from one line after the prompt as given: y or yes is yes, an empty line, the end of the input or an interrupt the default

func (*Console) Answer

func (c *Console) Answer(prompt string) (string, bool)

Line typed after the prompt without its surrounding spaces, false at the end of the input or on an interrupt

func (*Console) Ask

func (c *Console) Ask(question string, def bool) bool

Confirm of a wizard: the question indented and in yellow, its hint followed by a colon

func (*Console) Attended

func (c *Console) Attended() bool

Whether a user answers at a terminal and reads the lines on one

func (*Console) Await

func (c *Console) Await(prompt string) <-chan Line

Line typed after the prompt, read while the caller waits on other things, joining a read already outstanding. Took is called once it came

func (*Console) Blank

func (c *Console) Blank()

func (*Console) Checklist

func (c *Console) Checklist(title string, items []string, selected map[int]bool) map[int]bool

Items checked and unchecked by their numbers until the list is accepted. The picked ones, the selection given when cancelled

func (*Console) Choose

func (c *Console) Choose(title string, items []string) (int, bool)

One of the items picked by its number, false when none was

func (*Console) Colored

func (c *Console) Colored() bool

Whether the lines go to a terminal that shows color, which redraws a line in place too

func (*Console) Confirm

func (c *Console) Confirm(question string, def bool) bool

Yes or no from one line after the question and its y/N hint, the default on an empty line, the end of the input or an interrupt

func (*Console) Context

func (c *Console) Context() context.Context

Context of the command the console is for

func (*Console) Fail

func (c *Console) Fail(text string) error

Says a failure in red and ends the command with status 1

func (*Console) Failure

func (c *Console) Failure(text string)

func (*Console) Index

func (c *Console) Index(prompt string, count int, empty bool, emptyLine string) (int, bool)

Number from 1 to count typed after the prompt, asked again until one is; 0 for an empty line when empty is allowed, false at the end of the input

func (*Console) Info

func (c *Console) Info(text string)

Lines of a wizard: a note, a step done, a warning and a failure, each indented and marked

func (*Console) Input

func (c *Console) Input(prompt string) (string, bool)

Line typed after the prompt, false at the end of the input or on an interrupt

func (*Console) Interactive

func (c *Console) Interactive() bool

Whether a user answers at a terminal

func (*Console) OnOff

func (c *Console) OnOff(on bool) string

On in green or Off dimmed, as a switch is shown

func (*Console) Out

func (c *Console) Out() io.Writer

Where the console's lines go

func (*Console) Paint

func (c *Console) Paint(text string, codes ...string) string

Text in the colors given when the console shows color

func (*Console) Pairs

func (c *Console) Pairs(title string, rows [][2]string)

Prints labels and values in two columns, the labels in bold, under a title in a frame

func (*Console) Panel

func (c *Console) Panel(title string, lines ...string)

Prints lines in a frame, the title on its top edge

func (*Console) Prompt

func (c *Console) Prompt(question, def string, secret bool) string

Answer of a wizard to the question, indented and in yellow with its default when it is no secret. The default when nothing is typed

func (*Console) Say

func (c *Console) Say(text string, codes ...string)

Prints a line in the colors given

func (*Console) Secret

func (c *Console) Secret(prompt string) (string, bool)

Line typed after the prompt without echo where the input is a terminal, false at the end of the input or on an interrupt

func (*Console) Step

func (c *Console) Step(n int, title string)

Prints a step of a wizard: its number and title in bold after a blank line

func (*Console) Success

func (c *Console) Success(text string)

func (*Console) Table

func (c *Console) Table(headers []string, rows [][]string)

Prints a table: the headers in bold over a rule, then each row, every column as wide as its widest cell

func (*Console) Tick

func (c *Console) Tick() string

Check mark in green

func (*Console) Took

func (c *Console) Took()

Marks the line Await delivered as taken, so the next read waits for a new one

func (*Console) Warning

func (c *Console) Warning(text string)

func (*Console) YesNo

func (c *Console) YesNo(on bool) string

Yes in green or No dimmed

type Exit

type Exit int

Failure of a command with the exit status it ends with, its lines already printed

func (Exit) Error

func (e Exit) Error() string

func (Exit) ExitCode

func (e Exit) ExitCode() int

type Line

type Line struct {
	Text string
	Err  error
}

Line read from the input, or why none came

type Registrant

type Registrant interface {
	Commands(conn *connect.Client) []*cobra.Command
}

type Registry

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

func (*Registry) Commands

func (r *Registry) Commands(conn *connect.Client) []*cobra.Command

func (*Registry) Register

func (r *Registry) Register(registrant Registrant)

Jump to

Keyboard shortcuts

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