diff --git a/.changes/unreleased/Fixed-20240424-080940.yaml b/.changes/unreleased/Fixed-20240424-080940.yaml new file mode 100644 index 0000000..83fd089 --- /dev/null +++ b/.changes/unreleased/Fixed-20240424-080940.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: unset command is now aware of both stack names and aliases +time: 2024-04-24T08:09:40.430361307-05:00 +custom: + Author: Shackelford-Arden diff --git a/.github/workflows/prs.yml b/.github/workflows/prs.yml new file mode 100644 index 0000000..06c1653 --- /dev/null +++ b/.github/workflows/prs.yml @@ -0,0 +1,26 @@ +name: pr-checks + +on: + pull_request: + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - uses: dominikh/staticcheck-action@v1 + with: + version: "latest" + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + check-latest: true + - run: go test -cover ./... \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c619302..7ad8060 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,6 @@ name: goreleaser on: - pull_request: push: # run only against tags tags: diff --git a/cmd/config.go b/cmd/config.go deleted file mode 100644 index 1d619dd..0000000 --- a/cmd/config.go +++ /dev/null @@ -1 +0,0 @@ -package cmd diff --git a/cmd/unset_test.go b/cmd/unset_test.go deleted file mode 100644 index 3765551..0000000 --- a/cmd/unset_test.go +++ /dev/null @@ -1,8 +0,0 @@ -package cmd - -import "testing" - -func TestUnsetWhenNoStack(t *testing.T) { - - // -} diff --git a/go.mod b/go.mod index 0321e7a..1cb271e 100644 --- a/go.mod +++ b/go.mod @@ -3,18 +3,22 @@ module github.com/Shackelford-Arden/hctx go 1.21 require ( - github.com/hashicorp/hcl/v2 v2.19.1 + github.com/hashicorp/hcl/v2 v2.20.1 github.com/urfave/cli/v2 v2.27.1 ) require ( github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect - github.com/zclconf/go-cty v1.14.2 // indirect + github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect + github.com/zclconf/go-cty v1.14.4 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.20.0 // indirect ) diff --git a/go.sum b/go.sum index 8fd549c..07fb00f 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= @@ -12,6 +14,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI= github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= +github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc= +github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= @@ -28,7 +32,19 @@ github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e h1:+SOyEddqYF09QP7vr7CgJ1eti3pY9Fn3LHO1M1r/0sI= github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw= +github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk= github.com/zclconf/go-cty v1.14.2 h1:kTG7lqmBou0Zkx35r6HJHUQTvaRPr5bIAf3AoHS0izI= github.com/zclconf/go-cty v1.14.2/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= +github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= +golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg= diff --git a/models/config.go b/models/config.go index 04501da..ea30866 100644 --- a/models/config.go +++ b/models/config.go @@ -121,6 +121,7 @@ func (c *Config) Map() map[string]Stack { for _, stack := range c.Stacks { stacks[stack.Name] = stack + stacks[stack.Alias] = stack } return stacks diff --git a/models/config_test.go b/models/config_test.go index 3bbf97d..1ab2c37 100644 --- a/models/config_test.go +++ b/models/config_test.go @@ -96,3 +96,41 @@ unset %s`, } // endregion + +func TestStackExistsUsingStackName(t *testing.T) { + + // Create test stack + stack := Stack{ + Name: "test-stack", + Alias: "Test Stack", + } + + testConfig := Config{ + Stacks: []Stack{stack}, + } + + existingStack := testConfig.StackExists("test-stack") + + if existingStack == nil { + t.Fatalf("Expected stack to exist, but it does not.") + } +} + +func TestStackExistsUsingAlias(t *testing.T) { + + // Create test stack + stack := Stack{ + Name: "test-stack", + Alias: "Test Stack", + } + + testConfig := Config{ + Stacks: []Stack{stack}, + } + + existingStack := testConfig.StackExists("Test Stack") + + if existingStack == nil { + t.Fatalf("Expected stack to exist, but it does not.") + } +} diff --git a/models/utils.go b/models/utils.go index fec9631..01d9932 100644 --- a/models/utils.go +++ b/models/utils.go @@ -15,7 +15,7 @@ func genUseCommands(shell string, varName string, varValue string) string { envCmd = fmt.Sprintf("export %s=%s", varName, varValue) } - return fmt.Sprintf("%s", envCmd) + return envCmd }