utils

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package utils provides shared utility functions for message formatting.

Package utils provides shared utility functions for message formatting.

Index

Constants

View Source
const (
	TreeFinalPrefix = " ╰ "
	TreeMidPrefix   = " │ "
)

Tree prefix constants for visual formatting

Variables

View Source
var AsimiVersion = "0.16.1"

Update this before each release

Functions

func GCloudProject added in v0.16.0

func GCloudProject() string

GCloudProject resolves the GCP project used by Vertex AI. GOOGLE_CLOUD_PROJECT wins; otherwise it reads the configuration files the gcloud CLI writes, so `gcloud auth application-default login` followed by `gcloud config set project` is enough to authenticate Vertex AI without exporting the variable. CLOUDSDK_CONFIG overrides the configuration directory, mirroring gcloud's own behavior.

func GetAsimiSlug

func GetAsimiSlug() string

GetAsimiSlug gets the slug for asimi's repo

func GetFileTree

func GetFileTree(root string) ([]string, error)

GetFileTree walks root and returns every file path relative to root, sorted. The ignore set is taken from the .gitignore at root, merged with a small set of always-safe built-in directories (.git, vendor). A matched directory is pruned from the walk; a matched file is omitted from the result. The override paths (heaven, earth) are re-included even when .gitignore excludes them.

func ParseVersion

func ParseVersion(v string) (semver.Version, error)

ParseVersion parses a version string, handling "v" prefix

func TruncateMiddle

func TruncateMiddle(message string, maxWidth int) string

TruncateMiddle truncates a string by keeping the beginning and end portions and replacing the middle with an ellipsis. The maxWidth parameter specifies the maximum total width of the result. The beginning portion takes 1/3 of the available space, and the end portion takes the remaining 2/3. If the message fits within maxWidth, it is returned unchanged.

Types

type MsgBlockBuilder

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

MsgBlockBuilder builds multi-line messages with tree prefixes. It mimics strings.Builder but automatically adds TreeMidPrefix to intermediate lines and TreeFinalPrefix to the last line when String() is called.

func NewMsgBlockBuilder

func NewMsgBlockBuilder(prefix string) *MsgBlockBuilder

NewMsgBlockBuilder creates a new MsgBlockBuilder with the given prefix for the first line

func (*MsgBlockBuilder) String

func (b *MsgBlockBuilder) String() string

String returns the formatted message with tree prefixes. The first line gets the configured prefix, intermediate lines get TreeMidPrefix, and the last line gets TreeFinalPrefix.

func (*MsgBlockBuilder) WriteLn

func (b *MsgBlockBuilder) WriteLn(s ...string) *MsgBlockBuilder

WriteLn ends the current line and starts a new one. If called with arguments, appends them to the current line first.

func (*MsgBlockBuilder) WriteLnf

func (b *MsgBlockBuilder) WriteLnf(format string, args ...interface{}) *MsgBlockBuilder

WriteLnf appends formatted text to the current line and ends it

func (*MsgBlockBuilder) WriteString

func (b *MsgBlockBuilder) WriteString(s string) *MsgBlockBuilder

WriteString appends text to the current line (without ending it)

func (*MsgBlockBuilder) Writef

func (b *MsgBlockBuilder) Writef(format string, args ...interface{}) *MsgBlockBuilder

Writef appends formatted text to the current line (without ending it)

type ReleaseInfo added in v0.9.0

type ReleaseInfo struct {
	Version      string
	URL          string
	AssetURL     string
	ReleaseNotes string
}

ReleaseInfo holds information about a GitHub release.

func CheckForUpdates

func CheckForUpdates(ctx context.Context) (ReleaseInfo, bool, error)

CheckForUpdates checks if a newer version is available on GitHub. The ctx controls the HTTP request timeout and cancellation.

func ParseGitHubRelease added in v0.9.0

func ParseGitHubRelease(body []byte, currentVersion string) (ReleaseInfo, bool, error)

ParseGitHubRelease parses a GitHub releases API JSON body and determines whether an update is available relative to currentVersion.

Jump to

Keyboard shortcuts

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