/
clean.go
67 lines (54 loc) · 1.43 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
// Revel Framework source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/revel/cmd/model"
"github.com/revel/cmd/utils"
)
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/revel/examples/chat
It removes the app/tmp and app/routes directory.
`,
}
func init() {
cmdClean.UpdateConfig = updateCleanConfig
cmdClean.RunWith = cleanApp
}
// Update the clean command configuration, using old method.
func updateCleanConfig(c *model.CommandConfig, args []string) bool {
c.Index = model.CLEAN
if len(args) == 0 && c.Clean.ImportPath != "" {
return true
}
if len(args) == 0 {
fmt.Fprintf(os.Stderr, cmdClean.Long)
return false
}
c.Clean.ImportPath = args[0]
return true
}
// Clean the source directory of generated files.
func cleanApp(c *model.CommandConfig) (err error) {
purgeDirs := []string{
filepath.Join(c.AppPath, "app", "tmp"),
filepath.Join(c.AppPath, "app", "routes"),
}
for _, dir := range purgeDirs {
fmt.Println("Removing:", dir)
err = os.RemoveAll(dir)
if err != nil {
utils.Logger.Error("Failed to clean dir", "error", err)
return
}
}
return err
}