Skip to content

Option.IsGlobal creates potential unintended behavior when an option is used in more than one subcommand but is not intended to be global in both #1728

Closed

Description

@jonsequitur

The current implementation of Command.AddGlobalOption sets Option.IsGlobal, which can result in an unintended behavior when an option is used in more than one command and is intended to be global in one case but not in another.

In the following example, the second parse should result in a parse error because option was not added globally to childCommand2, but there is no parse error because AddGlobalOption was called on the same option. This bug will manifest regardless of the call order.

image

Activity

  1. KalleOlaviNiemitalo commented on Apr 3, 2023

    @KalleOlaviNiemitalo

    This was fixed with #2060, in the sense that AddGlobalOption was replaced with the public property Option.AppliesToSelfAndChildren; developers who set that won't be surprised that it affects the option in every command to which the option is added.

    (AppliesToSelfAndChildren was subsequently renamed to Recursive in #2132.)

  2. jonsequitur commented on Apr 3, 2023

    @jonsequitur
    ContributorAuthor

    Thanks for point this out, @KalleOlaviNiemitalo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Parser and Binderbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions