diff --git a/main.go b/main.go index 978cca47..b835e9b3 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/hcp/internal/pkg/format" "github.com/hashicorp/hcp/internal/pkg/iostreams" "github.com/hashicorp/hcp/internal/pkg/profile" + "github.com/hashicorp/hcp/version" "github.com/mitchellh/cli" "github.com/posener/complete" ) @@ -104,7 +105,12 @@ func realMain() int { return 1 } - hcpClient, err := httpclient.New(httpclient.Config{HCPConfig: hcpCfg}) + hconfig := httpclient.Config{ + HCPConfig: hcpCfg, + SourceChannel: getSourceChannel(), + } + + hcpClient, err := httpclient.New(hconfig) if err != nil { fmt.Fprintf(io.Err(), "failed to create HCP API client: %v\n", err) return 1 @@ -143,3 +149,8 @@ func realMain() int { return status } + +// getSourceChannel returns the source channel for the CLI +func getSourceChannel() string { + return fmt.Sprintf("hcp-cli/%s", version.FullVersion()) +} diff --git a/version/version.go b/version/version.go index 20965898..14359acf 100644 --- a/version/version.go +++ b/version/version.go @@ -17,7 +17,7 @@ var ( //go:embed VERSION fullVersion string - Version, VersionPrerelease, _ = strings.Cut(strings.TrimSpace(fullVersion), "-") + Version, VersionPrerelease, _ = strings.Cut(FullVersion(), "-") VersionMetadata = "" ) @@ -52,3 +52,8 @@ func GetHumanVersion() string { return version } + +// FullVersion returns the full version string including any prerelease tags. +func FullVersion() string { + return strings.TrimSpace(fullVersion) +}