top | item 39280199

(no title)

danstewart_ | 2 years ago

I tend to go the opposite way and have the default behaviour not actually make any changes and require passing `--commit` to actually do something.

I feel it’s safer for scripts that have irreversible (or difficult to reverse) actions.

discuss

order

enriquto|2 years ago

Even safer: your program does never perform any actual deed. It just prints commands that you can run afterwards, using an external program, ideally a shell. This has the advantage of allowing the user to edit all the actions one by one.

Instead of

    myprog           # see what would happen
    myprog --commit  # alright, do it

You do

    myprog           # see what would happen
    myprog | sh      # alright, do it

But if you want to change something:

    myprog > x
    vi x
    cat x | sh

And if you just want to run everything in parallel:

    myprog | parallel -j 16