mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
contrib/git-sync: add wait
This commit is contained in:
parent
0415b63ab4
commit
5aba5f00c0
@ -25,22 +25,37 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var flRepo = flag.String("repo", env("GIT_SYNC_REPO", ""), "git repo url")
|
var flRepo = flag.String("repo", envString("GIT_SYNC_REPO", ""), "git repo url")
|
||||||
var flBranch = flag.String("branch", env("GIT_SYNC_BRANCH", "master"), "git branch")
|
var flBranch = flag.String("branch", envString("GIT_SYNC_BRANCH", "master"), "git branch")
|
||||||
var flRev = flag.String("rev", env("GIT_SYNC_BRANCH", "HEAD"), "git rev")
|
var flRev = flag.String("rev", envString("GIT_SYNC_BRANCH", "HEAD"), "git rev")
|
||||||
var flDest = flag.String("dest", env("GIT_SYNC_DEST", ""), "destination path")
|
var flDest = flag.String("dest", envString("GIT_SYNC_DEST", ""), "destination path")
|
||||||
|
var flWait = flag.Int("wait", envInt("GIT_SYNC_WAIT", 0), "number of seconds to wait before exit")
|
||||||
|
|
||||||
func env(key, def string) string {
|
func envString(key, def string) string {
|
||||||
if env := os.Getenv(key); env != "" {
|
if env := os.Getenv(key); env != "" {
|
||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
return def
|
return def
|
||||||
}
|
}
|
||||||
|
|
||||||
const usage = "usage: GIT_SYNC_REPO= GIT_SYNC_DEST= [GIT_SYNC_BRANCH=] git-sync -repo GIT_REPO_URL -dest PATH [-branch]"
|
func envInt(key string, def int) int {
|
||||||
|
if env := os.Getenv(key); env != "" {
|
||||||
|
val, err := strconv.Atoi(env)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("invalid value for %q: using default: %q", key, def)
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
|
||||||
|
const usage = "usage: GIT_SYNC_REPO= GIT_SYNC_DEST= [GIT_SYNC_BRANCH= GIT_SYNC_WAIT=] git-sync -repo GIT_REPO_URL -dest PATH [-branch -wait]"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -54,6 +69,9 @@ func main() {
|
|||||||
if err := syncRepo(*flRepo, *flDest, *flBranch, *flRev); err != nil {
|
if err := syncRepo(*flRepo, *flDest, *flBranch, *flRev); err != nil {
|
||||||
log.Fatalf("error syncing repo: %v", err)
|
log.Fatalf("error syncing repo: %v", err)
|
||||||
}
|
}
|
||||||
|
log.Printf("wait %d seconds", *flWait)
|
||||||
|
time.Sleep(time.Duration(*flWait) * time.Second)
|
||||||
|
log.Println("done")
|
||||||
}
|
}
|
||||||
|
|
||||||
// syncRepo syncs the branch of a given repository to the destination at the given rev.
|
// syncRepo syncs the branch of a given repository to the destination at the given rev.
|
||||||
|
Loading…
Reference in New Issue
Block a user