obrimbaseapi/essential/visible/service/helper/status/status.go

109 lines
2.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
|--------------------------------------------------------------------------
| Manifest
|--------------------------------------------------------------------------
|
| 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 applications.
|
| Guideline:
| - Use semantic labels to classify terminal messages.
| - Invalid, unsupported, or empty labels default to INFO.
| - Emits exactly one terminal message per invocation.
| - Intended for framework and software level terminal messaging.
|
| Example:
| - ObrimStatus("INFO", "Application started.")
| - ObrimStatus("SUCCESS", "Operation completed.")
| - ObrimStatus("WARNING", "Configuration missing.")
| - ObrimStatus("ERROR", "Operation failed.")
|
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| Credit
|--------------------------------------------------------------------------
|
| Contributor:
| - Rajon Ahmed
| - Scionite
|
|--------------------------------------------------------------------------
*/
package status
import (
"fmt"
"strings"
)
// 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 "INFO":
return "INFO"
case "WARNING":
return "WARNING"
case "SUCCESS":
return "SUCCESS"
case "ERROR":
return "ERROR"
default:
return "INFO"
}
}
// obrimStatusFormatLabel formats semantic status labels.
func obrimStatusFormatLabel(label string) string {
return "[" + label + "]"
}
// obrimStatusFormatIndicator generates visual status indicators.
func obrimStatusFormatIndicator(label string) string {
switch label {
case "INFO":
return ""
case "WARNING":
return "⚠"
case "SUCCESS":
return "✓"
case "ERROR":
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)
}