Skip to content

Commit fb6adc5

Browse files
authored
Fix non-deterministic do help output (#23328)
Without these sorts the help text could re-order and then trigger test failures.
1 parent 896304f commit fb6adc5

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎pkg/cmd/pulumi/do/do.go‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525

2626
"github.com/google/shlex"
27+
"github.com/pgavlin/fx/v2/maps"
2728
"github.com/spf13/cobra"
2829
"github.com/spf13/pflag"
2930

@@ -501,22 +502,22 @@ func (pc *packageCommand) newPackageCommand() *cobra.Command {
501502
var help strings.Builder
502503
if len(modules) > 0 {
503504
fmt.Fprintln(&help, "Modules:")
504-
for mod := range modules {
505+
for mod := range maps.Sorted(modules) {
505506
fmt.Fprintf(&help, " %s\n", mod)
506507
}
507508
fmt.Fprintln(&help, "")
508509
}
509510
if len(functions) > 0 {
510511
fmt.Fprintln(&help, "Functions:")
511-
for _, fn := range functions {
512+
for _, fn := range maps.Sorted(functions) {
512513
tok := pc.spec.CanonicalizeToken(fn.Token)
513514
fmt.Fprintf(&help, " %s\n", tok)
514515
}
515516
fmt.Fprintln(&help, "")
516517
}
517518
if len(resources) > 0 {
518519
fmt.Fprintln(&help, "Resources:")
519-
for _, res := range resources {
520+
for _, res := range maps.Sorted(resources) {
520521
tok := pc.spec.CanonicalizeToken(res.Token)
521522
fmt.Fprintf(&help, " %s\n", tok)
522523
}
@@ -590,22 +591,22 @@ func (pc *packageCommand) newModuleCommand() *cobra.Command {
590591
var help strings.Builder
591592
if len(modules) > 0 {
592593
fmt.Fprintln(&help, "Modules:")
593-
for mod := range modules {
594+
for mod := range maps.Sorted(modules) {
594595
fmt.Fprintf(&help, " %s\n", mod)
595596
}
596597
fmt.Fprintln(&help, "")
597598
}
598599
if len(functions) > 0 {
599600
fmt.Fprintln(&help, "Functions:")
600-
for _, fn := range functions {
601+
for _, fn := range maps.Sorted(functions) {
601602
tok := pc.spec.CanonicalizeToken(fn.Token)
602603
fmt.Fprintf(&help, " %s\n", tok)
603604
}
604605
fmt.Fprintln(&help, "")
605606
}
606607
if len(resources) > 0 {
607608
fmt.Fprintln(&help, "Resources:")
608-
for _, res := range resources {
609+
for _, res := range maps.Sorted(resources) {
609610
tok := pc.spec.CanonicalizeToken(res.Token)
610611
fmt.Fprintf(&help, " %s\n", tok)
611612
}

0 commit comments

Comments
 (0)