You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.2 KiB

tags search
v2
boost
2

The default version flag (-v/--version) is defined as cli.VersionFlag, which is checked by the cli internals in order to print the App.Version via cli.VersionPrinter and break execution.

Customization

The default flag may be customized to something other than -v/--version by setting cli.VersionFlag, e.g.:

package main

import (
	"os"

	"github.com/urfave/cli/v2"
)

func main() {
	cli.VersionFlag = &cli.BoolFlag{
		Name:    "print-version",
		Aliases: []string{"V"},
		Usage:   "print only the version",
	}

	app := &cli.App{
		Name:    "partay",
		Version: "v19.99.0",
	}
	app.Run(os.Args)
}

Alternatively, the version printer at cli.VersionPrinter may be overridden, e.g.:

package main

import (
	"fmt"
	"os"

	"github.com/urfave/cli/v2"
)

var (
	Revision = "fafafaf"
)

func main() {
	cli.VersionPrinter = func(cCtx *cli.Context) {
		fmt.Printf("version=%s revision=%s\n", cCtx.App.Version, Revision)
	}

	app := &cli.App{
		Name:    "partay",
		Version: "v19.99.0",
	}
	app.Run(os.Args)
}