Documentation
¶
Overview ¶
utils/utils.go
Index ¶
- func ConfirmAction(message string) bool
- func FormatDate(t time.Time) string
- func FormatDateShort(t time.Time) string
- func GetBaseName(path string) string
- func GetLinkedProject() (string, error)
- func GetProjectIDOrLinked(projectID string) (string, error)
- func GetStatusIcon(status string) string
- func HandleAuthError(err error, opts OutputOptions) bool
- func HandleError(err error, message string, opts OutputOptions)
- func IsLinkedProject() bool
- func IsRoot() bool
- func IsValidURL(testURL string) bool
- func PrintError(message string, opts OutputOptions)
- func PrintInfo(message string, opts OutputOptions)
- func PrintJSON(data interface{}) error
- func PrintProjectContext(projectID string)
- func PrintProjectContextWithOptions(projectID string, opts OutputOptions)
- func PrintSuccess(message string, opts OutputOptions)
- func PrintTable(headers []string, rows [][]string, opts OutputOptions)
- func PrintWarning(message string, opts OutputOptions)
- func PromptUser(message string) (string, error)
- func PromptUserWithDefault(message, defaultValue string) string
- func RequireAuth(client interface{ ... }, opts OutputOptions) bool
- func RunCommand(name string, args ...string) (string, error)
- func RunCommandWithEnv(name string, args []string, env []string) (string, error)
- func RunCommandWithEnvStreaming(name string, args []string, env []string) (string, error)
- func RunShellCommandWithEnv(command string, extraEnv []string) (string, error)
- func RunShellCommandWithEnvStreaming(command string, extraEnv []string) (string, error)
- func SaveProjectContext(context *ProjectContext) error
- func SelectOption(label string, options []string) (int, string, error)
- func StartSpinner(message string, opts OutputOptions) interface{}
- func StopSpinner(s interface{})
- func TruncateString(s string, length int) string
- func ValidateOrPrompt() error
- func WithJSONOutput(fn func() (interface{}, error), opts OutputOptions) error
- type OutputFormat
- type OutputOptions
- type ProjectContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfirmAction ¶ added in v0.0.4
ConfirmAction asks user for confirmation using promptui
func FormatDate ¶ added in v0.0.4
FormatDate formats a date for display
func FormatDateShort ¶ added in v0.0.4
FormatDateShort formats a date in short format
func GetBaseName ¶ added in v0.0.4
GetBaseName returns the base name of a directory path
func GetLinkedProject ¶ added in v0.0.4
GetLinkedProject returns the project ID linked to the current directory
func GetProjectIDOrLinked ¶ added in v0.0.4
GetProjectIDOrLinked returns the provided project ID or the linked project ID If projectID is provided, it uses that. Otherwise, it tries to get the linked project.
func GetStatusIcon ¶ added in v0.0.4
GetStatusIcon returns a text-based icon for status
func HandleAuthError ¶ added in v0.2.9
func HandleAuthError(err error, opts OutputOptions) bool
HandleAuthError handles authentication errors with specific messaging
func HandleError ¶ added in v0.0.4
func HandleError(err error, message string, opts OutputOptions)
HandleError handles errors consistently across commands
func IsLinkedProject ¶ added in v0.0.4
func IsLinkedProject() bool
IsLinkedProject checks if current directory has a linked project
func IsRoot ¶ added in v0.2.81
func IsRoot() bool
IsRoot checks if the current process is running with root privileges
func IsValidURL ¶
IsValidURL checks if the provided string is a valid URL.
func PrintError ¶ added in v0.0.4
func PrintError(message string, opts OutputOptions)
PrintError prints an error message with color
func PrintInfo ¶ added in v0.0.4
func PrintInfo(message string, opts OutputOptions)
PrintInfo prints an info message with color
func PrintJSON ¶ added in v0.0.4
func PrintJSON(data interface{}) error
PrintJSON prints data as JSON
func PrintProjectContext ¶ added in v0.0.4
func PrintProjectContext(projectID string)
PrintProjectContext prints information about the current project context
func PrintProjectContextWithOptions ¶ added in v0.0.4
func PrintProjectContextWithOptions(projectID string, opts OutputOptions)
PrintProjectContextWithOptions prints project context information with output options
func PrintSuccess ¶ added in v0.0.4
func PrintSuccess(message string, opts OutputOptions)
PrintSuccess prints a success message with color
func PrintTable ¶ added in v0.0.4
func PrintTable(headers []string, rows [][]string, opts OutputOptions)
PrintTable prints data in a table format using tablewriter
func PrintWarning ¶ added in v0.0.4
func PrintWarning(message string, opts OutputOptions)
PrintWarning prints a warning message with color
func PromptUser ¶ added in v0.0.4
PromptUser prompts user for input with a message using promptui
func PromptUserWithDefault ¶ added in v0.0.4
PromptUserWithDefault prompts user for input with a default value using promptui
func RequireAuth ¶ added in v0.0.4
func RequireAuth(client interface{ IsAuthenticated() bool }, opts OutputOptions) bool
RequireAuth checks if user is authenticated and prints error if not
func RunCommandWithEnv ¶ added in v0.2.10
RunCommandWithEnv runs a command with custom environment variables
func RunCommandWithEnvStreaming ¶ added in v0.2.36
RunCommandWithEnvStreaming runs a command with custom environment variables while streaming stdout/stderr directly to the console. It still captures output for returning errors to callers.
func RunShellCommandWithEnv ¶ added in v0.2.38
RunShellCommandWithEnv runs a shell command and captures stdout/stderr. It uses the same shell selection logic as RunShellCommandWithEnvStreaming.
func RunShellCommandWithEnvStreaming ¶ added in v0.2.38
RunShellCommandWithEnvStreaming runs a shell command while streaming stdout/stderr to the console. It picks an appropriate shell per-OS.
On Windows, the PipeOps agent installer scripts require a POSIX shell. We try:
- bash (Git Bash)
- sh (MSYS)
- wsl (WSL2) + bash
extraEnv should be a slice of KEY=VALUE pairs that will be added to the process environment. Only keys in extraEnv are forwarded to WSL via WSLENV.
func SaveProjectContext ¶ added in v0.0.4
func SaveProjectContext(context *ProjectContext) error
SaveProjectContext saves project context to .pipeops/project.json
func SelectOption ¶ added in v0.2.29
SelectOption prompts user to select from a list of options
func StartSpinner ¶ added in v0.2.29
func StartSpinner(message string, opts OutputOptions) interface{}
StartSpinner starts a new spinner with the given message
func StopSpinner ¶ added in v0.2.29
func StopSpinner(s interface{})
StopSpinner stops the spinner if it exists
func TruncateString ¶ added in v0.0.4
TruncateString truncates a string to the specified length
func ValidateOrPrompt ¶
func ValidateOrPrompt() error
func WithJSONOutput ¶ added in v0.0.4
func WithJSONOutput(fn func() (interface{}, error), opts OutputOptions) error
WithJSONOutput wraps a function to support JSON output
Types ¶
type OutputFormat ¶ added in v0.0.4
type OutputFormat string
OutputFormat represents the output format type
const ( OutputFormatTable OutputFormat = "table" OutputFormatJSON OutputFormat = "json" )
type OutputOptions ¶ added in v0.0.4
type OutputOptions struct {
Format OutputFormat
Quiet bool
Verbose bool
}
OutputOptions contains options for output formatting
func GetOutputOptions ¶ added in v0.0.4
func GetOutputOptions(cmd *cobra.Command) OutputOptions
GetOutputOptions extracts output options from command flags
type ProjectContext ¶ added in v0.0.4
type ProjectContext struct {
ProjectID string `json:"project_id"`
ProjectName string `json:"project_name"`
Directory string `json:"directory"`
LinkedAt time.Time `json:"linked_at"`
}
ProjectContext represents the context of a linked project
func LoadProjectContext ¶ added in v0.0.4
func LoadProjectContext() (*ProjectContext, error)
LoadProjectContext loads project context from .pipeops/project.json