Skip to content

Implement better parsing of leftover arguments for run commands #271

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

soenkehahn
Copy link
Contributor

No description provided.

@soenkehahn soenkehahn force-pushed the sh/command-line-flags branch from c9ac6ec to 0b6f73a Compare October 21, 2023 19:19
@soenkehahn soenkehahn force-pushed the sh/command-line-flags branch from 0b6f73a to bf7f64b Compare October 21, 2023 19:22
@soenkehahn soenkehahn changed the title Add (failing) test for passing command line flags to Executables Implement better parsing of leftover arguments for run commands Oct 21, 2023
@soenkehahn soenkehahn marked this pull request as ready for review October 21, 2023 19:23
-- arguments.
handleParseResult $ execParserPure parserPrefs parserInfo allArgs
Left err ->
handleParseResult $ Failure $ parserFailure parserPrefs parserInfo err contexts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has gotten much more complicated than I thought it would be. But I haven't found an easier way to do this with optparse-applicative.

@@ -74,6 +74,32 @@ spec = around_ (hSilence [stderr]) $ do
command <- testWithGarnTs ["run", "project", "more", "args"] ("project" ~> targetConfig)
command `shouldBe` Run (CommandOptions "project" targetConfig) ["more", "args"]

it "parses run commands with additional flags (starting with `-`)" $ do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you need — only for —help to be parsed by the inner command? That feels unintuitive to me. Should we maybe require it for all arguments? I think not needing it made sense when we didn’t have the past command (eg “foo” in “garn build foo”) be optional, but doesn’t anymore.

Copy link
Contributor

@jkarni jkarni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing flags (rather than string arguments) to the subprocess is already possible with --; as in garn run foo bar -- --baz. It's not a great system, but I think requiring -- only when run happens to have a conflicting option isn't great either (both because it's not clear from the command alone who is getting the option, and because of backwards compatibility).

@soenkehahn
Copy link
Contributor Author

Passing flags (rather than string arguments) to the subprocess is already possible with --; as in garn run foo bar -- --baz.

I can't seem to manage to get any arguments that start with - passed to the subcommand. garn just complains with: Invalid option `--bar'. So -- doesn't work. Do you have an actual working example for this?

More importantly: I think this isn't super high priority. Maybe we should have a very simple PR that changes this to always require --. That should be easy to parse, outside of optparse-applicative. And then later we could revisit this. (I think even that PR is not thaaat urgent.)

@soenkehahn soenkehahn marked this pull request as draft October 23, 2023 13:42
@jkarni
Copy link
Contributor

jkarni commented Oct 23, 2023

For whatever reason, I need to pass -- before the target: garn run -- dev -f works, but garn run dev -- -f does not.

Parsing -- outside of optparse-applicative sounds like a good idea!

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 this pull request may close these issues.

Support passing CLI arguments to garn run that begin with -
2 participants