@@ -151,8 +151,8 @@ type ExecOptions struct {
151
151
ResourceName string
152
152
Command []string
153
153
154
- FullCmdName string
155
- SuggestedCmdUsage string
154
+ ParentCommandName string
155
+ EnableSuggestedCmdUsage bool
156
156
157
157
Builder func () * resource.Builder
158
158
ExecutablePodFn polymorphichelpers.AttachablePodForObjectFunc
@@ -200,10 +200,10 @@ func (p *ExecOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, argsIn []s
200
200
201
201
cmdParent := cmd .Parent ()
202
202
if cmdParent != nil {
203
- p .FullCmdName = cmdParent .CommandPath ()
203
+ p .ParentCommandName = cmdParent .CommandPath ()
204
204
}
205
- if len (p .FullCmdName ) > 0 && cmdutil .IsSiblingCommandExists (cmd , "describe" ) {
206
- p .SuggestedCmdUsage = fmt . Sprintf ( "Use '%s describe %s -n %s' to see all of the containers in this pod." , p . FullCmdName , p . ResourceName , p . Namespace )
205
+ if len (p .ParentCommandName ) > 0 && cmdutil .IsSiblingCommandExists (cmd , "describe" ) {
206
+ p .EnableSuggestedCmdUsage = true
207
207
}
208
208
209
209
p .Config , err = f .ToRESTConfig ()
@@ -322,11 +322,10 @@ func (p *ExecOptions) Run() error {
322
322
containerName := p .ContainerName
323
323
if len (containerName ) == 0 {
324
324
if len (pod .Spec .Containers ) > 1 {
325
- usageString := fmt .Sprintf ( "Defaulting container name to %s." , pod .Spec .Containers [0 ].Name )
326
- if len ( p . SuggestedCmdUsage ) > 0 {
327
- usageString = fmt .Sprintf ( "%s \n %s " , usageString , p . SuggestedCmdUsage )
325
+ fmt .Fprintf ( p . ErrOut , "Defaulting container name to %s.\n " , pod .Spec .Containers [0 ].Name )
326
+ if p . EnableSuggestedCmdUsage {
327
+ fmt .Fprintf ( p . ErrOut , "Use '%s describe pod/%s -n %s' to see all of the containers in this pod. \n " , p . ParentCommandName , pod . Name , p . Namespace )
328
328
}
329
- fmt .Fprintf (p .ErrOut , "%s\n " , usageString )
330
329
}
331
330
containerName = pod .Spec .Containers [0 ].Name
332
331
}
0 commit comments