Add godoc strings to all exported types, functions, and fields

Documents:
- cli: NO_COLOR, RunOptions fields, CLIApp, VersionString
- checker: Result fields, Status constants, CheckStatus fields
- scanner: EnumerateStatus, ScanStatus, Options, FileEntry fields
- log: Level alias, DisableStyling, Init, Info/Debug functions,
  verbosity helpers, GetLogger, GetLevel, WithError
- mfer: ManifestScanOptions, New, NewFromPaths, NewFromFS, MAGIC
This commit is contained in:
2025-12-17 11:17:38 -08:00
parent 155ebe9a78
commit 79fc5cca6c
7 changed files with 72 additions and 50 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/pterm/pterm"
)
// Level is an alias for apex/log.Level for use by callers without importing apex/log.
type Level = log.Level
var (
@@ -48,6 +49,7 @@ func GetStderr() io.Writer {
return stderr
}
// DisableStyling turns off colors and styling for terminal output.
func DisableStyling() {
pterm.DisableColor()
pterm.DisableStyling()
@@ -59,6 +61,7 @@ func DisableStyling() {
pterm.Fatal.Prefix.Text = ""
}
// Init initializes the logger with the CLI handler and default log level.
func Init() {
mu.RLock()
w := stderr
@@ -67,22 +70,27 @@ func Init() {
log.SetLevel(log.InfoLevel)
}
// Infof logs a formatted message at info level.
func Infof(format string, args ...interface{}) {
log.Infof(format, args...)
}
// Info logs a message at info level.
func Info(arg string) {
log.Info(arg)
}
// Debugf logs a formatted message at debug level with caller location.
func Debugf(format string, args ...interface{}) {
DebugReal(fmt.Sprintf(format, args...), 2)
}
// Debug logs a message at debug level with caller location.
func Debug(arg string) {
DebugReal(arg, 2)
}
// DebugReal logs at debug level with caller info from the specified stack depth.
func DebugReal(arg string, cs int) {
_, callerFile, callerLine, ok := runtime.Caller(cs)
if !ok {
@@ -92,14 +100,18 @@ func DebugReal(arg string, cs int) {
log.Debug(tag + arg)
}
// Dump logs a spew dump of the arguments at debug level.
func Dump(args ...interface{}) {
DebugReal(spew.Sdump(args...), 2)
}
// EnableDebugLogging sets the log level to debug.
func EnableDebugLogging() {
SetLevel(log.DebugLevel)
}
// VerbosityStepsToLogLevel converts a -v count to a log level.
// 0 returns InfoLevel, 1+ returns DebugLevel.
func VerbosityStepsToLogLevel(l int) log.Level {
switch l {
case 0:
@@ -111,14 +123,17 @@ func VerbosityStepsToLogLevel(l int) log.Level {
return log.DebugLevel
}
// SetLevelFromVerbosity sets the log level based on -v flag count.
func SetLevelFromVerbosity(l int) {
SetLevel(VerbosityStepsToLogLevel(l))
}
// SetLevel sets the global log level.
func SetLevel(arg log.Level) {
log.SetLevel(arg)
}
// GetLogger returns the underlying apex/log Logger.
func GetLogger() *log.Logger {
if logger, ok := log.Log.(*log.Logger); ok {
return logger
@@ -126,10 +141,12 @@ func GetLogger() *log.Logger {
panic("unable to get logger")
}
// GetLevel returns the current log level.
func GetLevel() log.Level {
return GetLogger().Level
}
// WithError returns a log entry with the error attached.
func WithError(e error) *log.Entry {
return GetLogger().WithError(e)
}