2024-05-05 20:14:55 +00:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
2024-05-17 19:49:59 +00:00
|
|
|
"os"
|
2024-05-05 20:14:55 +00:00
|
|
|
|
2024-05-17 19:49:59 +00:00
|
|
|
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
|
2024-05-05 20:14:55 +00:00
|
|
|
)
|
|
|
|
|
2024-05-17 19:49:59 +00:00
|
|
|
func SyncDirectories(exclude []string, del bool, src, dest string, debug bool) *plugin_exec.Cmd {
|
2024-05-05 20:14:55 +00:00
|
|
|
args := []string{
|
|
|
|
"-r",
|
|
|
|
"--exclude",
|
|
|
|
".git",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range exclude {
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
"--exclude",
|
|
|
|
item,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if del {
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
"--delete",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-05-14 08:19:04 +00:00
|
|
|
if debug {
|
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
"--stats",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-05-05 20:14:55 +00:00
|
|
|
args = append(
|
|
|
|
args,
|
|
|
|
".",
|
|
|
|
dest,
|
|
|
|
)
|
|
|
|
|
2024-05-17 19:49:59 +00:00
|
|
|
cmd := plugin_exec.Command("rsync", args...)
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
2024-05-05 20:14:55 +00:00
|
|
|
cmd.Dir = src
|
|
|
|
|
2024-05-06 20:43:56 +00:00
|
|
|
return cmd
|
2024-05-05 20:14:55 +00:00
|
|
|
}
|