diff --git a/cmd/build_info.go b/cmd/build_info.go index 08425f4..f94e1db 100644 --- a/cmd/build_info.go +++ b/cmd/build_info.go @@ -6,8 +6,9 @@ import ( ) var ( - version = "dev" - commit = "none" + version = "dev" + commit = "none" + sdkVersion = "" ) // includes a leading newline to make it easy to read the ascii art here in the source @@ -20,17 +21,36 @@ const versionHeader = ` ` func init() { - if info, ok := debug.ReadBuildInfo(); ok && version == "dev" { - if info.Main.Version != "" && info.Main.Version != "(devel)" { - version = strings.TrimPrefix(info.Main.Version, "v") + if info, ok := debug.ReadBuildInfo(); ok { + if version == "dev" { + if info.Main.Version != "" && info.Main.Version != "(devel)" { + version = info.Main.Version + } + for _, s := range info.Settings { + if s.Key == "vcs.revision" && len(s.Value) >= 7 { + commit = s.Value[:7] + break + } + } } - for _, s := range info.Settings { - if s.Key == "vcs.revision" && len(s.Value) >= 7 { - commit = s.Value[:7] + for _, dep := range info.Deps { + if dep.Path == "github.com/loops-so/loops-go" { + sdkVersion = dep.Version break } } } header := strings.TrimPrefix(versionHeader, "\n") - rootCmd.SetVersionTemplate(header + "\n{{with .Name}}{{printf \"%s \" .}}{{end}}{{printf \"version %s\" .Version}}\n") + parts := []string{} + if commit != "" && commit != "none" { + parts = append(parts, "git "+commit) + } + if sdkVersion != "" { + parts = append(parts, "sdk "+sdkVersion) + } + suffix := "" + if len(parts) > 0 { + suffix = " (" + strings.Join(parts, ", ") + ")" + } + rootCmd.SetVersionTemplate(header + "\n{{with .Name}}{{printf \"%s \" .}}{{end}}{{printf \"version %s\" .Version}}" + suffix + "\n") } diff --git a/cmd/root.go b/cmd/root.go index 39fe8cf..d908833 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -75,7 +75,6 @@ func Execute() { context.Background(), rootCmd, fang.WithVersion(version), - fang.WithCommit(commit), fang.WithErrorHandler(jsonAwareErrorHandler), ) diff --git a/install.ps1 b/install.ps1 index 25bea4c..39a4464 100644 --- a/install.ps1 +++ b/install.ps1 @@ -50,7 +50,7 @@ $checksumsName = "${ProjName}_${versionNoV}_checksums.txt" $downloadUrl = "$GHAssetsUrl/$release/$archiveName" $checksumsUrl = "$GHAssetsUrl/$release/$checksumsName" -Write-Host "Installing $ProjName $release for windows/$Arch..." +Write-Host "Installing $ProjName $release for windows/$Arch... " -NoNewline $tmpDir = Join-Path $env:TEMP ([System.IO.Path]::GetRandomFileName()) New-Item -ItemType Directory -Path $tmpDir | Out-Null @@ -80,4 +80,8 @@ try { } Write-Host "Done!" +Write-Host "✓ " -ForegroundColor Green -NoNewline Write-Host "Installed to $InstallDir\$BinName" +& "$InstallDir\$BinName" --version +Write-Host "" +Write-Host 'Try `loops --help` to get started.' -ForegroundColor DarkGray diff --git a/install.sh b/install.sh index c75145d..14f69c9 100755 --- a/install.sh +++ b/install.sh @@ -244,7 +244,10 @@ execute() { rm -rf "$TMPDIR" } -echo "Installing ${PROJ_NAME} $GH_RELEASE for $OS $ARCH... " +printf "Installing %s %s for %s %s... " "$PROJ_NAME" "$GH_RELEASE" "$OS" "$ARCH" execute echo "Done!" -echo "Installed to ${INSTALL_DIR}/${SHORT_BIN_NAME}" +printf '\033[32m✓\033[0m Installed to %s\n' "${INSTALL_DIR}/${SHORT_BIN_NAME}" +"${INSTALL_DIR}/${SHORT_BIN_NAME}" --version +echo "" +printf '\033[2mTry `%s --help` to get started.\033[0m\n' "$SHORT_BIN_NAME"