utils

package
v0.2.82 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

utils/utils.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfirmAction added in v0.0.4

func ConfirmAction(message string) bool

ConfirmAction asks user for confirmation using promptui

func FormatDate added in v0.0.4

func FormatDate(t time.Time) string

FormatDate formats a date for display

func FormatDateShort added in v0.0.4

func FormatDateShort(t time.Time) string

FormatDateShort formats a date in short format

func GetBaseName added in v0.0.4

func GetBaseName(path string) string

GetBaseName returns the base name of a directory path

func GetLinkedProject added in v0.0.4

func GetLinkedProject() (string, error)

GetLinkedProject returns the project ID linked to the current directory

func GetProjectIDOrLinked added in v0.0.4

func GetProjectIDOrLinked(projectID string) (string, error)

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

func GetStatusIcon(status string) string

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

func IsValidURL(testURL string) bool

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

func PromptUser(message string) (string, error)

PromptUser prompts user for input with a message using promptui

func PromptUserWithDefault added in v0.0.4

func PromptUserWithDefault(message, defaultValue string) string

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 RunCommand

func RunCommand(name string, args ...string) (string, error)

func RunCommandWithEnv added in v0.2.10

func RunCommandWithEnv(name string, args []string, env []string) (string, error)

RunCommandWithEnv runs a command with custom environment variables

func RunCommandWithEnvStreaming added in v0.2.36

func RunCommandWithEnvStreaming(name string, args []string, env []string) (string, error)

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

func RunShellCommandWithEnv(command string, extraEnv []string) (string, error)

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

func RunShellCommandWithEnvStreaming(command string, extraEnv []string) (string, error)

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:

  1. bash (Git Bash)
  2. sh (MSYS)
  3. 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

func SelectOption(label string, options []string) (int, string, error)

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

func TruncateString(s string, length int) string

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

Jump to

Keyboard shortcuts

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