Add offline mode for get

Signed-off-by: jolheiser <john.olheiser@gmail.com>
pull/1/head
jolheiser 2020-02-19 11:29:42 -06:00
parent e4eeb190b9
commit 41750c0200
No known key found for this signature in database
GPG Key ID: 83E486E71AFEB820
1 changed files with 12 additions and 3 deletions

View File

@ -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 {