github.com/terhitormanen/cmd@v1.1.4/revel/clean.go (about) 1 // Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved. 2 // Revel Framework source code and usage is governed by a MIT style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "os" 10 "path/filepath" 11 12 "github.com/terhitormanen/cmd/model" 13 "github.com/terhitormanen/cmd/utils" 14 ) 15 16 var cmdClean = &Command{ 17 UsageLine: "clean [import path]", 18 Short: "clean a Revel application's temp files", 19 Long: ` 20 Clean the Revel web application named by the given import path. 21 22 For example: 23 24 revel clean github.com/terhitormanen/examples/chat 25 26 It removes the app/tmp and app/routes directory. 27 28 29 `, 30 } 31 32 func init() { 33 cmdClean.UpdateConfig = updateCleanConfig 34 cmdClean.RunWith = cleanApp 35 } 36 37 // Update the clean command configuration, using old method. 38 func updateCleanConfig(c *model.CommandConfig, args []string) bool { 39 c.Index = model.CLEAN 40 if len(args) == 0 && c.Clean.ImportPath != "" { 41 return true 42 } 43 if len(args) == 0 { 44 fmt.Fprintf(os.Stderr, cmdClean.Long) 45 return false 46 } 47 c.Clean.ImportPath = args[0] 48 return true 49 } 50 51 // Clean the source directory of generated files. 52 func cleanApp(c *model.CommandConfig) (err error) { 53 purgeDirs := []string{ 54 filepath.Join(c.AppPath, "app", "tmp"), 55 filepath.Join(c.AppPath, "app", "routes"), 56 } 57 58 for _, dir := range purgeDirs { 59 fmt.Println("Removing:", dir) 60 err = os.RemoveAll(dir) 61 if err != nil { 62 utils.Logger.Error("Failed to clean dir", "error", err) 63 return 64 } 65 } 66 return err 67 }