sagiegurari / shell2batch

Coverts simple basic shell scripts to windows batch scripts.
Apache License 2.0
57 stars 7 forks source link

suppress error for `rm -rf` on non-existent files #12

Closed dakom closed 4 years ago

dakom commented 4 years ago

running rm -rf on a non-existent directory gives an error

would be nice if the default could be in that case to not have an error (rather than needing to do conditional checks before running, for use in cargo-make)

sagiegurari commented 4 years ago

you see the error on linux or windows? can you provide the error?

dakom commented 4 years ago

Windows

The system cannot find the file specified.
[cargo-make] ERROR - Error while executing command, exit code: 2
dakom commented 4 years ago

The toml (from cargo-make) is:

[tasks.clean-rust]
script_runner = "@shell"
script = ["rm -rf ./rust/pkg"]

Resulting command is

rmdir /S /Q .\rust\pkg
sagiegurari commented 4 years ago

you can add a condition to the task "file_exists" so this will only execute if the dir exists

dakom commented 4 years ago

is there a way to add a condition to each line in a task's script?

Right now I'm doing this, as a workaround... kinda ugly imho:

[tasks.clean-rust]
run_task = [{name = [
    "clean-rust1", 
    "clean-rust2",
    "clean-rust3",
]}]

[tasks.clean-rust1]
script_runner = "@shell"
script = ["rm -rf ./_static/wasm/core/pkg"]
condition = {files_exist = ["./_static/wasm/core/pkg"]}

[tasks.clean-rust2]
script_runner = "@shell"
script = ["rm -rf ./rust/target"]
condition = {files_exist = ["./rust/target"]}

[tasks.clean-rust3]
script_runner = "@shell"
script = ["rm -rf ./rust/pkg"]
condition = {files_exist = ["./rust/pkg"]}
sagiegurari commented 4 years ago

nope. shell2batch is limited, but if there is a flag to rmdir that can silence this error i can add it. need to check

sagiegurari commented 4 years ago

windows doesn't provide such option, so either add the condition or add ignore_errors=true

dakom commented 4 years ago

ok cool. can ignore_errors=true be set for a given task only?

dakom commented 4 years ago

nm I see that it can. Thanks!

sagiegurari commented 4 years ago

@dakom you can now put @duckscript instead of shell and it should work cross platform without errors. no need for conditions or to ignore errors