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

Remove -- requirement for roc [FILE] to allow better messaging #5425

Merged
merged 5 commits into from
May 27, 2023

Conversation

dlsmith
Copy link
Contributor

@dlsmith dlsmith commented May 19, 2023

#5388

roc [FILE] no longer requires --, to allow for better error messaging (see foromat example below). Subcommands are required up front to avoid ambiguity:

$ roc help
Run the given .roc file, if there are no compilation errors.
You can use one of the SUBCOMMANDS below to do something else!

Usage: roc [OPTIONS] [ROC_FILE] [ARGS_FOR_APP]...
       roc <COMMAND>

-- is still required for roc <COMMAND>:

$ roc help test
Run all top-level `expect`s in a main module and any modules it imports

Usage: roc test [OPTIONS] [ROC_FILE] [-- [ARGS_FOR_APP]...]

When roc [FILE] errors, we provide a hint about a possible misspelled subcommand:

$ roc foromat *

This file was not found: /Users/dlsmith/src/roc/foromat

Did you mean to use the format subcommand?

You can run `roc help` to see the list of available subcommands and for more information on how to provide a .roc file.

bhansconnect
bhansconnect previously approved these changes May 27, 2023
// Add some additional hints if run as `roc [FILENAME]`.
if matches.subcommand().is_none() {
if let Some(possible_typo) = path.to_str() {
if let Some((nearest_command, _)) =
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We may want to skip this message if the possible_typo ends in .roc.

Also, even more optional, if the distance is large, maybe we should skip the message as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good ideas! I added the .roc check, but thought I'd be a little more permissive to start when it came to subcommand matching. I included the distance in the return value when I wrote the matching function so it's easy to add additional restrictions later if there are too many false positives. Happy to add it now though if you prefer.

@bhansconnect
Copy link
Contributor

Looks good! Just a nit idea.

Copy link
Contributor

@bhansconnect bhansconnect left a comment

Choose a reason for hiding this comment

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

Sounds good

@bhansconnect bhansconnect merged commit 7cabaec into roc-lang:main May 27, 2023
10 checks passed
@dlsmith dlsmith deleted the better-subcommand-error branch May 27, 2023 16:56
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.

None yet

2 participants