saves/main.go
2016-01-02 11:03:22 -08:00

48 lines
955 B
Go

// command sk pushes and pulls save files from my server
package main
import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"os/user"
)
const usage = "sk <push|pull>"
func main() {
u, err := user.Current()
if err != nil {
fmt.Fprintf(os.Stderr, "cannot calculate home dir: %v", err)
os.Exit(1)
}
docs := fmt.Sprintf("%s/Documents/", u.HomeDir)
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "%s\n", usage)
os.Exit(1)
}
var cmd *exec.Cmd
switch os.Args[1] {
case "pull":
cmd = exec.Command("rsync", "-auv", "sj.mcquay.me:~/docs/ycg", docs)
case "push":
cmd = exec.Command("rsync", "-auv", fmt.Sprintf("%sycg", docs), "sj.mcquay.me:~/docs/")
default:
fmt.Fprintf(os.Stderr, "%s\n", usage)
os.Exit(1)
}
var so, se bytes.Buffer
cmd.Stdout = &so
cmd.Stderr = &se
if rc := cmd.Run(); rc != nil {
log.Printf("cmd: %+v", cmd)
log.Printf("so: %s", so.Bytes())
log.Printf("se: %s", se.Bytes())
log.Printf("rc: %+v", rc)
}
}