/
destroy.go
45 lines (36 loc) · 1018 Bytes
/
destroy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package apps
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/io"
"gopkg.in/errgo.v1"
)
func Destroy(appName string) error {
var validationName string
c, err := config.ScalingoClient()
if err != nil {
return errgo.Notef(err, "fail to get Scalingo client")
}
_, err = c.AppsShow(appName)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
fmt.Printf("/!\\ You're going to delete %s, this operation is irreversible.\nTo confirm type the name of the application: ", appName)
validationName, err = bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
return errgo.Mask(err, errgo.Any)
}
validationName = strings.Trim(validationName, "\n")
if validationName != appName {
return errgo.Newf("'%s' is not '%s', aborting…\n", validationName, appName)
}
err = c.AppsDestroy(appName, validationName)
if err != nil {
return errgo.Notef(err, "fail to destroy app")
}
io.Status("App " + appName + " has been deleted")
return nil
}