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

Make it *very* obvious that sd will modify in-place #64

Closed
HarrisonMc555 opened this issue Feb 14, 2020 · 5 comments · Fixed by #93
Closed

Make it *very* obvious that sd will modify in-place #64

HarrisonMc555 opened this issue Feb 14, 2020 · 5 comments · Fixed by #93

Comments

@HarrisonMc555
Copy link

First of all, thanks for the great tool! This is slowly becoming my default go-to instead of sed.

I used sd today for the first time in a while, so I ran sd --help to refresh on the (admittedly intuitive) syntax.

There was one line in the help dialog of note:

    -i, --in-place
            (Deprecated). Modify the files in-place. Otherwise, transformations will be emitted to STDOUT by default.

If I'm not mistaken, this line is out of date. By default, sd does modify files in-place.

I would personally vote for this tool to not modify in-place to more closely match the behavior of sed, awk, and other similar tools. I would argue that the most common use case for a tool like this is to run a few test cases through to ensure that you're doing what you think you're doing, iterate a few times, and then modify the file in place.

However, I respect that you decided to move to the default of modifying in-place. I would ask, however, that we change the help text to make it very obvious that, by default, this tool modifies files in place. It can be very surprising to someone coming from sed, awk, or a ton of other tools. I was lucky that I had recently committed my file to git, otherwise I could have lost a lot of changes--my replacement did not behave the way I thought it would!

I'm willing to submit a pull request if you'd be willing to merge such a change :)

Thanks again for the great tool!

@ngirard
Copy link

ngirard commented Feb 27, 2020

While I don't have a strong opinion on weather to modify in-place or not by default, I agree that the command-line help is misleading.

@perklet
Copy link

perklet commented May 27, 2020

Anyway, the help message should be updated, it's very misleading.

@jchook
Copy link

jchook commented Aug 1, 2020

I can agree. Perhaps a simple note here:

ARGS:
    <find>
            The regexp or string (if -s) to search for

    <replace-with>
            What to replace each match with. Unless in string mode, you may use captured values like $1, $2, etc

    <files>...
            The path to file(s). This is optional - sd can also read from STDIN.
+           NOTE: sd modifies files in-place. See documentation for examples.

Currently, from the --help docs, the only clue that it will modify files in place:

    -p, --preview
            Output result into stdout and do not modify files

From reading the online docs, I felt immediately aware of the modify-in-place behavior. The docs also pointed out a very simple way to add backup functionality with a couple lines of shell.

@chmln
Copy link
Owner

chmln commented Aug 3, 2020

@jchook that looks good! Wanna submit a quick PR?

@ngirard
Copy link

ngirard commented Aug 4, 2020

Thanks @jchook !

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 a pull request may close this issue.

5 participants