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

CLI flags interpreted as files if mistyped #3407

Open
eayus opened this issue Oct 30, 2024 · 2 comments
Open

CLI flags interpreted as files if mistyped #3407

eayus opened this issue Oct 30, 2024 · 2 comments

Comments

@eayus
Copy link
Contributor

eayus commented Oct 30, 2024

Currently, the typing the following (mistyped) command:

idris2 --chec Test.idr

Will launch the repl saying it can't find the file --chec.

     ____    __     _         ___
    /  _/___/ /____(_)____   |__ \
    / // __  / ___/ / ___/   __/ /     Version 0.7.0-2bd88b7d3
  _/ // /_/ / /  / (__  )   / __/      https://www.idris-lang.org
 /___/\__,_/_/  /_/____/   /____/      Type :? for help

Welcome to Idris 2.  Enjoy yourself!
File error in --chec: File Not Found
Main>

This is pretty unusual behaviour, as most applications will error saying that --chec is not a valid flag. From a user perspective I would say its undesirable as they most likely made a typo and didn't want to start the REPL anyway. (I think there is another argument to be made that the REPL should not start if given non existent files in general).

@eayus
Copy link
Contributor Author

eayus commented Nov 8, 2024

I've been thinking about this a bit and I feel like any robust solution will basically implement 90% of a generic command line arguments parser. I'm not sure how we feel about pulling in external libraries for the compiler (which might rely on getting the compiler packaged with a package manger like pack). To my knowledge there are two CLI libraries, collie and sap (my own library, so I'm probably biased).

The other thing I was going to suggest is that the CLI for Idris could be broken down into subcommands, something like:

idris2 check ...
idris2 repl ...
idris2 compile ...

The main advantage for this is that we can segregate flags into the different subcommands depending on where they are relevant. For example, a user checking a file does not need to know about the flags to set the compiler backend. This would simplify the help dialogues, and (in my opinion) provide a more intuitive interface. I'm not sure whether this is something that other people agree on? It would obviously break backwards compatibility for scripts using the interface.

@buzden
Copy link
Contributor

buzden commented Nov 11, 2024

To my knowledge there are two CLI libraries, collie and sap

There is at least https://github.com/idris-community/idris2-getopts, which is a pulled-out version from contrib (https://github.com/idris-lang/Idris2/blob/main/libs/contrib/System/Console/GetOpt.idr)

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