2014-06-03 15:08:58 +00:00
|
|
|
package commands
|
2013-10-04 17:09:03 +00:00
|
|
|
|
|
|
|
import (
|
2014-06-24 14:30:33 +00:00
|
|
|
"fmt"
|
2014-06-03 15:08:58 +00:00
|
|
|
"github.com/github/git-media/gitmedia"
|
|
|
|
"github.com/github/git-media/gitmediaclient"
|
2014-06-26 20:53:37 +00:00
|
|
|
"github.com/spf13/cobra"
|
2014-03-12 14:55:01 +00:00
|
|
|
"strings"
|
2013-10-04 17:09:03 +00:00
|
|
|
)
|
|
|
|
|
2014-06-26 20:53:37 +00:00
|
|
|
var (
|
|
|
|
pushCmd = &cobra.Command{
|
|
|
|
Use: "push",
|
2014-06-26 21:22:24 +00:00
|
|
|
Short: "Push files to the media endpoint",
|
2014-06-26 20:53:37 +00:00
|
|
|
Run: pushCommand,
|
|
|
|
}
|
|
|
|
)
|
2013-10-04 17:09:03 +00:00
|
|
|
|
2014-06-26 20:53:37 +00:00
|
|
|
func pushCommand(cmd *cobra.Command, args []string) {
|
2014-06-05 18:48:23 +00:00
|
|
|
q, err := gitmedia.UploadQueue()
|
|
|
|
if err != nil {
|
|
|
|
Panic(err, "Error setting up the queue")
|
|
|
|
}
|
|
|
|
|
2013-10-21 20:02:15 +00:00
|
|
|
q.Walk(func(id string, body []byte) error {
|
2014-03-12 14:55:01 +00:00
|
|
|
fileInfo := string(body)
|
|
|
|
parts := strings.Split(fileInfo, ":")
|
|
|
|
|
|
|
|
var sha, filename string
|
|
|
|
sha = parts[0]
|
|
|
|
if len(parts) > 1 {
|
|
|
|
filename = parts[1]
|
|
|
|
}
|
|
|
|
|
2014-06-05 19:05:02 +00:00
|
|
|
path, err := gitmedia.LocalMediaPath(sha)
|
|
|
|
if err == nil {
|
|
|
|
err = gitmediaclient.Options(path)
|
|
|
|
}
|
2014-04-01 15:17:04 +00:00
|
|
|
if err != nil {
|
2014-06-05 19:05:02 +00:00
|
|
|
Panic(err, "error uploading file %s/%s", sha, filename)
|
2014-04-01 15:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = gitmediaclient.Put(path, filename)
|
2013-10-21 20:02:15 +00:00
|
|
|
if err != nil {
|
2014-06-05 19:05:02 +00:00
|
|
|
Panic(err, "error uploading file %s/%s", sha, filename)
|
2013-10-21 20:02:15 +00:00
|
|
|
}
|
2014-06-24 14:30:33 +00:00
|
|
|
fmt.Printf("\n")
|
2013-10-21 18:42:29 +00:00
|
|
|
|
2013-10-21 20:02:15 +00:00
|
|
|
if err := q.Del(id); err != nil {
|
2014-06-05 18:48:23 +00:00
|
|
|
Panic(err, "error removing %s from queue", sha)
|
2013-10-21 20:02:15 +00:00
|
|
|
}
|
2014-06-24 14:30:33 +00:00
|
|
|
|
2013-10-21 20:25:24 +00:00
|
|
|
return nil
|
2013-10-21 20:02:15 +00:00
|
|
|
})
|
2013-10-04 17:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2014-06-26 20:53:37 +00:00
|
|
|
RootCmd.AddCommand(pushCmd)
|
2013-10-04 17:09:03 +00:00
|
|
|
}
|