75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package status
|
||
|
||
import (
|
||
"fmt"
|
||
"strings"
|
||
)
|
||
|
||
const (
|
||
// obrimStatusLabelInfo represents the INFO status label.
|
||
obrimStatusLabelInfo = "INFO"
|
||
|
||
// obrimStatusLabelWarning represents the WARNING status label.
|
||
obrimStatusLabelWarning = "WARNING"
|
||
|
||
// obrimStatusLabelSuccess represents the SUCCESS status label.
|
||
obrimStatusLabelSuccess = "SUCCESS"
|
||
|
||
// obrimStatusLabelError represents the ERROR status label.
|
||
obrimStatusLabelError = "ERROR"
|
||
)
|
||
|
||
// ObrimStatus emits a standardized CLI status message.
|
||
func ObrimStatus(label string, message string) {
|
||
normalizedLabel := obrimStatusNormalizeLabel(label)
|
||
formattedLabel := obrimStatusFormatLabel(normalizedLabel)
|
||
indicator := obrimStatusFormatIndicator(normalizedLabel)
|
||
finalMessage := obrimStatusBuildMessage(formattedLabel, indicator, message)
|
||
|
||
fmt.Println(finalMessage)
|
||
}
|
||
|
||
// obrimStatusNormalizeLabel normalizes and validates status labels.
|
||
func obrimStatusNormalizeLabel(label string) string {
|
||
normalizedLabel := strings.ToUpper(strings.TrimSpace(label))
|
||
|
||
switch normalizedLabel {
|
||
case obrimStatusLabelInfo:
|
||
return obrimStatusLabelInfo
|
||
case obrimStatusLabelWarning:
|
||
return obrimStatusLabelWarning
|
||
case obrimStatusLabelSuccess:
|
||
return obrimStatusLabelSuccess
|
||
case obrimStatusLabelError:
|
||
return obrimStatusLabelError
|
||
default:
|
||
return obrimStatusLabelInfo
|
||
}
|
||
}
|
||
|
||
// obrimStatusFormatLabel formats semantic status labels.
|
||
func obrimStatusFormatLabel(label string) string {
|
||
return fmt.Sprintf("[%s]", label)
|
||
}
|
||
|
||
// obrimStatusFormatIndicator generates visual status indicators.
|
||
func obrimStatusFormatIndicator(label string) string {
|
||
switch label {
|
||
case obrimStatusLabelInfo:
|
||
return "ℹ"
|
||
case obrimStatusLabelWarning:
|
||
return "⚠"
|
||
case obrimStatusLabelSuccess:
|
||
return "✓"
|
||
case obrimStatusLabelError:
|
||
return "✖"
|
||
default:
|
||
return "ℹ"
|
||
}
|
||
}
|
||
|
||
// obrimStatusBuildMessage constructs the final terminal message.
|
||
func obrimStatusBuildMessage(label string, indicator string, message string) string {
|
||
return fmt.Sprintf("%s %s %s", indicator, label, message)
|
||
}
|