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

Argfiles not supported in Clikt library version 5.0 or higher #570

Closed
bernardladenthin opened this issue Jan 22, 2025 · 8 comments · Fixed by #574
Closed

Argfiles not supported in Clikt library version 5.0 or higher #570

bernardladenthin opened this issue Jan 22, 2025 · 8 comments · Fixed by #574

Comments

@bernardladenthin
Copy link

bernardladenthin commented Jan 22, 2025

The implementation of argument files (argfiles) fails when using Clikt library version 5.0 or higher. The application throws an error:
got unexpected extra argument (@src/test/resources/cliargs.arg)

This issue occurs when trying to parse arguments from a file. The feature works correctly with Clikt versions below 5.0. The bug can be reproduced easily by switching to Clikt version 5.0 or higher and making a minor adjustment to the import statement.

Steps to Reproduce:

  1. Use Clikt library version 5.0 or higher.
  2. Provide an argument file (e.g., @src/test/resources/cliargs.arg).
  3. Update the import statement if necessary to match Clikt 5.0 syntax.
  4. Run the application.

Expected Behavior:
The argument file should be parsed correctly, as it works with Clikt versions below 5.0.

Actual Behavior:
The application throws an error indicating an unexpected extra argument.

Environment:

  • Clikt version: 5.0 or higher
  • Operating System: [Specify OS]
  • Java/Kotlin version: [Specify version if relevant]

Documentation: https://ajalt.github.io/clikt/advanced/#command-line-argument-files-argfiles

Attachments:

@ajalt
Copy link
Owner

ajalt commented Jan 23, 2025

I can't reproduce that problem. Argfiles work fine for me from the command line, and all the argfile unit tests pass. How are you trying to run your code?

@bernardladenthin
Copy link
Author

Hi,

I’ve provided an example of my use case. If you set the library version to below 5.0, the example works as expected. However, upgrading to version 5.0 results in the following error:
got unexpected extra argument (@src/test/resources/cliargs.arg)

This indicates that something has changed or become incompatible in version 5.0.

@ajalt
Copy link
Owner

ajalt commented Jan 24, 2025

Your example has as a lot of unrelated code. Can you reduce it down to a minimal example that can reproduce the issue?

@bernardladenthin
Copy link
Author

bernardladenthin commented Jan 26, 2025

The provided example is already minimal:

class ExampleCommand : CliktCommand() {

    val firstOption: String by option().required()

    override fun run() {
    }
}

Run this program with the following arguments:

@src/test/resources/cliargs.arg --first-option=example

This worked in versions below 5.0, but now I get the following error message:

got unexpected extra argument (@src/test/resources/cliargs.arg)

I've included a working Unit Test example that allows you to easily switch between version 4 and version 5 to observe the difference in behavior.

@bernardladenthin
Copy link
Author

Hi, were you able to reproduce the issue? How can I assist you? Best regards, Bernard

@ajalt
Copy link
Owner

ajalt commented Feb 3, 2025

Ah, I figured it out. Your description wasn't correct: ./tool @argfile --option works fine. The error occurs when you specify an argfile after a subcommand like ./tool subcommand @argfile.

@bernardladenthin
Copy link
Author

In my original software, I have both cases. The Argfile options, both before and after, are used to overwrite these. It was working fine. I hope you can reproduce the issue. I need to know whether I need to change something in the implementation (which I didn't find in the migration description) or if this is an issue in version 5.0 and later.

@bernardladenthin
Copy link
Author

Thanks so much for the quick fix! I'm looking forward to the next release with the bug resolved.

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

Successfully merging a pull request may close this issue.

2 participants