util

package
v0.0.171 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version = "dev"
	Commit  = "unknown"
)
View Source
var ErrTimeout = errors.New("timeout")
View Source
var PackageJsonKeysOrder = []string{
	"name",
	"description",
	"version",
	"main",
	"type",
	"scripts",
	"keywords",
	"author",
	"license",
	"engines",
	"private",
	"devDependencies",
	"peerDependencies",
	"dependencies",
}

these are the keys that will be written in order to the package.json file if a key is not present, it will be added to the end of the file

View Source
var TypeScriptConfigJsonKeysOrder = []string{
	"compilerOptions",
	"include",
	"exclude",
}

these are the keys that will be written in order to the package.json file if a key is not present, it will be added to the end of the file

Functions

func BrowserFlow

func BrowserFlow(opts BrowserFlowOptions) error

BrowserFlow will open a browser and wait for the user to finish the flow. It will return an error if the flow times out with an ErrTimeout error. It will return an error if the callback fails or any other error occurs.

func CheckLatestRelease added in v0.0.70

func CheckLatestRelease(ctx context.Context, logger logger.Logger, force bool) (bool, error)

func CopyDir

func CopyDir(src string, dst string) error

CopyDir will copy all files recursively from src to dst

func CopyFile

func CopyFile(src, dst string) (int64, error)

CopyFile will copy src to dst

func EnsureLoggedIn added in v0.0.42

func EnsureLoggedIn(ctx context.Context, logger logger.Logger, cmd *cobra.Command) (string, string)

func EnsureLoggedInWithOnlyAPIKey added in v0.0.43

func EnsureLoggedInWithOnlyAPIKey(ctx context.Context, logger logger.Logger, cmd *cobra.Command) string

func Exists

func Exists(fn string) bool

Exists returns true if the filename or directory specified by fn exists.

func GetAppSupportDir added in v0.0.74

func GetAppSupportDir(appName string) string

GetAppSupportDir returns the path to the application support directory for the current user. It supports Darwin, Windows, and Linux. Returns an empty string if the directory cannot be determined.

func GetLatestRelease added in v0.0.70

func GetLatestRelease(ctx context.Context) (string, error)

GetLatestRelease returns the latest release tag name from the GitHub API

func GetRelativePath added in v0.0.75

func GetRelativePath(basePath, absolutePath string) string

func GetURLs added in v0.0.42

func GetURLs(logger logger.Logger) (string, string, string)

func ListDir

func ListDir(dir string) ([]string, error)

ListDir will return an array of files recursively walking into sub directories

func MaxString added in v0.0.133

func MaxString(val string, max int) string

func NewOrderedMap added in v0.0.26

func NewOrderedMap(keys []string, data map[string]any) *orderedMap

func NewOrderedMapFromFile added in v0.0.26

func NewOrderedMapFromFile(keys []string, filename string) (*orderedMap, error)

func NewOrderedMapFromJSON added in v0.0.26

func NewOrderedMapFromJSON(keys []string, buf []byte) (*orderedMap, error)

func Pluralize added in v0.0.23

func Pluralize(count int, singular string, plural string) string

func ProcessKill added in v0.0.74

func ProcessKill(cmd *exec.Cmd)

func ProcessSetup added in v0.0.74

func ProcessSetup(cmd *exec.Cmd)

func PromptBrowserOpen added in v0.0.162

func PromptBrowserOpen(logger interface{ Error(string, ...interface{}) }, url string)

PromptBrowserOpen prompts the user to press Enter to open a browser to the given URL. It handles display detection on Linux and provides appropriate user feedback.

func RandStringBytes

func RandStringBytes(n int) string

RandStringBytes will generate a random string of length n using the alphaNumChars string.

func ReadFileLines added in v0.0.75

func ReadFileLines(filename string, startLine, endLine int) ([]string, error)

func RemoveDuplicates added in v0.0.121

func RemoveDuplicates[T comparable](slice []T) []T

func RemoveEmpty added in v0.0.121

func RemoveEmpty[T comparable](slice []T) []T

func SafeProjectFilename added in v0.0.142

func SafeProjectFilename(name string, python bool) string

func ShowLogin added in v0.0.42

func ShowLogin(ctx context.Context, logger logger.Logger, cmd *cobra.Command)

func TransformUrl added in v0.0.47

func TransformUrl(urlString string) string

func TryLoggedIn added in v0.0.74

func TryLoggedIn() (string, string, bool)

func UpgradeCLI added in v0.0.75

func UpgradeCLI(ctx context.Context, logger logger.Logger, force bool) error

func UserAgent added in v0.0.70

func UserAgent() string

func ZipDir

func ZipDir(dir string, outfilename string, opts ...Option) error

ZipDir will zip up a directory into the outfilename and return an error if it fails

Types

type APIClient

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

func NewAPIClient

func NewAPIClient(ctx context.Context, logger logger.Logger, baseURL, token string) *APIClient

func (*APIClient) Do

func (c *APIClient) Do(method, pathParam string, payload interface{}, response interface{}) error

type APIError added in v0.0.51

type APIError struct {
	URL      string
	Method   string
	Status   int
	Body     string
	TheError error
	TraceID  string
}

func NewAPIError added in v0.0.51

func NewAPIError(url, method string, status int, body string, err error, traceID string) *APIError

func (*APIError) Error added in v0.0.51

func (e *APIError) Error() string

type APIResponse added in v0.0.52

type APIResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Code    string `json:"code,omitempty"`
	Error   struct {
		Issues []struct {
			Code    string   `json:"code"`
			Message string   `json:"message"`
			Path    []string `json:"path"`
		} `json:"issues"`
	} `json:"error"`
}

type BrowserFlowOptions

type BrowserFlowOptions struct {
	Logger      logger.Logger
	BaseUrl     string
	StartPath   string
	WaitMessage string
	AuthToken   string
	Query       map[string]string
	Callback    browserCallback
}

type Option added in v0.0.143

type Option func(*options)

func WithMatcher added in v0.0.143

func WithMatcher(matcher ZipDirCallbackMatcher) Option

WithMatcher will filter the files that are added to the zip

func WithMutator added in v0.0.143

func WithMutator(mutator ZipDirCallbackMutator) Option

WithMutator will mutate the zip file after it has been created allowing you to add files to the zip

type ZipDirCallbackMatcher

type ZipDirCallbackMatcher func(fn string, fi os.FileInfo) bool

ZipDirCallbackMatcher is a function that returns true if the file should be included in the zip

type ZipDirCallbackMutator added in v0.0.143

type ZipDirCallbackMutator func(writer *zip.Writer) error

Jump to

Keyboard shortcuts

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