Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to parse arguments if a subcommand has an option with remaining parsing strategy and one of the remaining arguments matches the top-level command #623

Open
ahoppen opened this issue Mar 11, 2024 · 0 comments

Comments

@ahoppen
Copy link

ahoppen commented Mar 11, 2024

Consider the following

import ArgumentParser

@main
struct asfdsdafjlk: AsyncParsableCommand {
  static let configuration = CommandConfiguration(subcommands: [MySubcommand.self])

  @Option(name: [.customLong("configuration"), .customShort("c")])
  var buildConfiguration: String = "x"

  mutating func run() throws {}
}


struct MySubcommand: AsyncParsableCommand {
  static var configuration: CommandConfiguration = CommandConfiguration(commandName: "sub")

  @Option(parsing: .remaining)
  var compilerArgs: [String]

  func run() async throws {
    print(compilerArgs)
  }
}

When running the executable with sub --compiler-args -abc xxx, the argument parser prints

Error: Missing expected argument '--compiler-args <compiler-args> …'

I would have expected it to print ["-abc", "xxx"] as the value for compilerArgs.

Removing customShort("c") from the top-level command makes the arguments parse as expected.

My expectation would be that if a subcommand is specified, the top level arguments should not influence argument parsing of the subcommand in any way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant