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

nimpretty shall support pipe on stdin, to stdout #24622

Open
litlighilit opened this issue Jan 18, 2025 · 5 comments
Open

nimpretty shall support pipe on stdin, to stdout #24622

litlighilit opened this issue Jan 18, 2025 · 5 comments

Comments

@litlighilit
Copy link
Contributor

litlighilit commented Jan 18, 2025

Summary

nimpretty currently must run on nim files (passed as arguments),

and lacks the feature of pipe.

Description

Formatter of other langs, like rustfmt, gofmt, allows reading stdin and outputting to stdout,

which is handy, for example, in vim, you can simply use :%!rustfmt to format current source code file.

Yet neither :%!nimpretty or :%!nimpretty - doesn't work, as it currently expects one or more files as arguments.

Alternatives

Write to a temp file, nimpretty it and then cat it.

In addition, according to #8458 (comment), relying on bash substitution won't work

Examples

No response

Backwards Compatibility

None.

This just allows a cli usage used to be invalid

Links

#8458 (comment)

@Araq
Copy link
Member

Araq commented Jan 18, 2025

Fine with me if enabled via an explicit --stdin switch.

@litlighilit
Copy link
Contributor Author

Fine with me if enabled via an explicit --stdin switch.

How about via - switch, which is also widely available throughout UNIX utils.

(Or like gofmt & rustfmt, no args means reading from stdin)

Maybe --stdin switch isn't very widely used for such cases?

@Araq
Copy link
Member

Araq commented Jan 18, 2025

Nimsuggest uses --stdin and it's better to be consistent with ourselves than to be consistent with others who never care about consistency with Nim either.

@ire4ever1190
Copy link
Contributor

Mean - would also be consistent since it's supported for nim/nim check

echo "echo 1" | nim r -

outputs "1"

@Araq
Copy link
Member

Araq commented Jan 19, 2025

Alright then nimpretty better supports both - and --stdin.

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

3 participants