fredrikekre / Runic.jl

A code formatter for Julia with rules set in stone.
MIT License
92 stars 2 forks source link

problems with command-line options #36

Closed matthias314 closed 1 month ago

matthias314 commented 1 month ago

I get unexpected results when using the command-line options mentioned in the man page.

~$ alias runic="/usr/local/git/julia/julia --project=. -m Runic"   # Julia 1.12
~$ runic test.jl
ERROR: at least one of options `-c, --check`, `-d, --diff`, `-i, --inplace`, or `-o, --output` must be specified

So far, so good. (Would it make sense to send output to stdout by default?)

~$ runic -o test.out test.jl
ERROR: at least one of options `-c, --check`, `-d, --diff`, `-i, --inplace`, or `-o, --output` must be specified

Why is this? I gave the option -o.

~$ runic -d test.jl
ERROR: no output file specified

Why is this? I gave the option -d.

~$ runic -o test.out -d test.jl
Formatting `test.jl` -> `-` .................................................. ✔
diff --git a/test.jl b/test.jl
[...]

The output goes to both test.out and stdout although stdout was not specified. Why is this?

~$ runic -o - -d test.jl

This sends output to both stdout and the file ./-. However, the man page says:

If the specified file is - output is written to stdout.

fredrikekre commented 1 month ago

Thanks for trying out Runic. The command line parsing is a bit of a mess sorry.

Would it make sense to send output to stdout by default?

I think I had this at first but it is a bit annoying if you do runic and it seemingly just hangs but I suppose that is how many unix tools work. Perhaps it is possible to detect what type stdin have and bail after a while if there is no input.

runic -o test.out test.jl

This one should definitely work.

runic -d test.jl

This one should probably also work and simply print the diff to stderr? (Or stdout since formatted text isn't outputted?)

runic -o test.out -d test.jl

This one I think works as expected. The formatted text is outputted to test.out and auxiliary information like the diff to stderr. It doesn't make sense to output them both to the file I think?

runic -o - -d test.jl

Hmm, this should work and output formatted text to stdout and diff to stderr.

matthias314 commented 1 month ago

Would it make sense to send output to stdout by default?

I suppose that is how many unix tools work.

I agree.

runic -d test.jl

This one should probably also work and simply print the diff to stderr?

The error message given for runic test.jl suggests that with a single -d option it works. So it should work (or the error message should be changed). If the output went to stdout by default, then this would apply here, too.

runic -o test.out -d test.jl

This one I think works as expected. The formatted text is outputted to test.out and auxiliary information like the diff to stderr. It doesn't make sense to output them both to the file I think?

I see, it's stderr, not stdout. I didn't expect any output outside of the specified output file. Again, that would be how Unix tools work. If you use runic in a script, then you probably want it to do its job silently.

BTW, the long form of runic -o test.out is runic --output test.out. It seems to me that the (GNU?) convention for long options is to use a = sign, for example, grep -f test becomes grep --file=test. Also compare julia --project=..

fredrikekre commented 1 month ago

I didn't expect any output outside of the specified output file. Again, that would be how Unix tools work.

Logging info and verbose extra stuff is usually still printed to stderr though because you don't want that to garble up the "real output" which in this case is the formatted text.

fredrikekre commented 1 month ago

Reworked the argument parsing a bit and also now stdin/stdout are defaults.