Default dest to leaf of repo

This commit is contained in:
Tim Hockin 2016-08-24 21:52:24 -07:00
parent dd60fb0312
commit dd09cac833
1 changed files with 6 additions and 2 deletions

View File

@ -46,7 +46,7 @@ var flDepth = flag.Int("depth", envInt("GIT_SYNC_DEPTH", 0),
var flRoot = flag.String("root", envString("GIT_SYNC_ROOT", "/git"), var flRoot = flag.String("root", envString("GIT_SYNC_ROOT", "/git"),
"root directory for git operations") "root directory for git operations")
var flDest = flag.String("dest", envString("GIT_SYNC_DEST", ""), var flDest = flag.String("dest", envString("GIT_SYNC_DEST", ""),
"path at which to publish the checked-out files (a subdirectory under --root)") "path at which to publish the checked-out files (a subdirectory under --root, defaults to leaf dir of --root)")
var flWait = flag.Int("wait", envInt("GIT_SYNC_WAIT", 0), var flWait = flag.Int("wait", envInt("GIT_SYNC_WAIT", 0),
"number of seconds between syncs") "number of seconds between syncs")
var flOneTime = flag.Bool("one-time", envBool("GIT_SYNC_ONE_TIME", false), var flOneTime = flag.Bool("one-time", envBool("GIT_SYNC_ONE_TIME", false),
@ -107,10 +107,14 @@ func main() {
setFlagDefaults() setFlagDefaults()
flag.Parse() flag.Parse()
if *flRepo == "" || *flDest == "" { if *flRepo == "" {
flag.Usage() flag.Usage()
os.Exit(1) os.Exit(1)
} }
if *flDest == "" {
parts := strings.Split(strings.Trim(*flRepo, "/"), "/")
*flDest = parts[len(parts)-1]
}
if _, err := exec.LookPath("git"); err != nil { if _, err := exec.LookPath("git"); err != nil {
log.Errorf("required git executable not found: %v", err) log.Errorf("required git executable not found: %v", err)
os.Exit(1) os.Exit(1)