mirror of https://github.com/dapr/cli.git
Add 'build-info' command
This commit is contained in:
parent
a81262ae24
commit
c8770254a8
3
Makefile
3
Makefile
|
@ -83,7 +83,8 @@ BASE_PACKAGE_NAME := github.com/dapr/cli
|
|||
OUT_DIR := ./dist
|
||||
|
||||
BINS_OUT_DIR := $(OUT_DIR)/$(GOOS)_$(GOARCH)/$(BUILDTYPE_DIR)
|
||||
LDFLAGS := "-X main.version=$(CLI_VERSION) -X main.apiVersion=$(RUNTIME_API_VERSION)"
|
||||
LDFLAGS := "-X main.version=$(CLI_VERSION) -X main.apiVersion=$(RUNTIME_API_VERSION) \
|
||||
-X $(BASE_PACKAGE_NAME)/pkg/standalone.gitcommit=$(GIT_COMMIT) -X $(BASE_PACKAGE_NAME)/pkg/standalone.gitversion=$(GIT_VERSION)"
|
||||
|
||||
################################################################################
|
||||
# Target: build #
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation and Dapr Contributors.
|
||||
// Licensed under the MIT License.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/dapr/cli/pkg/standalone"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var BuildInfoCmd = &cobra.Command{
|
||||
Use: "build-info",
|
||||
Short: "Print build info of Dapr CLI and runtime",
|
||||
Example: `
|
||||
# Print build info
|
||||
dapr build-info
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println(standalone.GetBuildInfo(RootCmd.Version))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
BuildInfoCmd.Flags().BoolP("help", "h", false, "Print this help message")
|
||||
RootCmd.AddCommand(BuildInfoCmd)
|
||||
}
|
|
@ -5,7 +5,16 @@
|
|||
|
||||
package standalone
|
||||
|
||||
import "os/exec"
|
||||
import (
|
||||
"bufio"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Values for these are injected by the build.
|
||||
var (
|
||||
gitcommit, gitversion string
|
||||
)
|
||||
|
||||
// GetRuntimeVersion returns the version for the local Dapr runtime.
|
||||
func GetRuntimeVersion() string {
|
||||
|
@ -30,3 +39,32 @@ func GetDashboardVersion() string {
|
|||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// GetBuildInfo returns build info for the CLI and the local Dapr runtime.
|
||||
func GetBuildInfo(version string) string {
|
||||
daprBinDir := defaultDaprBinPath()
|
||||
daprCMD := binaryFilePath(daprBinDir, "daprd")
|
||||
|
||||
strs := []string{
|
||||
"CLI:",
|
||||
"\tVersion: " + version,
|
||||
"\tGit Commit: " + gitcommit,
|
||||
"\tGit Version: " + gitversion,
|
||||
"Runtime:",
|
||||
}
|
||||
|
||||
out, err := exec.Command(daprCMD, "--build-info").Output()
|
||||
if err != nil {
|
||||
// try '--version' for older runtime version
|
||||
out, err = exec.Command(daprCMD, "--version").Output()
|
||||
}
|
||||
if err != nil {
|
||||
strs = append(strs, "\tN/A")
|
||||
} else {
|
||||
scanner := bufio.NewScanner(strings.NewReader(string(out)))
|
||||
for scanner.Scan() {
|
||||
strs = append(strs, "\t"+scanner.Text())
|
||||
}
|
||||
}
|
||||
return strings.Join(strs, "\n")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue