Add offline mode for get
Signed-off-by: jolheiser <john.olheiser@gmail.com>pull/1/head
parent
e4eeb190b9
commit
41750c0200
15
cmd/get.go
15
cmd/get.go
|
@ -22,6 +22,10 @@ var Get = cli.Command{
|
|||
Name: "ignore-local",
|
||||
Usage: "Ignore local packages",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "offline",
|
||||
Usage: "Offline mode, return error instead of querying server",
|
||||
},
|
||||
},
|
||||
Action: doGet,
|
||||
}
|
||||
|
@ -44,9 +48,9 @@ func doGet(ctx *cli.Context) error {
|
|||
local := config.PackageMap()
|
||||
for _, pkg := range pkgs {
|
||||
var url string
|
||||
if u, ok := local[pkg]; ok {
|
||||
if u, ok := local[pkg]; ok && !ctx.Bool("ignore-local") {
|
||||
url = u
|
||||
} else {
|
||||
} else if !ctx.Bool("offline") {
|
||||
u, err := queryServer(ctx.String("url"), pkg)
|
||||
if err != nil {
|
||||
beaver.Error(err)
|
||||
|
@ -55,6 +59,11 @@ func doGet(ctx *cli.Context) error {
|
|||
url = u
|
||||
}
|
||||
|
||||
if url == "" {
|
||||
beaver.Errorf("no package found for `%s`", pkg)
|
||||
continue
|
||||
}
|
||||
|
||||
beaver.Infof("getting `%s`...", pkg)
|
||||
if err := goGet(url); err != nil {
|
||||
beaver.Error(err)
|
||||
|
@ -72,7 +81,7 @@ func queryServer(server, name string) (string, error) {
|
|||
endpoint := fmt.Sprintf("%s/%s", server, name)
|
||||
resp, err := http.Get(endpoint)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
return "", fmt.Errorf("could not query server at `%s`", endpoint)
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
|
Loading…
Reference in New Issue