0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-09-20 01:12:47 +02:00
wp-git-action/plugin/utils.go

59 lines
776 B
Go
Raw Normal View History

2022-11-27 14:33:39 +01:00
package plugin
2019-06-07 12:32:16 +02:00
import (
"fmt"
"os"
"os/exec"
"strings"
"github.com/thegeeklab/drone-git-action/git"
2019-06-07 12:32:16 +02:00
)
// helper function to simply wrap os execte command.
func execute(cmd *exec.Cmd) error {
fmt.Println("+", strings.Join(cmd.Args, " "))
cmd.Env = os.Environ()
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return cmd.Run()
}
func rsyncDirectories(pages Pages, repo git.Repository) *exec.Cmd {
args := []string{
"-r",
"--exclude",
".git",
}
for _, item := range pages.Exclude.Value() {
args = append(
args,
"--exclude",
item,
)
2019-06-07 12:32:16 +02:00
}
if pages.Delete {
args = append(
args,
"--delete",
)
}
args = append(
args,
".",
repo.WorkDir,
)
cmd := exec.Command(
"rsync",
args...,
)
cmd.Dir = pages.Directory
2019-06-07 12:32:16 +02:00
return cmd
2019-06-07 12:32:16 +02:00
}