0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-11-22 20:20:38 +00:00
wp-git-action/plugin/utils.go

59 lines
829 B
Go
Raw Normal View History

2022-11-27 13:33:39 +00:00
package plugin
2019-06-07 10:32:16 +00:00
import (
"os"
"strings"
"github.com/rs/zerolog/log"
"github.com/thegeeklab/wp-git-action/git"
"golang.org/x/sys/execabs"
2019-06-07 10:32:16 +00:00
)
// helper function to simply wrap os execte command.
func execute(cmd *execabs.Cmd) error {
log.Debug().Msgf("+ %s", strings.Join(cmd.Args, " "))
2019-06-07 10:32:16 +00:00
cmd.Env = os.Environ()
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return cmd.Run()
}
func rsyncDirectories(pages Pages, repo git.Repository) *execabs.Cmd {
args := []string{
"-r",
"--exclude",
".git",
}
for _, item := range pages.Exclude.Value() {
args = append(
args,
"--exclude",
item,
)
2019-06-07 10:32:16 +00:00
}
if pages.Delete {
args = append(
args,
"--delete",
)
}
args = append(
args,
".",
repo.WorkDir,
)
cmd := execabs.Command(
"rsync",
args...,
)
cmd.Dir = pages.Directory
2019-06-07 10:32:16 +00:00
return cmd
2019-06-07 10:32:16 +00:00
}