Skip to content

Commit

Permalink
✨ add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
plusiv committed Jun 11, 2024
1 parent 1a87665 commit 27b9ed9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ jobs:
goarch: [amd64, arm64]
steps:
- uses: actions/checkout@v4
- uses: wangyoucao577/go-release-action@v1
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
- name: Get module name
id: module_name
run: |
echo "module_name=$(go list -m)" >> $GITHUB_OUTPUT
- name: Build and Release app
uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "1.22.4"
ldflags: -X "${{ steps.module_name.outputs.module_name }}.cmd.Version=${{ github.event.release.tag_name }}"
extra_files: LICENSE README.md
7 changes: 5 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
LongDescription string = `kubectl-envsecret is a plugin for kubectl that simplifies the process of creating Kubernetes secrets from .env files, including support for multiline environment variables.
This tool reads the .env file, converts its contents into Kubernetes secret format, and applies it to your cluster. It streamlines the management of secrets, making it easier to handle configurations that include multiline values.`
AppVersion string = "undefined"
)

// NewCmdEnvSecret creates a new cobra command for the kubectl-envsecret plugin.
Expand All @@ -55,8 +56,9 @@ func NewCmdEnvSecret(streams genericiooptions.IOStreams) *cobra.Command {
Annotations: map[string]string{
cobra.CommandDisplayNameAnnotation: DisplayName,
},
Short: ShortDescription,
Long: LongDescription,
Short: ShortDescription,
Long: LongDescription,
Version: AppVersion,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
Expand All @@ -71,6 +73,7 @@ func NewCmdEnvSecret(streams genericiooptions.IOStreams) *cobra.Command {

// create subcommands
cmd.AddCommand(NewCmdCreate(streams))
cmd.AddCommand(NewCmdVersion(streams))

return cmd
}
47 changes: 47 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericiooptions"
)

// VersionOptions contains the options for the version command.
type VersionOptions struct {
genericiooptions.IOStreams // Input/output streams for the CLI.
version string
}

// NewVersionOptions initializes VersionOptions with the provided IO streams.
//
// Example usage:
// streams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}
// options := NewVersionOptions(streams)
func NewVersionOptions(streams genericiooptions.IOStreams) *VersionOptions {
return &VersionOptions{
version: AppVersion,
IOStreams: streams,
}
}

// NewCmdCreate creates a new cobra command for printing kubectl-envsecret version.
//
// Example usage:
// streams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}
// cmd := NewCmdVersion(streams)
// cmd.Execute()
func NewCmdVersion(streams genericiooptions.IOStreams) *cobra.Command {
// versionCmd represents the version command
versionCmd := &cobra.Command{
Use: "version",
Short: "Print kubectl-envsecret version.",
Long: "Print kubectl-envsecret version.",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println(AppVersion)
return nil
},
}

return versionCmd
}

0 comments on commit 27b9ed9

Please sign in to comment.