Documentation
¶
Index ¶
- Constants
- Variables
- func CancellationNotice(command *cobra.Command) string
- func ErrorDetail(err error) string
- func Execute(root *cobra.Command) (*cobra.Command, error)
- func FormatError(err error) string
- func IsCancelled(err error) bool
- func NewRootCommand() *cobra.Command
- func RenderMainHelp(root *cobra.Command) string
- func Report(writer io.Writer, executed *cobra.Command, err error) int
- func ReportBlock(err error) string
- func ReportURL(err error) string
- func RequiredArgument(name, description string) cobra.PositionalArgs
- func RewriteBooleanValues(root *cobra.Command, args []string) []string
- func SafeDirectoryName(value, fallback string) string
- type FunctionEntry
- type SiteEntry
Constants ¶
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 ¶
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().
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 ¶
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 ¶
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 FormatError ¶
FormatError renders a command failure for the terminal.
func IsCancelled ¶
IsCancelled reports whether a command stopped because the user cancelled a prompt rather than because anything went wrong.
func NewRootCommand ¶
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 ¶
RenderMainHelp builds the screen. Exported so a test can assert it without going through cobra's help plumbing.
func Report ¶
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 ¶
ReportBlock is what the CLI prints under an error when --report is given.
func ReportURL ¶
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 ¶
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 ¶
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.
Source Files
¶
- ambient_native.go
- client.go
- commands_host.go
- commands_portable.go
- completion.go
- endpoint.go
- errors.go
- flags.go
- generate.go
- generic.go
- help.go
- init.go
- initfunction.go
- initproject.go
- initprojectskills.go
- initscaffold.go
- initsite.go
- initskill.go
- login.go
- logout.go
- organization.go
- pull.go
- pullall.go
- pulldatabase.go
- pullfunction.go
- pullsettings.go
- pushall.go
- pushcommon.go
- pushdatabase.go
- pushdeploy.go
- pushpreview.go
- pushsimple.go
- resource.go
- root.go
- run.go
- runjwt.go
- session.go
- types.go
- update.go