idris-lang / Idris2

A purely functional programming language with first class types
https://idris-lang.org/
Other
2.53k stars 378 forks source link

CLI flags interpreted as files if mistyped #3407

Open eayus opened 3 weeks ago

eayus commented 3 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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)