From 92535a2a9c038e3e9ad4a73500e95682e32b7869 Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 22 May 2024 19:11:54 +0900 Subject: [PATCH] prefer document URL at specific version tag --- command.go | 18 ++++++++++++++---- playground/index.html | 2 +- scripts/bump-version.bash | 5 ++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/command.go b/command.go index ffac07831..6587b9cc1 100644 --- a/command.go +++ b/command.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "io" + "regexp" "runtime" "runtime/debug" ) @@ -25,7 +26,14 @@ const ( ExitStatusFailure = 3 ) -const commandUsageHeader = `Usage: actionlint [FLAGS] [FILES...] [-] +func printUsageHeader(out io.Writer) { + v := getCommandVersion() + b := "main" + if regexp.MustCompile(`^\d+\.\d+\.\d+$`).MatchString(v) { + b = "v" + v + } + + fmt.Fprintf(out, `Usage: actionlint [FLAGS] [FILES...] [-] actionlint is a linter for GitHub Actions workflow files. @@ -50,9 +58,11 @@ const commandUsageHeader = `Usage: actionlint [FLAGS] [FILES...] [-] Documents: - https://github.com/rhysd/actionlint/tree/main/docs + https://github.com/rhysd/actionlint/tree/%s/docs -Flags:` +Flags: +`, b) +} func getCommandVersion() string { if version != "" { @@ -143,7 +153,7 @@ func (cmd *Command) Main(args []string) int { flags.BoolVar(&ver, "version", false, "Show version and how this binary was installed") flags.StringVar(&opts.StdinFileName, "stdin-filename", "", "File name when reading input from stdin") flags.Usage = func() { - fmt.Fprintln(cmd.Stderr, commandUsageHeader) + printUsageHeader(cmd.Stderr) flags.PrintDefaults() } if err := flags.Parse(args[1:]); err != nil { diff --git a/playground/index.html b/playground/index.html index 9826ad9a2..ab72957fd 100644 --- a/playground/index.html +++ b/playground/index.html @@ -60,7 +60,7 @@

Static checker for GitHub Actions workflow files

Resources