Skip to content

Conversation

@Minnozz
Copy link
Contributor

@Minnozz Minnozz commented Jun 13, 2021

  • Clearer usage/help
  • Write subprocess stderr output to stderr instead of stdout
  • Fix parsing for -stdin argument
  • Fix TOCTOU issue with temp file creation
  • Clean up temp file

Fixes #5131

- Clearer usage for end users - No longer accept `-stdin foo.res` (should now be `-stdin .res`) - Split up code - Clarify error handling Fixes rescript-lang#5131
@Minnozz Minnozz changed the title rescript format: write subprocess stderr output to stderr instead of stdout Rewrite rescript format Jun 13, 2021
@Minnozz Minnozz marked this pull request as ready for review June 13, 2021 22:49
@Minnozz
Copy link
Contributor Author

Minnozz commented Jun 13, 2021

I got a bit carried away fixing #5131. Let me know what you think.

I would also like to change the style of the command line usage output of other parts of the rescript command to this one if you agree.

❯ ./rescript format -h rescript format Automatically format code in ReScript syntax Commands rescript format Format all .res(i) files in the current directory rescript format -all Format all .res(i) files in the whole project rescript format <file>... Format the specified files Files with .res(i) syntax are formatted in place Files with other supported extensions are printed to stdout in ReScript syntax rescript format -stdin <ext> Read code from stdin and print the formatted code to stdout in ReScript syntax The syntax of the input must be specified by passing an extension (like .res) rescript format -h Show this help Supported inputs Formatting in place: .res, .resi Printing to stdout: .res, .resi, .ml, .mli, .re, .rei 
@bobzhang
Copy link
Member

bobzhang commented Jun 14, 2021

The command line parsing is done using rescript_args, this is a port of native CLI parsing, it is better to be consistent here.

rescript subcommand subcommand_flags 

Some subcommands are implemented in native, some are implemented in JS, they are consistent because the command line parsing library is the same.

In general, it would be nice to do the code format in a separate pull request so it is easier to review

@Minnozz
Copy link
Contributor Author

Minnozz commented Jun 14, 2021

I'll revert to the previous command line argument parsing.

Note that the diff is so huge because almost all the code has been restructured/rewritten; it is not just reformatted. But if you want I can try to split it up, this will be difficult though.

@Minnozz
Copy link
Contributor Author

Minnozz commented Jun 14, 2021

Note that due to my usage of fs/promises, this breaks rescript format on node@12. I've created #5189 to clarify which node versions we want to support.

@Minnozz
Copy link
Contributor Author

Minnozz commented Jun 14, 2021

I've reverted to using ./scripts/rescript_arg.js.

@bobzhang
Copy link
Member

bobzhang commented Jun 15, 2021

Hi , my time budget spent on this project is quite limited, it would be nice if you can spend some time to make it easy to review, e.g, bug fixes first and refactoring later

@Minnozz
Copy link
Contributor Author

Minnozz commented Jun 15, 2021

Sure, I'll give it a shot soon.

@Minnozz
Copy link
Contributor Author

Minnozz commented Jun 16, 2021

@bobzhang I've created #5194 with all bugfixes as individual commits.

Compared to that PR, this PR adds the following changes:

  • rescript format -stdin used to accept a path/to/file.res, which was undocumented (and caused a bug, which rescript format bugfixes #5194 fixes). This PR only accepts an extension (.res)
  • Use async fs calls
  • Restructure code into functions
  • Expand usage (-h)

I'll leave this PR open and update it after #5194 is merged.

@Minnozz Minnozz marked this pull request as draft June 17, 2021 07:10
@cristianoc
Copy link
Collaborator

This most certainly got stale. Feel free to reopen if still relevant.

@cristianoc cristianoc closed this Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants