mirror of
https://github.com/Valkyrie00/bold-brew.git
synced 2026-03-14 22:35:53 +01:00
feat(cli): add --version and --help flags
Add -v/--version flag to display version information. Add custom --help message with usage examples. Improve CLI user experience with clear documentation.
This commit is contained in:
parent
6e541cf05d
commit
fa7996453f
1 changed files with 34 additions and 1 deletions
|
|
@ -9,10 +9,32 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
// Parse command line flags
|
||||
// Define flags
|
||||
brewfilePath := flag.String("f", "", "Path to Brewfile (show only packages from this Brewfile)")
|
||||
showVersion := flag.Bool("v", false, "Show version information")
|
||||
flag.Bool("version", false, "Show version information")
|
||||
|
||||
// Custom usage message
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "Bold Brew - A TUI for Homebrew package management\n\n")
|
||||
fmt.Fprintf(os.Stderr, "Usage: bbrew [options]\n\n")
|
||||
fmt.Fprintf(os.Stderr, "Options:\n")
|
||||
fmt.Fprintf(os.Stderr, " -f <path> Path to Brewfile (show only packages from this Brewfile)\n")
|
||||
fmt.Fprintf(os.Stderr, " -v, --version Show version information\n")
|
||||
fmt.Fprintf(os.Stderr, " -h, --help Show this help message\n")
|
||||
fmt.Fprintf(os.Stderr, "\nExamples:\n")
|
||||
fmt.Fprintf(os.Stderr, " bbrew Launch the TUI with all packages\n")
|
||||
fmt.Fprintf(os.Stderr, " bbrew -f ~/Brewfile Launch with packages from Brewfile\n")
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
|
||||
// Handle --version flag (check both -v and --version)
|
||||
if *showVersion || isFlagPassed("version") {
|
||||
fmt.Printf("Bold Brew %s\n", services.AppVersion)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Validate Brewfile path if provided
|
||||
if *brewfilePath != "" {
|
||||
if _, err := os.Stat(*brewfilePath); os.IsNotExist(err) {
|
||||
|
|
@ -42,3 +64,14 @@ func main() {
|
|||
log.Fatalf("Application error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// isFlagPassed checks if a flag was explicitly passed on the command line.
|
||||
func isFlagPassed(name string) bool {
|
||||
found := false
|
||||
flag.Visit(func(f *flag.Flag) {
|
||||
if f.Name == name {
|
||||
found = true
|
||||
}
|
||||
})
|
||||
return found
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue