Skip to content

Commit

Permalink
version - add version flag, modify goreleaser config
Browse files Browse the repository at this point in the history
  • Loading branch information
hashmap-kz committed Jan 8, 2025
1 parent 6bf1225 commit 1a2b259
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ builds:
- id: kubectl-envsubst
main: ./cmd/kubectl-envsubst.go
binary: kubectl-envsubst
ldflags:
- -s -w
- -X github.com/hashmap-kz/kubectl-envsubst/pkg/version.Version={{.Version}}
env:
- CGO_ENABLED=0
goos:
Expand Down
17 changes: 15 additions & 2 deletions cmd/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/hashmap-kz/kubectl-envsubst/pkg/cmd"
"github.com/hashmap-kz/kubectl-envsubst/pkg/version"
)

// runApp executes the plugin, with logic divided into smaller, testable components
Expand All @@ -18,8 +19,20 @@ func RunApp() error {
return err
}

// either help message, either 'apply' was not provided
if flags.Help || len(flags.Others) == 0 {
// show help message
if flags.Help {
fmt.Println(cmd.UsageMessage)
return nil
}

// show version
if flags.Version {
fmt.Println(version.Version)
return nil
}

// 'apply' was not provided
if len(flags.Others) == 0 {
fmt.Println(cmd.UsageMessage)
return nil
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/rawargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ArgsRawRecognized struct {
Help bool
Others []string
HasStdin bool
Version bool
}

func allEmpty(values []string) bool {
Expand Down Expand Up @@ -93,13 +94,17 @@ func ParseArgs() (ArgsRawRecognized, error) {
result.EnvsubstAllowedPrefix = append(result.EnvsubstAllowedPrefix, list...)
i++ // Skip the next argument

// Handle recursive and help flags
// Handle boolean flags

case arg == "--recursive" || arg == "-R":
result.Recursive = true

case arg == "--help" || arg == "-h":
result.Help = true

case arg == "--version":
result.Version = true

// Handle unrecognized arguments
default:
result.Others = append(result.Others, arg)
Expand Down
10 changes: 10 additions & 0 deletions pkg/cmd/rawargs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ func TestParseArgs(t *testing.T) {
},
expectedError: false,
},
{
name: "Valid args with unrecognized argument that looks like a short flag (3)",
args: []string{"-h", "-xyz", "--version"},
expectedResult: ArgsRawRecognized{
Help: true,
Version: true,
Others: []string{"-xyz"},
},
expectedError: false,
},
}

for _, tc := range cases {
Expand Down
4 changes: 4 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package version

// Version holds the current version of kubectl-envsubst plugin.
var Version = "dev"

0 comments on commit 1a2b259

Please sign in to comment.