-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use pversion to retrieve buildtime information
- Loading branch information
1 parent
35ad6a3
commit 4d6e361
Showing
14 changed files
with
369 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,61 @@ | ||
// Copyright 2020-2022 the Pinniped contributors. All Rights Reserved. | ||
// Copyright 2020-2023 the Pinniped contributors. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"k8s.io/component-base/version" | ||
"sigs.k8s.io/yaml" | ||
|
||
"go.pinniped.dev/internal/pversion" | ||
) | ||
|
||
//nolint:gochecknoinits | ||
func init() { | ||
rootCmd.AddCommand(newVersionCommand()) | ||
} | ||
|
||
//nolint:gochecknoglobals | ||
var ( | ||
output = new(string) | ||
// getBuildInfo can be overwritten by tests. | ||
getBuildInfo = pversion.Get | ||
) | ||
|
||
func newVersionCommand() *cobra.Command { | ||
return &cobra.Command{ | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
fmt.Fprintf(cmd.OutOrStdout(), "%#v\n", version.Get()) | ||
return nil | ||
}, | ||
c := &cobra.Command{ | ||
RunE: runner, | ||
Args: cobra.NoArgs, // do not accept positional arguments for this command | ||
Use: "version", | ||
Short: "Print the version of this Pinniped CLI", | ||
} | ||
c.Flags().StringVarP(output, "output", "o", "", "one of 'yaml' or 'json'") | ||
return c | ||
} | ||
|
||
func runner(cmd *cobra.Command, _ []string) error { | ||
buildVersion := getBuildInfo() | ||
|
||
switch { | ||
case output == nil || *output == "": | ||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s\n", buildVersion.GitVersion) | ||
case *output == "json": | ||
bytes, err := json.MarshalIndent(buildVersion, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s\n", bytes) | ||
case *output == "yaml": | ||
bytes, err := yaml.Marshal(buildVersion) | ||
if err != nil { | ||
return err | ||
} | ||
_, _ = fmt.Fprint(cmd.OutOrStdout(), string(bytes)) | ||
default: | ||
return fmt.Errorf("'%s' is not a valid option for output", *output) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2020 the Pinniped contributors. All Rights Reserved. | ||
# Copyright 2020-2023 the Pinniped contributors. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -euo pipefail | ||
|
||
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" | ||
|
||
KUBE_ROOT="${ROOT}" # required by `hack/lib/version.sh` | ||
source "${ROOT}/hack/lib/version.sh" | ||
|
||
kube::version::ldflags | ||
echo "-X 'go.pinniped.dev/internal/pversion.gitVersion=$KUBE_GIT_VERSION'" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.