loadCommand finds the leaf command to run.
(c *cobra.Command, a []string)
| 351 | |
| 352 | // loadCommand finds the leaf command to run. |
| 353 | func (fc *FuncCommand) loadCommand(c *cobra.Command, a []string) (rcmd *cobra.Command, rargs []string, rerr error) { |
| 354 | ctx := c.Context() |
| 355 | |
| 356 | spanCtx, span := Tracer().Start(ctx, "parsing command line arguments", telemetry.Encapsulate()) |
| 357 | defer telemetry.EndWithCause(span, &rerr) |
| 358 | fc.ctx = spanCtx |
| 359 | |
| 360 | builder := fc.cobraBuilder(ctx, fc.mod.MainObject.AsObject.Constructor) |
| 361 | |
| 362 | cmd, args, err := fc.traverse(c, a, builder) |
| 363 | if err != nil { |
| 364 | fc.logCommandParseSchemaSummary(ctx, "traverse_error", a, cmd, args, err) |
| 365 | return cmd, args, err |
| 366 | } |
| 367 | |
| 368 | // There should be no args left, if there are it's an unknown command. |
| 369 | if err := cobra.NoArgs(cmd, args); err != nil { |
| 370 | fc.logCommandParseSchemaSummary(ctx, "remaining_args", a, cmd, args, err) |
| 371 | return cmd, args, err |
| 372 | } |
| 373 | |
| 374 | return cmd, args, nil |
| 375 | } |
| 376 | |
| 377 | func (fc *FuncCommand) logCommandParseSchemaSummary(ctx context.Context, reason string, requestedArgs []string, cmd *cobra.Command, remainingArgs []string, parseErr error) { |
| 378 | if fc == nil || fc.mod == nil { |
no test coverage detected