Backport of Handle `-help` usage in stacks plugin into v1.14 (#37655)

* backport of commit 10f00d437f

* backport of commit 7f0ef4c8d0

---------

Co-authored-by: Mark DeCrane <mark.decrane@hashicorp.com>
pull/37668/head
github-actions[bot] 7 months ago committed by GitHub
parent d080ec6054
commit 2434b319b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
kind: ENHANCEMENTS
body: '`terraform stacks` command support for `-help` flag'
time: 2025-09-19T11:52:53.923764-04:00
custom:
Issue: "37645"

@ -82,7 +82,6 @@ func (c *StacksCommand) realRun(args []string, stdout, stderr io.Writer) int {
args = c.Meta.process(args)
cmdFlags := c.Meta.defaultFlagSet("stacks")
cmdFlags.StringVar(&pluginCacheDirOverride, "plugin-cache-dir", "", "plugin cache directory")
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
cmdFlags.Parse(args)
if pluginCacheDirOverride != "" {
@ -379,8 +378,17 @@ func (c *StacksCommand) Run(args []string) int {
// Help returns help text for the stacks command.
func (c *StacksCommand) Help() string {
helpText := new(bytes.Buffer)
if exitCode := c.realRun([]string{}, helpText, io.Discard); exitCode != 0 {
return ""
errorText := new(bytes.Buffer)
parsedArgs := []string{}
for _, arg := range os.Args[1:] {
if arg == "stacks" {
continue // skip stacks command name
}
parsedArgs = append(parsedArgs, arg)
}
if exitCode := c.realRun(parsedArgs, helpText, errorText); exitCode != 0 {
return errorText.String()
}
return helpText.String()

Loading…
Cancel
Save