Add version flag insteaf of subcommand (#1639)

This commit is contained in:
Sven van Ginkel
2026-02-06 02:36:57 +01:00
committed by GitHub
parent 8347afd68e
commit 221be1da58

View File

@@ -31,9 +31,6 @@ func (opts *cmdOptions) parse() bool {
// Subcommands that don't require any pflag parsing // Subcommands that don't require any pflag parsing
switch subcommand { switch subcommand {
case "-v", "version":
fmt.Println(beszel.AppName+"-agent", beszel.Version)
return true
case "health": case "health":
err := health.Check() err := health.Check()
if err != nil { if err != nil {
@@ -49,6 +46,7 @@ func (opts *cmdOptions) parse() bool {
pflag.StringVarP(&opts.hubURL, "url", "u", "", "URL of the Beszel hub") pflag.StringVarP(&opts.hubURL, "url", "u", "", "URL of the Beszel hub")
pflag.StringVarP(&opts.token, "token", "t", "", "Token to use for authentication") pflag.StringVarP(&opts.token, "token", "t", "", "Token to use for authentication")
chinaMirrors := pflag.BoolP("china-mirrors", "c", false, "Use mirror for update (gh.beszel.dev) instead of GitHub") chinaMirrors := pflag.BoolP("china-mirrors", "c", false, "Use mirror for update (gh.beszel.dev) instead of GitHub")
version := pflag.BoolP("version", "v", false, "Show version information")
help := pflag.BoolP("help", "h", false, "Show this help message") help := pflag.BoolP("help", "h", false, "Show this help message")
// Convert old single-dash long flags to double-dash for backward compatibility // Convert old single-dash long flags to double-dash for backward compatibility
@@ -86,6 +84,9 @@ func (opts *cmdOptions) parse() bool {
// Must run after pflag.Parse() // Must run after pflag.Parse()
switch { switch {
case *version:
fmt.Println(beszel.AppName+"-agent", beszel.Version)
return true
case *help || subcommand == "help": case *help || subcommand == "help":
pflag.Usage() pflag.Usage()
return true return true