120 lines
2.8 KiB
Go
120 lines
2.8 KiB
Go
/*
|
||
|--------------------------------------------------------------------------
|
||
| Status
|
||
|--------------------------------------------------------------------------
|
||
|
|
||
| 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.
|
||
|
|
||
| Guidelines:
|
||
| - Accept semantic label and message as input.
|
||
| - Normalize and validate labels.
|
||
| - Default unsupported, empty, or invalid labels to INFO.
|
||
| - Emit exactly one terminal message per invocation.
|
||
|
|
||
| Examples:
|
||
| - ObrimStatus("INFO", "Application started.")
|
||
| - ObrimStatus("SUCCESS", "Operation completed.")
|
||
|
|
||
|--------------------------------------------------------------------------
|
||
*/
|
||
|
||
/*
|
||
|--------------------------------------------------------------------------
|
||
| Credit
|
||
|--------------------------------------------------------------------------
|
||
|
|
||
| Contributor:
|
||
| - Rajon Ahmed
|
||
|
|
||
|--------------------------------------------------------------------------
|
||
*/
|
||
|
||
package status
|
||
|
||
import (
|
||
"fmt"
|
||
"strings"
|
||
)
|
||
|
||
// Function Name: ObrimStatus
|
||
// Function Purpose: Emit a standardized CLI status message.
|
||
func ObrimStatus(label string, message string) {
|
||
// Logic:
|
||
var normalizedLabel string = obrimStatusNormalizeLabel(label)
|
||
|
||
// Logic:
|
||
var formattedLabel string = obrimStatusFormatLabel(normalizedLabel)
|
||
|
||
// Logic:
|
||
var indicator string = obrimStatusFormatIndicator(normalizedLabel)
|
||
|
||
// Logic:
|
||
var finalMessage string = obrimStatusBuildMessage(
|
||
formattedLabel,
|
||
indicator,
|
||
message,
|
||
)
|
||
|
||
// Logic:
|
||
fmt.Println(finalMessage)
|
||
}
|
||
|
||
// Function Name: obrimStatusNormalizeLabel
|
||
// Function Purpose: Normalize and validate labels.
|
||
func obrimStatusNormalizeLabel(label string) string {
|
||
// Logic:
|
||
var normalizedLabel string = 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"
|
||
}
|
||
}
|
||
|
||
// Function Name: obrimStatusFormatLabel
|
||
// Function Purpose: Format semantic labels.
|
||
func obrimStatusFormatLabel(label string) string {
|
||
return "[" + label + "]"
|
||
}
|
||
|
||
// Function Name: obrimStatusFormatIndicator
|
||
// Function Purpose: Generate visual status indicators.
|
||
func obrimStatusFormatIndicator(label string) string {
|
||
switch label {
|
||
case "INFO":
|
||
return "ℹ"
|
||
case "WARNING":
|
||
return "⚠"
|
||
case "SUCCESS":
|
||
return "✓"
|
||
case "ERROR":
|
||
return "✗"
|
||
default:
|
||
return "ℹ"
|
||
}
|
||
}
|
||
|
||
// Function Name: obrimStatusBuildMessage
|
||
// Function Purpose: Construct the final terminal message.
|
||
func obrimStatusBuildMessage(
|
||
label string,
|
||
indicator string,
|
||
message string,
|
||
) string {
|
||
return fmt.Sprintf("%s %s %s", indicator, label, message)
|
||
}
|