Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add version command to the binary #74

Merged
merged 3 commits into from
May 24, 2024
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: 0 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ builds:
- -trimpath
env:
- CGO_ENABLED=0
ldflags:
- -s -w
goos:
- linux
- darwin
Expand Down
27 changes: 27 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var Version = "v0.0.0-dev"

// versionCmd is root for various `generate ...` commands.
var versionCmd = &cobra.Command{
Use: "version",
Short: "Return the current version.",
RunE: runVersion,
}

func init() {
rootCmd.AddCommand(versionCmd)
}

func runVersion(_ *cobra.Command, _ []string) error {
_, err := fmt.Fprintln(os.Stdout, Version)

return err
}
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import (
"github.com/Skarlso/crd-to-sample-yaml/cmd"
)

// version is set during build time by GoReleaser.
var version string

func main() {
if version != "" {
cmd.Version = version
}

if err := cmd.Execute(); err != nil {
log.Fatal("failed to run command: ", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

const array = "array"

var RootRequiredFields = []string{"apiVersion", "kind", "spec"}
var RootRequiredFields = []string{"apiVersion", "kind", "spec", "metadata"}

// Generate takes a CRD content and path, and outputs.
func Generate(crd *v1beta1.CustomResourceDefinition, w io.WriteCloser, enableComments, minimal bool) (err error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/testdata/sample_crd_with_minimal_example_golden.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apiVersion: delivery.krok.app/v1alpha1
kind: KrokCommand
metadata: {}
spec:
image: string
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apiVersion: delivery.krok.app/v1alpha1
kind: KrokCommand
metadata: {}
spec:
image: "krok-hook/slack-notification:v0.0.1"
22 changes: 22 additions & 0 deletions sample-crd/krokcommands.delivery.krok.app_sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ <h1>
apiVersion: delivery.krok.app/v1alpha1
# Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
kind: KrokCommand
metadata: {}
# KrokCommandSpec defines the desired state of KrokCommand
spec:
# Image defines the image name and tag of the command example: krok-hook/slack-notification:v0.0.1
Expand Down Expand Up @@ -114,6 +115,27 @@ <h1>



</div>
<br>
</details>

<details class="collapse-panel">
<summary class="collapse-header position-relative">
metadata <kbd class="text-muted">object</kbd>




<span class="badge badge-primary">required</span>

</summary>
<div id="metadata" class="collapse-content">
<div class="property-description">
<p></p>
</div>



</div>
<br>
</details>
Expand Down