mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
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:
29
fn/apps.go
29
fn/apps.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user