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
Using main
instead of run
in subcommands leads to unexpected behavior
#622
Comments
Sorry you ran into this, @MaxDesiatov! There's a default implementation of the
This sounds like a different issue – if you're able to create a reproducing command, could you file this separately? For the command above, I get this output:
|
When accidentally defining
main
instead ofrun
in subcommands, no warning or error is shown, but the subcommand itself either displays a help message or swallows all arguments with no output.ArgumentParser version:
1.2.0
and1.3.0
or themain
branch, for example.Swift version: Apple Swift version 6.0-dev (LLVM ce41a43bba95b2b, Swift 1a840948a0905df), also reproducible with Swift 5.10.0 from Xcode 15.3.0
Checklist
main
branch of this packageSteps to Reproduce
Build and run an executable that has only this code:
Expected behavior
I realize that I should've defined
run
instead of main, but definingmain
inEntrypoint
does work, that function is called, albeit with no argument parsing done IIUC. The actual behavior for subcommands is unexpected. The default implementation ofParsableCommand
andAsyncParsableCommand
should at least issue a warning, if possible, that no custom implementaiton ofrun
is provided. Otherwise it's very easy to spend a long time debugging this issue.I'd assume this can also be a very frustrating experience for first-time users who try to convert their existing
@main
entrypoint toParsableCommand
but don't realize they have to renamestatic func main()
tofunc run()
.Actual behavior
When running
server
orclient
subcommands on their own, a help message is shown, but not other output is produced:When passing any arguments like
server foo bar
, no output is produced whatsoever.The text was updated successfully, but these errors were encountered: