Add new TASK_VERSION special variable

Closes #1014
Closes #990
This commit is contained in:
João Pedro
2023-02-19 22:28:17 -03:00
committed by Andrey Nering
parent 12a1cd6f62
commit ec2110e58f
10 changed files with 45 additions and 28 deletions

View File

@@ -6,7 +6,6 @@ import (
"log"
"os"
"path/filepath"
"runtime/debug"
"strings"
"time"
@@ -16,13 +15,10 @@ import (
"github.com/go-task/task/v3"
"github.com/go-task/task/v3/args"
"github.com/go-task/task/v3/internal/logger"
ver "github.com/go-task/task/v3/internal/version"
"github.com/go-task/task/v3/taskfile"
)
var (
version = ""
)
const usage = `Usage: task [-ilfwvsd] [--init] [--list] [--force] [--watch] [--verbose] [--silent] [--dir] [--taskfile] [--dry] [--summary] [task...]
Runs the specified task(s). Falls back to the "default" task if no task name
@@ -104,7 +100,7 @@ func main() {
pflag.Parse()
if versionFlag {
fmt.Printf("Task version: %s\n", getVersion())
fmt.Printf("Task version: %s\n", ver.GetVersion())
return
}
@@ -255,21 +251,3 @@ func getArgs() ([]string, string, error) {
}
return args[:doubleDashPos], strings.Join(quotedCliArgs, " "), nil
}
func getVersion() string {
if version != "" {
return version
}
info, ok := debug.ReadBuildInfo()
if !ok || info.Main.Version == "" {
return "unknown"
}
version = info.Main.Version
if info.Main.Sum != "" {
version += fmt.Sprintf(" (%s)", info.Main.Sum)
}
return version
}