Documentation
¶
Overview ¶
Package utils provides shared utility functions for message formatting.
Package utils provides shared utility functions for message formatting.
Index ¶
- Constants
- Variables
- func GCloudProject() string
- func GetAsimiSlug() string
- func GetFileTree(root string) ([]string, error)
- func ParseVersion(v string) (semver.Version, error)
- func TruncateMiddle(message string, maxWidth int) string
- type MsgBlockBuilder
- func (b *MsgBlockBuilder) String() string
- func (b *MsgBlockBuilder) WriteLn(s ...string) *MsgBlockBuilder
- func (b *MsgBlockBuilder) WriteLnf(format string, args ...interface{}) *MsgBlockBuilder
- func (b *MsgBlockBuilder) WriteString(s string) *MsgBlockBuilder
- func (b *MsgBlockBuilder) Writef(format string, args ...interface{}) *MsgBlockBuilder
- type ReleaseInfo
Constants ¶
const ( TreeFinalPrefix = " ╰ " TreeMidPrefix = " │ " )
Tree prefix constants for visual formatting
Variables ¶
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 GetFileTree ¶
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 ¶
ParseVersion parses a version string, handling "v" prefix
func TruncateMiddle ¶
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
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.