forked from revel/revel
/
clean.go
48 lines (39 loc) · 874 Bytes
/
clean.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
46
47
48
package main
import (
"fmt"
"go/build"
"os"
"path"
)
var cmdClean = &Command{
UsageLine: "clean [import path]",
Short: "clean a Revel application's temp files",
Long: `
Clean the Revel web application named by the given import path.
For example:
revel clean github.com/robfig/revel/samples/chat
It removes the app/tmp directory.
`,
}
func init() {
cmdClean.Run = cleanApp
}
func cleanApp(args []string) {
if len(args) == 0 {
fmt.Fprintf(os.Stderr, cmdClean.Long)
return
}
appPkg, err := build.Import(args[0], "", build.FindOnly)
if err != nil {
fmt.Fprintln(os.Stderr, "Abort: Failed to find import path:", err)
return
}
// Remove the app/tmp directory.
tmpDir := path.Join(appPkg.Dir, "app", "tmp")
fmt.Println("Removing:", tmpDir)
err = os.RemoveAll(tmpDir)
if err != nil {
fmt.Fprintln(os.Stderr, "Abort:", err)
return
}
}