cli

package
v1.18.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MPL-2.0 Imports: 28 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

Overview

Package cli builds the gyro command tree: generated commands for every API operation (generated.go, from internal/spec) plus hand-written commands with nicer UX (server.go, ...).

Index

Constants

View Source
const (
	ExitOK        = 0
	ExitError     = 1
	ExitUsage     = 2
	ExitAuth      = 3 // 401/403
	ExitNotFound  = 4
	ExitConflict  = 5 // 409
	ExitPayment   = 6 // 402
	ExitAborted   = 7 // user said no / confirmation missing
	ExitRateLimit = 8
	ExitTimeout   = 9 // --wait timed out
)

Exit codes (documented in README).

Variables

View Source
var (
	Version = "dev"
	Commit  = "none"
	Date    = "unknown"
)

Build information (set with -ldflags by GoReleaser).

View Source
var UpdateURL = "https://api.github.com/repos/Gyro-Hosting/gyro-cli/releases/latest"

UpdateURL is the GitHub "latest release" API endpoint (GYRO_UPDATE_URL overrides; "off" disables).

Functions

func Execute

func Execute(a *App, args []string) int

Execute runs the CLI and returns the process exit code.

func NewRoot

func NewRoot(a *App) *cobra.Command

NewRoot builds the whole command tree.

func ParseKV

func ParseKV(pairs []string) (map[string]any, error)

ParseKV parses k=v pairs (values that look like JSON are decoded: numbers, true/false, [..], {..}).

func PlanSlug

func PlanSlug(name string) string

PlanSlug is the short plan name shown to users: "Gyro Bulut Pro 2-8" -> "pro-2-8".

func Run

func Run(args []string) int

Run is the process entry point: language pre-scan, build, execute.

func Slug

func Slug(s string) string

Slug folds Turkish letters and punctuation: "Gyro Bulut Pro 2-8" -> "gyro-bulut-pro-2-8".

Types

type App

type App struct {
	Opt   Options
	In    io.Reader
	Out   io.Writer
	Err   io.Writer
	Env   func(string) string
	IsTTY func() bool // stdin is an interactive terminal (prompts allowed)

	// NewClient can be replaced in tests.
	NewClient func(baseURL, token string) *api.Client
	// Sleep for --wait polling (tests set it to a no-op).
	Sleep func(time.Duration)
	// Exec runs external programs (ssh); tests replace it.
	Exec func(name string, args []string) error
	// contains filtered or unexported fields
}

App is shared by all commands.

func NewApp

func NewApp() *App

NewApp returns an App wired to the real process.

func (*App) APIURL

func (a *App) APIURL() string

APIURL resolves the base URL: flag > GYRO_API_URL > profile > default.

func (*App) Client

func (a *App) Client() (*api.Client, error)

Client returns an authenticated API client.

func (*App) Config

func (a *App) Config() (*config.File, error)

Config loads the config file once.

func (*App) Confirm

func (a *App) Confirm(question string) error

Confirm asks a yes/no question. --yes skips it; without a terminal it fails (exit 7) so scripts never spend money silently.

func (*App) ConfirmTyped

func (a *App) ConfirmTyped(question, word string) error

ConfirmTyped makes the user type a word (e.g. the server name) before deleting.

func (*App) Ctx

func (a *App) Ctx() (context.Context, context.CancelFunc)

Ctx returns a context cancelled on Ctrl-C and after --timeout.

func (*App) Info

func (a *App) Info(format string, args ...any)

Info prints a human message to stderr (suppressed in quiet mode).

func (*App) Machine

func (a *App) Machine() bool

Machine reports json/yaml output (progress and hints then go to stderr only).

func (*App) NewSpinner

func (a *App) NewSpinner(label string) *Spinner

func (*App) PrintList

func (a *App) PrintList(items []json.RawMessage, cols []output.Column, idPath string) error

PrintList prints raw list items.

func (*App) PrintRaw

func (a *App) PrintRaw(raw json.RawMessage, cols []output.Column, idPath string) error

PrintRaw decodes and prints a data block.

func (*App) Printer

func (a *App) Printer() *output.Printer

Printer returns the output printer for the current flags.

func (*App) Profile

func (a *App) Profile() *config.Profile

Profile returns the active profile (may be empty).

func (*App) ProfileName

func (a *App) ProfileName() string

ProfileName is the active profile.

func (*App) Prompt

func (a *App) Prompt(r *bufio.Reader, label, def string) string

Prompt reads one line with a default.

func (*App) ReadData

func (a *App) ReadData(s string) (map[string]any, error)

ReadData loads --data: inline JSON, @file or @- (stdin).

func (*App) ReadValue

func (a *App) ReadValue(s string) (string, error)

ReadValue loads @file / @- values for string flags (user data, public keys).

func (*App) Token

func (a *App) Token() (token, source string, err error)

Token resolves the API key: GYRO_TOKEN > profile (file or keychain).

func (*App) WaitFor

func (a *App) WaitFor(ctx context.Context, label string, timeout time.Duration, check func() (bool, string, error)) error

WaitFor polls check() until it reports done, with a timeout. check returns (done, status text, error).

type ExitErr

type ExitErr struct {
	Code int
	Err  error
}

ExitErr carries an exit code.

func (*ExitErr) Error

func (e *ExitErr) Error() string

func (*ExitErr) Unwrap

func (e *ExitErr) Unwrap() error

type Options

type Options struct {
	Profile  string
	APIURL   string
	Output   string
	Query    string
	NoHeader bool
	Quiet    bool
	NoColor  bool
	Lang     string
	Yes      bool
	Debug    bool
	Wide     bool
	Timeout  time.Duration
}

Options are the global flags.

type Spinner

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

Spinner shows progress on stderr when it is a terminal.

func (*Spinner) Done

func (s *Spinner) Done(msg string)

func (*Spinner) Tick

func (s *Spinner) Tick(status string)

Jump to

Keyboard shortcuts

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