Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ jobs:
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: latest
args: release --clean
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ builds:
# Default: Project directory name
binary: pingcli

# Custom ldflags.
#
# Default: '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser'.
# Templates: allowed.
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'

# GOOS list to build for.
# For more info refer to: https://golang.org/doc/install/source#environment
# Choices for $GOOS are android, darwin, dragonfly, freebsd, illumos, ios, js, linux, netbsd, openbsd, plan9, solaris, wasip1, and windows.
Expand Down
3 changes: 3 additions & 0 deletions cmd/request/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func TestRequestCmd_Execute(t *testing.T) {

for index, name := range re.SubexpNames() {
if name == captureGroupName {
if len(matchData) <= index {
t.Fatalf("Failed to capture JSON body: %v", matchData)
}
bodyJSON := matchData[index]

// Check for valid JSON
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func init() {
}

// rootCmd represents the base command when called without any subcommands
func NewRootCommand() *cobra.Command {
func NewRootCommand(version string, commit string) *cobra.Command {
cmd := &cobra.Command{
Long: "A CLI tool for managing the configuration of Ping Identity products.",
Short: "A CLI tool for managing the configuration of Ping Identity products.",
SilenceErrors: true, // Upon error in RunE method, let output package in main.go handle error output
Use: "pingcli",
Version: "v2.0.0-alpha.4",
Version: fmt.Sprintf("%s (commit: %s)", version, commit),
}

cmd.AddCommand(
Expand Down
4 changes: 2 additions & 2 deletions internal/testing/testutils_cobra/cobra_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func ExecutePingcli(t *testing.T, args ...string) (err error) {
// Reset options for testing individual executions of pingcli
configuration.InitAllOptions()

root := cmd.NewRootCommand()
root := cmd.NewRootCommand("test-version", "test-commit")

// Add config location to the root command
configFilepath := testutils_viper.CreateConfigFile(t)
Expand All @@ -36,7 +36,7 @@ func ExecutePingcli(t *testing.T, args ...string) (err error) {
func ExecutePingcliCaptureCobraOutput(t *testing.T, args ...string) (output string, err error) {
t.Helper()

root := cmd.NewRootCommand()
root := cmd.NewRootCommand("test-version", "test-commit")

// Add config location to the root command
configFilepath := testutils_viper.CreateConfigFile(t)
Expand Down
23 changes: 22 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
package main

import (
"runtime/debug"

"github.com/pingidentity/pingcli/cmd"
"github.com/pingidentity/pingcli/internal/output"
)

var (
// these will be set by the goreleaser configuration
// to appropriate values for the compiled binary
version string = "dev"
commit string = "dev"
)

func main() {
rootCmd := cmd.NewRootCommand()
// Try to get the commit hash from the build info if it wasn't set by goreleaser
if commit == "dev" {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
commit = setting.Value
break
}
}
}
}

rootCmd := cmd.NewRootCommand(version, commit)

err := rootCmd.Execute()
if err != nil {
Expand Down