Visitar URL original
fix usage string for `pulumi do` (#23325) · pulumi/pulumi@21ce979 · GitHub
Skip to content

Commit 21ce979

Browse files
authored
fix usage string for pulumi do (#23325)
Currently when I run e.g. `pulumi do aws:lambda:Function`, the usage string ends up being `pulumi Function`. This isn't correct, and can be confusing. Fix this to show the full usage string as the command was typed, so it can be copy-pasted. As an additional (good) side effect, this also removes the `help` and `completion` commands from the "Available Commands" output, which is correct as they aren't actually available at this level.
1 parent bd45130 commit 21ce979

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ func NewDoCmd(
237237
dryrun: dryrun,
238238
showSecrets: showSecrets,
239239
}).newCommand()
240+
// Replace the short name in Use with the full token so the usage
241+
// string shows e.g. "pulumi do aws:s3:Bucket" instead of "pulumi do Bucket".
242+
if len(pargs) > 0 {
243+
subcmd.Use = pargs[0] + strings.TrimPrefix(subcmd.Use, subcmd.Name())
244+
}
245+
240246
subcmd.SetContext(cmd.Context())
241247
subcmd.SetOut(cmd.OutOrStdout())
242248
subcmd.SetErr(cmd.ErrOrStderr())
@@ -271,8 +277,19 @@ func NewDoCmd(
271277
subcmd.PersistentFlags().AddFlag(f)
272278
}
273279
})
280+
// Insert a fake "do" node so the command path reads "pulumi do <token>"
281+
// instead of "pulumi <token>". Don't copy flags here — they're already
282+
// on subcmd from the copy above.
283+
fakeDo := &cobra.Command{Use: cmd.Use}
284+
fakeDo.SetContext(cmd.Context())
285+
fakeDo.SetOut(cmd.OutOrStdout())
286+
fakeDo.SetErr(cmd.ErrOrStderr())
287+
fakeDo.SetIn(cmd.InOrStdin())
288+
fakeDo.AddCommand(subcmd)
289+
fullArgs = append([]string{subcmd.Name()}, fullArgs...)
290+
274291
parent := cmd.Parent()
275-
current := subcmd
292+
current := fakeDo
276293
for parent != nil {
277294
nextParent := &cobra.Command{
278295
Use: parent.Use,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Outputs:
126126
output3 (boolean, required) - Whether it worked.
127127
128128
Usage:
129-
myOtherFunction [flags]
129+
do azure:myModule:myOtherFunction [flags]
130130
131131
Flags:
132132
--dry-run Run the operation in preview mode

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,12 @@ List Inputs:
118118
prefix (string, optional)
119119
120120
Usage:
121-
myResource [flags]
122-
myResource [command]
121+
do azure:index:myResource [flags]
122+
do azure:index:myResource [command]
123123
124124
Available Commands:
125-
completion Generate the autocompletion script for the specified shell
126125
create Create a resource
127126
delete Delete a resource
128-
help Help about any command
129127
list List resources
130128
patch Patch a resource
131129
read Read a resource
@@ -138,7 +136,7 @@ Flags:
138136
--provider-file string Path to a file containing provider configuration
139137
--show-secrets Show secret values in output
140138
141-
Use "myResource [command] --help" for more information about a command.
139+
Use "do azure:index:myResource [command] --help" for more information about a command.
142140
`
143141
assert.Equal(t, expected, stdout.String())
144142
}
@@ -168,14 +166,12 @@ Outputs:
168166
size (integer)
169167
170168
Usage:
171-
myResource [flags]
172-
myResource [command]
169+
do azure:index:myResource [flags]
170+
do azure:index:myResource [command]
173171
174172
Available Commands:
175-
completion Generate the autocompletion script for the specified shell
176173
create Create a resource
177174
delete Delete a resource
178-
help Help about any command
179175
patch Patch a resource
180176
read Read a resource
181177
@@ -187,7 +183,7 @@ Flags:
187183
--provider-file string Path to a file containing provider configuration
188184
--show-secrets Show secret values in output
189185
190-
Use "myResource [command] --help" for more information about a command.
186+
Use "do azure:index:myResource [command] --help" for more information about a command.
191187
`
192188
assert.Equal(t, expected, stdout.String())
193189
}

0 commit comments

Comments
 (0)