Skip to content

RunAsSubcommand has been broken #1610

@hsanjuan

Description

@hsanjuan

My urfave/cli version is

v2.25.0

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this problem? Here's the GitHub guide about searching.

Dependency Management

  • My project is using go modules.

Describe the bug

On d5947d7 the RunAsSubcommand method was removed. It was re-added on 00afca4 as a deprecated stub.

However, a.RunContext(ctx.Context, ctx.Args().Slice()) behaves differently than what RunAsSubcommand did. For example, all the global flags in the original cli.Context are lost, where RunAsSubcommand correctly transferred them.

I have not found a way to run dynamic subcommands (i.e. an app which generates different subcommands at runtime by creating a subApp and calling subApp.RunAsSubcommand(origCtx). The subApp no longer has access to global flags defined in the parent app as before.

For me this is a breaking and silent behavior change, moreover since it arrived with absolutely no heads up: https://github.com/urfave/cli/releases/tag/v2.20.0. It seems unintended, therefore a bug.

To reproduce

See above.

Observed behavior

Sub-apps cannot get global flags anymore.

Expected behavior

There should be a way to pass global flags to sub-apps.

Additional context

Want to fix this yourself?

I think removals were done for a reason that is in conflict with keeping this functionality.

Run go version and paste its output here

go version go1.19.3 linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v2relates to / is being considered for v2kind/bugdescribes or fixes a bugstatus/triagemaintainers still need to look into thisstatus/waiting-for-responseWaiting for response from original requester

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions