Skip to content

Completions for subcommands don't contain global options from parent commands #1563

Closed

Description

@baronfel

This sample script illustrates the issue:

#r "nuget: System.CommandLine, 2.0.0-beta2.22054.4"
#r "nuget: RestoreSources=https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json"

open System.CommandLine

let rootCommand = RootCommand()
rootCommand.AddGlobalOption(Option("test"))
let subCommand = Command("doThing")
subCommand.AddArgument(Argument("place", Arity = ArgumentArity.ZeroOrOne))
subCommand.AddOption(Option("other"))
rootCommand.AddCommand(subCommand)

let results = rootCommand.Parse("doThing", "")
let completions = results.GetCompletions()

let hasTestOption = completions |> Seq.exists (fun item -> item.Label = "test")

completions
|> Seq.iter (fun item -> printfn $"{item.Label}") // outputs "other" only, no "test"

When requesting completions for a command, we should also include the global options from any parent(s).

Activity

  1. added
    Area-Completions
    bug
    on Jan 5, 2022
  2. self-assigned this
    on Jan 5, 2022
  3. added this to the 2.0 GA milestone on Jan 5, 2022
  4. added a commit that references this issue on Jan 5, 2022
    ccc6377
  5. added a commit that references this issue on Mar 6, 2024
    4c7669a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-Completionsbug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions