git-lfs/commands/command_push.go

60 lines
1.1 KiB
Go
Raw Normal View History

package commands
2013-10-04 17:09:03 +00:00
import (
"fmt"
"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",
Short: "Push files to the media endpoint.",
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")
}
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)
}
if err != nil {
2014-06-05 19:05:02 +00:00
Panic(err, "error uploading file %s/%s", sha, filename)
}
err = gitmediaclient.Put(path, filename)
if err != nil {
2014-06-05 19:05:02 +00:00
Panic(err, "error uploading file %s/%s", sha, filename)
}
fmt.Printf("\n")
2013-10-21 18:42:29 +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:25:24 +00:00
return nil
})
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
}