Skip to content

Commit 1af5d14

Browse files
refactor: improve command initialization and help display with consistent UI banner
1 parent a010381 commit 1af5d14

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

cmd/root.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ import (
1313

1414
// rootCmd represents the base command
1515
var rootCmd = &cobra.Command{
16-
Use: "aibomgen-cli",
16+
Use: "AIBoMGen-cli",
1717
Short: "BOM Generator for Software Projects using AI {}",
18-
Long: bannerASCII + "\n" + "BOM Generator for Software Projects using AI. Helps PDE manufacturers create accurate Bills of Materials for their AI-based software projects.",
18+
Long: longDescription,
1919

2020
PersistentPreRun: func(cmd *cobra.Command, args []string) {
21-
ui.Init(noColor)
21+
initUIAndBanner(cmd)
22+
},
23+
24+
// When invoked without a subcommand, show help (with banner) instead of
25+
// printing a plain usage output.
26+
RunE: func(cmd *cobra.Command, args []string) error {
27+
initUIAndBanner(cmd)
28+
return cmd.Help()
2229
},
2330
}
2431

@@ -40,6 +47,13 @@ func init() {
4047
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.aibomgen-cli.yaml)")
4148
rootCmd.PersistentFlags().BoolVar(&noColor, "no-color", false, "Disable colored output")
4249

50+
// Ensure `--help` (and help subcommands) show a green banner consistently.
51+
defaultHelp := rootCmd.HelpFunc()
52+
rootCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
53+
initUIAndBanner(cmd)
54+
defaultHelp(cmd, args)
55+
})
56+
4357
// Add subcommands
4458
rootCmd.AddCommand(generateCmd, enrichCmd, validateCmd)
4559
}
@@ -77,7 +91,21 @@ func initConfig() {
7791

7892
// Simple ASCII banner shown at startup
7993
const bannerASCII = `
80-
░█▀█░▀█▀░█▀▄░█▀█░█▄█░█▀▀░█▀▀░█▀█░░░█▀▀░█▀▄░█▀█
81-
░█▀█░░█░░█▀▄░█░█░█░█░█░█░█▀▀░█░█░░░█░░░█▀▄░█▀█
82-
░▀░▀░▀▀▀░▀▀░░▀▀▀░▀░▀░▀▀▀░▀▀▀░▀░▀░░░▀▀▀░▀░▀░▀░▀
94+
/$$$$$$ /$$$$$$ /$$$$$$$ /$$ /$$ /$$$$$$ /$$ /$$
95+
/$$__ $$|_ $$_/| $$__ $$ | $$$ /$$$ /$$__ $$ | $$|__/
96+
| $$ \ $$ | $$ | $$ \ $$ /$$$$$$ | $$$$ /$$$$| $$ \__/ /$$$$$$ /$$$$$$$ /$$$$$$$| $$ /$$
97+
| $$$$$$$$ | $$ | $$$$$$$ /$$__ $$| $$ $$/$$ $$| $$ /$$$$ /$$__ $$| $$__ $$ /$$$$$$ /$$_____/| $$| $$
98+
| $$__ $$ | $$ | $$__ $$| $$ \ $$| $$ $$$| $$| $$|_ $$| $$$$$$$$| $$ \ $$|______/| $$ | $$| $$
99+
| $$ | $$ | $$ | $$ \ $$| $$ | $$| $$\ $ | $$| $$ \ $$| $$_____/| $$ | $$ | $$ | $$| $$
100+
| $$ | $$ /$$$$$$| $$$$$$$/| $$$$$$/| $$ \/ | $$| $$$$$$/| $$$$$$$| $$ | $$ | $$$$$$$| $$| $$
101+
|__/ |__/|______/|_______/ \______/ |__/ |__/ \______/ \_______/|__/ |__/ \_______/|__/|__/
83102
`
103+
const longDescription = "BOM Generator for Software Projects using AI. Helps PDE manufacturers create accurate Bills of Materials for their AI-based software projects."
104+
105+
func initUIAndBanner(cmd *cobra.Command) {
106+
ui.Init(noColor)
107+
if cmd == nil {
108+
return
109+
}
110+
cmd.Root().Long = ui.Color(bannerASCII, ui.FgGreen) + "\n" + longDescription
111+
}

0 commit comments

Comments
 (0)