From 088b7736043b05813adeaff1bf2a3c9fac3d628d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 17 Dec 2024 15:05:57 +0100 Subject: [PATCH] Send the version to stderr Until https://tip.golang.org/doc/modules/managing-dependencies#tools is available to me, I have a shell script that detects the version of swag by invoking swag --version and parsing its output, then updates if I'm not using the version specified in the script. With v2, the output looks like this Swag version: v2.0.0 swag version v2.0.0 While it might be useful to have the swag version always printed for troubleshooting purposes, I think it should be printed to stderr so as not to mess up output that is supposed to be parsed. This change will result in the first line to be sent to stderr, making it backward-compatible with the previous output of swag --version while still retaining the improvement of having it printed for every command. --- cmd/swag/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/swag/main.go b/cmd/swag/main.go index 238b25c36..46cecf14d 100644 --- a/cmd/swag/main.go +++ b/cmd/swag/main.go @@ -279,7 +279,7 @@ func initAction(ctx *cli.Context) error { } func main() { - fmt.Println("Swag version:", swag.Version) + fmt.Fprintln(os.Stderr, "Swag version:", swag.Version) app := cli.NewApp() app.Version = swag.Version app.Usage = "Automatically generate RESTful API documentation with Swagger 2.0 for Go."