Skip to content

Commit

Permalink
Merge branch 'main' of github.com:terramate-io/terramate into i4k-fix…
Browse files Browse the repository at this point in the history
…-tg-panic

Signed-off-by: i4k <[email protected]>
  • Loading branch information
i4ki committed Nov 29, 2024
2 parents b8dee41 + 607852d commit 8f7080c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 54 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Given a version number `MAJOR.MINOR.PATCH`, we increment the:

## Fixed

- Fix the command-line parsing of `run` and `script run` which were not failing from unknown flags.
- Panic in the Terragrunt integration when the project had modules with dependency paths outside the current Terramate project.
- Now Terramate throw a warning for such configurations.

Expand Down
41 changes: 20 additions & 21 deletions cmd/terramate/cli/cli_flags_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import (
const (
defaultIndent = 2
defaultColumnPadding = 4

// negatableDefault is a placeholder value for the Negatable tag to indicate
// the negated flag is --no-<flag-name>. This is needed as at the time of
// parsing a tag, the field's flag name is not yet known.
negatableDefault = "_"
)

// terramateHelpPrinter is the default HelpPrinter.
Expand Down Expand Up @@ -310,24 +305,28 @@ func formatFlag(haveShort bool, flag *kong.Flag) string {
flagString := ""
name := flag.Name
isBool := flag.IsBool()
isCounter := flag.IsCounter()

short := ""
if flag.Short != 0 {
short = "-" + string(flag.Short) + ", "
} else if haveShort {
short = " "
}

if isBool && flag.Tag.Negatable == negatableDefault {
name = "[no-]" + name
} else if isBool && flag.Tag.Negatable != "" {
name += "/" + flag.Tag.Negatable
if isBool && flag.Tag.Negatable {
flagString += fmt.Sprintf("-%c, --[no-]%s", flag.Short, name)
} else {
flagString += fmt.Sprintf("-%c, --%s", flag.Short, name)
}
} else {
if isBool && flag.Tag.Negatable {
if haveShort {
flagString = fmt.Sprintf(" --[no-]%s", name)
} else {
flagString = fmt.Sprintf("--[no-]%s", name)
}
} else {
if haveShort {
flagString += fmt.Sprintf(" --%s", name)
} else {
flagString += fmt.Sprintf("--%s", name)
}
}
}

flagString += fmt.Sprintf("%s--%s", short, name)

if !isBool && !isCounter {
if !isBool {
flagString += fmt.Sprintf("=%s", flag.FormatPlaceHolder())
}
return flagString
Expand Down
6 changes: 0 additions & 6 deletions cmd/terramate/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ func selectPlanFile(terraformPlan, tofuPlan string) (planfile, provisioner strin
func (c *cli) runOnStacks() {
c.gitSafeguardDefaultBranchIsReachable()

if len(c.parsedArgs.Run.Command) > 0 {
if c.parsedArgs.Run.Command[0] == "--" {
c.parsedArgs.Run.Command = c.parsedArgs.Run.Command[1:]
}
}

if len(c.parsedArgs.Run.Command) == 0 {
fatal("run expects a cmd")
}
Expand Down
10 changes: 0 additions & 10 deletions cmd/terramate/cli/script_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ import (
)

func (c *cli) printScriptInfo() {
if len(c.parsedArgs.Script.Info.Cmds) > 0 {
if c.parsedArgs.Script.Info.Cmds[0] == "--" {
c.parsedArgs.Script.Info.Cmds = c.parsedArgs.Script.Info.Cmds[1:]
}
}

if len(c.parsedArgs.Script.Info.Cmds) == 0 {
fatal("script info expects cmds")
}

labels := c.parsedArgs.Script.Info.Cmds

stacks, err := c.computeSelectedStacks(false, cloudstack.AnyTarget, cloud.NoStatusFilters())
Expand Down
10 changes: 0 additions & 10 deletions cmd/terramate/cli/script_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ func (c *cli) runScript() {
c.gitSafeguardDefaultBranchIsReachable()
c.checkOutdatedGeneratedCode()

if len(c.parsedArgs.Script.Run.Cmds) > 0 {
if c.parsedArgs.Script.Run.Cmds[0] == "--" {
c.parsedArgs.Script.Run.Cmds = c.parsedArgs.Script.Run.Cmds[1:]
}
}

if len(c.parsedArgs.Script.Run.Cmds) == 0 {
fatal("script run expects cmds")
}

c.checkTargetsConfiguration(c.parsedArgs.Script.Run.Target, c.parsedArgs.Script.Run.FromTarget, func(isTargetSet bool) {
if !isTargetSet {
// We don't check here if any script has any sync command options enabled.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21.0
toolchain go1.22.3

require (
github.com/alecthomas/kong v1.4.0
github.com/alecthomas/kong v0.7.1
github.com/apparentlymart/go-versions v1.0.2
github.com/cli/go-gh/v2 v2.11.1
github.com/cli/safeexec v1.0.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
github.com/alecthomas/assert/v2 v2.1.0/go.mod h1:b/+1DI2Q6NckYi+3mXyH3wFb8qG37K/DuK80n7WefXA=
github.com/alecthomas/kong v0.2.2/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE=
github.com/alecthomas/kong v1.4.0 h1:UL7tzGMnnY0YRMMvJyITIRX1EpO6RbBRZDNcCevy3HA=
github.com/alecthomas/kong v1.4.0/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4=
github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
github.com/alecthomas/repr v0.1.0/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190329064014-6e358769c32a/go.mod h1:T9M45xf79ahXVelWoOBmH0y4aC1t5kXO5BxwyakgIGA=
Expand Down

0 comments on commit 8f7080c

Please sign in to comment.