cmd

package
v0.0.0-...-9d267ab Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: BSD-3-Clause Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const ExitCancelled = 130

ExitCancelled is the status a cancelled prompt exits with: 128 + SIGINT, which is what a shell reports for a program the user interrupted.

Distinct from 1 on purpose. Answering "no" to a prompt, or walking away from one, is not the same outcome as a command that failed, and a script driving the CLI should be able to tell them apart.

Variables

View Source
var ErrConsoleNeedsSession = errors.New(
	"session not found. Run `" + app.ExecutableName + " login`. API keys work for project commands " +
		"(e.g. `" + app.ExecutableName + " push functions`), not console-only commands " +
		"(e.g. `" + app.ExecutableName + " push settings`)")

ErrConsoleNeedsSession is returned when only an API key is stored and the command needs the console. Ports the two-sentence message in sdkForConsole().

View Source
var ErrNotLoggedIn = errors.New("no active session. Run `" + app.ExecutableName + " login` to sign in")

ErrNotLoggedIn is returned when a command needs a session and none is stored.

Functions

func CancellationNotice

func CancellationNotice(command *cobra.Command) string

CancellationNotice is the line printed for a cancelled prompt.

Names the command, because a prompt can be several screens into a flow -- `push` asks three questions -- so "Cancelled." alone leaves the user to work out what they just abandoned. The command's PATH, not the arguments: those can carry an API key, and this line may end up in a log.

func ErrorDetail

func ErrorDetail(err error) string

ErrorDetail is everything known about a failure, for --verbose.

A Go error carries no stack, so the unwrap chain stands in for one. The response body is the reason this exists: it is the only thing that says whether the API changed shape or the CLI has the model wrong.

func Execute

func Execute(root *cobra.Command) (*cobra.Command, error)

Execute runs the root command and checks early exits skipped by PersistentPreRun.

func FormatError

func FormatError(err error) string

FormatError renders a command failure for the terminal.

func IsCancelled

func IsCancelled(err error) bool

IsCancelled reports whether a command stopped because the user cancelled a prompt rather than because anything went wrong.

func NewRootCommand

func NewRootCommand() *cobra.Command

NewRootCommand builds the full command tree.

Registration is deliberately eager: the complete tree measures at 5.0ms, so lazy construction would add complexity to generated code for no measurable gain.

func RenderMainHelp

func RenderMainHelp(root *cobra.Command) string

RenderMainHelp builds the screen. Exported so a test can assert it without going through cobra's help plumbing.

func Report

func Report(writer io.Writer, executed *cobra.Command, err error) int

Report renders a command failure and returns the status the process should exit with.

Lives here rather than in main so it can be exercised: the difference between what a user sees for a cancelled prompt and for a failed request is the whole point of it, and main() is not reachable from a test.

func ReportBlock

func ReportBlock(err error) string

ReportBlock is what the CLI prints under an error when --report is given.

func ReportURL

func ReportURL(err error) string

ReportURL builds a prefilled GitHub issue for a failed command.

CLI releases tell the user to "pass the --verbose or --report flag" on every error; in Go the second half of that sentence was a lie, because the flag did not exist.

func RequiredArgument

func RequiredArgument(name, description string) cobra.PositionalArgs

RequiredArgument validates a command that takes exactly one argument, and says which one when it is missing. cobra's own `accepts 1 arg(s), received 0` names neither the argument nor the command; description is the argument's help text, which is what turns the error into an instruction.

func RewriteBooleanValues

func RewriteBooleanValues(root *cobra.Command, args []string) []string

RewriteBooleanValues joins `--flag value` into `--flag=value` for boolean flags, so the space-separated spelling keeps working.

Runs before cobra parses. Find matches on command names only, ignoring flags, so the target command -- and therefore which of its flags are boolean -- is known without parsing anything.

func SafeDirectoryName

func SafeDirectoryName(value, fallback string) string

SafeDirectoryName turns a resource name into a directory name.

Accents are stripped, everything outside [a-z0-9] collapses to a single hyphen, and a name that reduces to nothing falls back to the id -- otherwise two unnamed resources would share a directory.

Types

type FunctionEntry

type FunctionEntry struct {
	ID                        string   `json:"$id"`
	Name                      string   `json:"name"`
	Runtime                   string   `json:"runtime"`
	BuildSpecification        string   `json:"buildSpecification"`
	RuntimeSpecification      string   `json:"runtimeSpecification"`
	Execute                   []string `json:"execute"`
	Events                    []string `json:"events"`
	Scopes                    []string `json:"scopes"`
	Schedule                  string   `json:"schedule"`
	Timeout                   int      `json:"timeout"`
	Enabled                   bool     `json:"enabled"`
	Logging                   bool     `json:"logging"`
	Entrypoint                string   `json:"entrypoint"`
	Commands                  string   `json:"commands"`
	Ignore                    []string `json:"ignore"`
	DeploymentRetention       int      `json:"deploymentRetention"`
	Path                      string   `json:"path"`
	PreviewDomainTarget       string   `json:"previewDomainTarget,omitempty"`
	PreviewDomainLabel        string   `json:"previewDomainLabel,omitempty"`
	InstallationID            string   `json:"installationId,omitempty"`
	ProviderRepositoryID      string   `json:"providerRepositoryId,omitempty"`
	ProviderRepositoryName    string   `json:"providerRepositoryName,omitempty"`
	ProviderRepositoryPrivate bool     `json:"providerRepositoryPrivate,omitempty"`
	ProviderRepositoryPending bool     `json:"providerRepositoryPending,omitempty"`
	ProviderBranch            string   `json:"providerBranch,omitempty"`
	ProviderSilentMode        bool     `json:"providerSilentMode,omitempty"`
	ProviderRootDirectory     string   `json:"providerRootDirectory,omitempty"`
	ProviderBranches          []string `json:"providerBranches,omitempty"`
	ProviderPaths             []string `json:"providerPaths,omitempty"`
	TemplateRepository        string   `json:"templateRepository,omitempty"`
	TemplateOwner             string   `json:"templateOwner,omitempty"`
	TemplateRootDirectory     string   `json:"templateRootDirectory,omitempty"`
	TemplateReference         string   `json:"templateReference,omitempty"`
	TemplateReferenceType     string   `json:"templateReferenceType,omitempty"`
}

FunctionEntry is a function as `init function` writes it.

Field order is what lands in the file, so it is contractual. `ignore` is a list here and a newline-joined string in config.Function: that type is the READ model used by `run`, and the two are deliberately separate rather than one type trying to be both.

type SiteEntry

type SiteEntry struct {
	ID                   string `json:"$id"`
	Name                 string `json:"name"`
	Framework            string `json:"framework"`
	Adapter              string `json:"adapter"`
	BuildRuntime         string `json:"buildRuntime"`
	InstallCommand       string `json:"installCommand"`
	BuildCommand         string `json:"buildCommand"`
	OutputDirectory      string `json:"outputDirectory"`
	FallbackFile         string `json:"fallbackFile"`
	BuildSpecification   string `json:"buildSpecification"`
	RuntimeSpecification string `json:"runtimeSpecification"`
	DeploymentRetention  int    `json:"deploymentRetention"`
	Timeout              int    `json:"timeout"`
	Logging              bool   `json:"logging"`
	Path                 string `json:"path"`
}

SiteEntry is a site as `init site` writes it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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