add initial out command

This commit is contained in:
Chris Brown
2015-01-31 23:04:49 +00:00
parent 6780afd2ca
commit a36b7368e7
6 changed files with 289 additions and 0 deletions

45
out_command.go Normal file
View File

@@ -0,0 +1,45 @@
package resource
import (
"os"
"path/filepath"
"github.com/google/go-github/github"
)
type OutCommand struct {
github GitHub
}
func NewOutCommand(github GitHub) *OutCommand {
return &OutCommand{
github: github,
}
}
func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, error) {
params := request.Params
release := &github.RepositoryRelease{}
createdRelease, err := c.github.CreateRelease(release)
if err != nil {
return OutResponse{}, err
}
for _, filePath := range params.Globs {
file, err := os.Open(filePath)
if err != nil {
return OutResponse{}, err
}
name := filepath.Base(filePath)
err = c.github.UploadReleaseAsset(createdRelease, name, file)
if err != nil {
return OutResponse{}, err
}
file.Close()
}
return OutResponse{}, nil
}