125 lines
3.3 KiB
Go
125 lines
3.3 KiB
Go
/*
|
||
|--------------------------------------------------------------------------
|
||
| Metadata
|
||
|--------------------------------------------------------------------------
|
||
|
|
||
| Name:
|
||
| - Status
|
||
|
|
||
| Purpose:
|
||
| - Provide a framework-level CLI status utility that standardizes
|
||
| terminal message presentation using semantic labels and visual
|
||
| indicators to ensure consistent output across all softwares.
|
||
|
|
||
| Guideline:
|
||
| - Call ObrimStatus() whenever a standardized terminal status message
|
||
| must be emitted.
|
||
| - Use only supported semantic labels: INFO, WARNING, SUCCESS, ERROR.
|
||
| - Invalid, unsupported, or empty labels are automatically normalized
|
||
| to INFO.
|
||
| - Status operates through terminal output side-effects and does not
|
||
| return any value.
|
||
|
|
||
| Example:
|
||
| - ObrimStatus("INFO", "Application started.")
|
||
| - ObrimStatus("SUCCESS", "Configuration loaded.")
|
||
| - ObrimStatus("WARNING", "Configuration file not found.")
|
||
| - ObrimStatus("ERROR", "Unable to establish connection.")
|
||
|
|
||
|--------------------------------------------------------------------------
|
||
*/
|
||
|
||
/*
|
||
|--------------------------------------------------------------------------
|
||
| Credit
|
||
|--------------------------------------------------------------------------
|
||
|
|
||
| Contributor:
|
||
| - Rajon Ahmed
|
||
| - Blockonite
|
||
|
|
||
|--------------------------------------------------------------------------
|
||
*/
|
||
|
||
package status
|
||
|
||
import (
|
||
"fmt"
|
||
"strings"
|
||
)
|
||
|
||
const (
|
||
obrimStatusLabelInfo = "INFO"
|
||
obrimStatusLabelWarning = "WARNING"
|
||
obrimStatusLabelSuccess = "SUCCESS"
|
||
obrimStatusLabelError = "ERROR"
|
||
)
|
||
|
||
// obrimStatusIndicatorRegistry stores status indicators.
|
||
var obrimStatusIndicatorRegistry = map[string]string{
|
||
obrimStatusLabelInfo: "ℹ",
|
||
obrimStatusLabelWarning: "⚠",
|
||
obrimStatusLabelSuccess: "✓",
|
||
obrimStatusLabelError: "✖",
|
||
}
|
||
|
||
// ObrimStatus emits a standardized CLI status message.
|
||
func ObrimStatus(label string, message string) {
|
||
normalizedLabel := obrimStatusNormalizeLabel(label)
|
||
formattedLabel := obrimStatusFormatLabel(normalizedLabel)
|
||
formattedIndicator := obrimStatusFormatIndicator(normalizedLabel)
|
||
formattedMessage := obrimStatusBuildMessage(
|
||
formattedLabel,
|
||
formattedIndicator,
|
||
message,
|
||
)
|
||
|
||
fmt.Println(formattedMessage)
|
||
}
|
||
|
||
// obrimStatusNormalizeLabel normalizes and validates 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 labels.
|
||
func obrimStatusFormatLabel(label string) string {
|
||
return fmt.Sprintf("[%s]", label)
|
||
}
|
||
|
||
// obrimStatusFormatIndicator generates visual status indicators.
|
||
func obrimStatusFormatIndicator(label string) string {
|
||
indicator, exists := obrimStatusIndicatorRegistry[label]
|
||
if !exists {
|
||
return obrimStatusIndicatorRegistry[obrimStatusLabelInfo]
|
||
}
|
||
|
||
return indicator
|
||
}
|
||
|
||
// obrimStatusBuildMessage constructs the final terminal message.
|
||
func obrimStatusBuildMessage(
|
||
label string,
|
||
indicator string,
|
||
message string,
|
||
) string {
|
||
return fmt.Sprintf("%s %s %s", indicator, label, message)
|
||
}
|