api: add support for deleting apps (#327)

* api: add support for deleting apps

Fixes #274

* functions: improve error name and description

* functions: fix test regression
This commit is contained in:
C Cirello
2016-11-22 01:07:30 +01:00
committed by GitHub
parent be6685b361
commit da96ef471a
5 changed files with 89 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
"text/tabwriter"
@@ -79,6 +80,11 @@ func apps() cli.Command {
},
},
},
{
Name: "delete",
Usage: "delete an app",
Action: a.delete,
},
},
}
}
@@ -249,3 +255,26 @@ func (a *appsCmd) storeApp(appName string, config map[string]string) error {
}
return nil
}
func (a *appsCmd) delete(c *cli.Context) error {
appName := c.Args().First()
if appName == "" {
return errors.New("error: deleting an app takes one argument, an app name")
}
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}
resp, err := a.AppsAppDelete(appName)
if err != nil {
return fmt.Errorf("error deleting app: %v", err)
}
if resp.StatusCode == http.StatusBadRequest {
return errors.New("could not delete this application - pending routes")
}
fmt.Println(appName, "deleted")
return nil
}