cmdutil

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cmdutil provides shared helpers for repository command utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fatalf

func Fatalf(message string, args ...any)

Fatalf writes a formatted error message to stderr and exits with status 1.

func Must

func Must[T any](value T, err error) T

Must returns value, and panics when err is non-nil.

It is for an operation that cannot fail where it is called and whose failure a caller could not act on anyway: connecting an in-memory MCP transport, building the action catalog compiled into this binary, marshaling a struct the program built a line earlier. Returning such an error adds a return path to every frame it crosses, none of which can ever execute, and every caller can only print it and stop, which is what this panic already does. It is the standard library's Must convention, regexp.MustCompile and template.Must, applied to this module's command utilities.

Do not use it for a failure a caller can act on: a bad flag, a missing file, a generated artifact that has drifted. Those return an error so the command reports them cleanly and chooses its own exit code.

The panic carries the error, so wrap the error where it is produced if it does not already say what was attempted. Go's call rules make a context argument impossible here: f(g()) compiles only when g's results are exactly f's parameters.

func MustDo

func MustDo(err error)

MustDo panics when err is non-nil. It is Must for an operation that returns no value, and carries the same contract: use it only where the failure cannot happen and a caller could not act on it.

func Progressf

func Progressf(message string, args ...any)

Progressf writes a formatted progress line to stderr so long-running command utilities show activity instead of looking stale. It writes to stderr (never stdout) so it never pollutes JSON or generated output captured from stdout. A trailing newline is added automatically.

func RepositoryRoot

func RepositoryRoot(start string) (string, error)

RepositoryRoot walks upward from start until it finds the module root.

Types

This section is empty.

Jump to

Keyboard shortcuts

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