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

Not parsing positional argument #489

Closed
2 tasks done
RISCfuture opened this issue Sep 13, 2022 · 1 comment
Closed
2 tasks done

Not parsing positional argument #489

RISCfuture opened this issue Sep 13, 2022 · 1 comment

Comments

@RISCfuture
Copy link

I have a ParsableCommand instance with two positional arguments, one of which is required. Despite passing a value for the required argument, it still claims that argument is not being specified.

ArgumentParser version: main
Swift version: 5.7.0.127.4

Checklist

  • If possible, I've reproduced the issue using the main branch of this package
  • I've searched for existing GitHub issues

Steps to Reproduce

import Foundation
import ArgumentParser

@main
struct ExampleCommand: ParsableCommand {
    @Argument(help: "arg1",
              completion: .file(extensions: ["sql"]),
              transform: URL.init(fileURLWithPath:))
    var firstArg = URL(fileURLWithPath: "default/value.sql")
    
    @Argument(help: "arg2",
              completion: .file(extensions: ["csv"]),
              transform: URL.init(fileURLWithPath:))
    var secondArg
    
    @Flag(help: "Include extra information in the output.")
    var verbose = false
    
    mutating func run() throws {
      print(firstArg, secondArg)
    }
}

Run example-command some/file.csv

Expected behavior

Prints the two arguments.

Actual behavior

Error: Missing expected argument '<second-arg>'
Help:  <second-arg>  arg2
Usage: example-command [<first-arg>] <second-arg> [--verbose]
  See 'example-command --help' for more information.
Program ended with exit code: 64
@natecook1000
Copy link
Member

This is behaving as intended, since positional arguments are always filled in declaration order. It would be nice if we had a warning or validation error for commands with this configuration, so that you don't have to wonder what's going on.

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

2 participants