Skip to content

Commit f8b0051

Browse files
authored
Merge pull request #37645 from hashicorp/handle-help-usage-stacks-plugin
Handle `-help` usage in stacks plugin
2 parents e65c562 + 7f0ef4c commit f8b0051

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: ENHANCEMENTS
2+
body: '`terraform stacks` command support for `-help` flag'
3+
time: 2025-09-19T11:52:53.923764-04:00
4+
custom:
5+
Issue: "37645"

internal/command/stacks.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ func (c *StacksCommand) realRun(args []string, stdout, stderr io.Writer) int {
8282
args = c.Meta.process(args)
8383
cmdFlags := c.Meta.defaultFlagSet("stacks")
8484
cmdFlags.StringVar(&pluginCacheDirOverride, "plugin-cache-dir", "", "plugin cache directory")
85-
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
8685
cmdFlags.Parse(args)
8786

8887
if pluginCacheDirOverride != "" {
@@ -379,8 +378,17 @@ func (c *StacksCommand) Run(args []string) int {
379378
// Help returns help text for the stacks command.
380379
func (c *StacksCommand) Help() string {
381380
helpText := new(bytes.Buffer)
382-
if exitCode := c.realRun([]string{}, helpText, io.Discard); exitCode != 0 {
383-
return ""
381+
errorText := new(bytes.Buffer)
382+
383+
parsedArgs := []string{}
384+
for _, arg := range os.Args[1:] {
385+
if arg == "stacks" {
386+
continue // skip stacks command name
387+
}
388+
parsedArgs = append(parsedArgs, arg)
389+
}
390+
if exitCode := c.realRun(parsedArgs, helpText, errorText); exitCode != 0 {
391+
return errorText.String()
384392
}
385393

386394
return helpText.String()

0 commit comments

Comments
 (0)