snowfallorg / nix-editor

A simple rust program to edit NixOS configuration files with just a command
MIT License
72 stars 5 forks source link

dont add newline on print #10

Closed milahu closed 2 years ago

milahu commented 2 years ago

fix #8

vlinkz commented 2 years ago

I like the idea of removing potential extra newlines added by println!, however with the implementation in this PR, other command options, such as just reading a value would not have a newline after them, leading to a weird terminal output. I'm thinking instead I might add a strip and then println!, that way it is predictable that there will be one and only one newline at the end

milahu commented 2 years ago

do one thing

the tool should minimize diff noise

if the user has a million newlines at the end of his configuration.nix, then so be it

to prettify nix code, we have other tools like nixpkgs-fmt and alejandra

vlinkz commented 2 years ago

I agree about the diff noise, perhaps a better alternative would be to check what output is being printed and then print a newline depending on the query, however since the user is simply printing something out to the console, I don't see changing or adding a newline to the end as an issue. If a user wants to use the unmodified output for something they could use nix-editor -o output rather than nix-editor something > output. I think I'll just add a --raw option to print without edits or newlines (including values), and trim otherwise

vlinkz commented 2 years ago

651e2a323a586bcc5693bf896a1faa4014361207

milahu commented 2 years ago

thanks, this is better

-  println!("{}", output);
+  println!("{}", output.trim());

trimming should be optional via --trim ... but well, nix-editor --raw will do