Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
feat(cmd): refresh-units accepts -t for tag, branch, or SHA
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Sep 24, 2014
1 parent 731d728 commit a9c98c1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cmd/cmd.go
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -277,10 +278,12 @@ deisctl looks for unit files in these directories, in this order:
- /var/lib/deis/units
Usage:
deisctl refresh-units [-p <target>]
deisctl refresh-units [-p <target>] [-t <tag>]
Options:
-p --path=<target> where to save unit files [default: /var/lib/deis/units]
-t --tag=<tag> git tag, branch, or SHA to use when downloading unit files
[default: master]
`
// parse command-line arguments
args, err := docopt.Parse(usage, nil, true, "", false)
Expand All @@ -295,7 +298,7 @@ Options:
}
// download and save the unit files to the specified path
rootURL := "https://raw.githubusercontent.com/deis/deisctl/"
branch := "master"
tag := args["--tag"].(string)
units := []string{
"deis-builder.service",
"deis-builder-data.service",
Expand All @@ -310,12 +313,15 @@ Options:
"deis-router.service",
}
for _, unit := range units {
src := rootURL + branch + "/units/" + unit
src := rootURL + tag + "/units/" + unit
dest := filepath.Join(dir, unit)
res, err := http.Get(src)
if err != nil {
return err
}
if res.StatusCode != 200 {
return errors.New(res.Status)
}
defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
if err != nil {
Expand All @@ -324,7 +330,7 @@ Options:
if err = ioutil.WriteFile(dest, data, 0644); err != nil {
return err
}
fmt.Printf("Refreshed %s from %s\n", unit, branch)
fmt.Printf("Refreshed %s from %s\n", unit, tag)
}
return nil
}

0 comments on commit a9c98c1

Please sign in to comment.