Skip to content

Commit a5c8a8d

Browse files
committed
revel/revel#1057 code improvements docs, errcheck, cyclo, etc
1 parent 5a57eaa commit a5c8a8d

14 files changed

+228
-127
lines changed

harness/app.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
package harness
26

37
import (

harness/build.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
package harness
26

37
import (

harness/harness.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
// The Harness for a Revel program.
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 harness for a Revel Framework.
26
//
3-
// It has a couple responsibilities:
7+
// It has a following responsibilities:
48
// 1. Parse the user program, generating a main.go file that registers
59
// controller classes and starts the user's server.
610
// 2. Build and run the user program. Show compile errors.
711
// 3. Monitor the user source and re-build / restart the program when necessary.
812
//
913
// Source files are generated in the app/tmp directory.
10-
1114
package harness
1215

1316
import (

harness/reflect.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
package harness
26

37
// This file handles the app code introspection.

harness/reflect_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
package harness
26

37
import (

revel/build.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
package main
26

37
import (
@@ -40,7 +44,7 @@ func buildApp(args []string) {
4044
return
4145
}
4246

43-
appImportPath, destPath, mode := args[0], args[1], "dev"
47+
appImportPath, destPath, mode := args[0], args[1], DefaultRunMode
4448
if len(args) >= 3 {
4549
mode = args[2]
4650
}
@@ -55,8 +59,13 @@ func buildApp(args []string) {
5559
errorf("Abort: %s exists and does not look like a build directory.", destPath)
5660
}
5761

58-
os.RemoveAll(destPath)
59-
os.MkdirAll(destPath, 0777)
62+
if err := os.RemoveAll(destPath); err != nil && !os.IsNotExist(err) {
63+
revel.ERROR.Fatalln(err)
64+
}
65+
66+
if err := os.MkdirAll(destPath, 0777); err != nil {
67+
revel.ERROR.Fatalln(err)
68+
}
6069

6170
app, reverr := harness.Build()
6271
panicOnError(reverr, "Failed to build")
@@ -73,9 +82,9 @@ func buildApp(args []string) {
7382
tmpRevelPath := filepath.Join(srcPath, filepath.FromSlash(revel.RevelImportPath))
7483
mustCopyFile(destBinaryPath, app.BinaryPath)
7584
mustChmod(destBinaryPath, 0755)
76-
mustCopyDir(filepath.Join(tmpRevelPath, "conf"), filepath.Join(revel.RevelPath, "conf"), nil)
77-
mustCopyDir(filepath.Join(tmpRevelPath, "templates"), filepath.Join(revel.RevelPath, "templates"), nil)
78-
mustCopyDir(filepath.Join(srcPath, filepath.FromSlash(appImportPath)), revel.BasePath, nil)
85+
_ = mustCopyDir(filepath.Join(tmpRevelPath, "conf"), filepath.Join(revel.RevelPath, "conf"), nil)
86+
_ = mustCopyDir(filepath.Join(tmpRevelPath, "templates"), filepath.Join(revel.RevelPath, "templates"), nil)
87+
_ = mustCopyDir(filepath.Join(srcPath, filepath.FromSlash(appImportPath)), revel.BasePath, nil)
7988

8089
// Find all the modules used and copy them over.
8190
config := revel.Config.Raw()
@@ -98,7 +107,7 @@ func buildApp(args []string) {
98107
}
99108
}
100109
for importPath, fsPath := range modulePaths {
101-
mustCopyDir(filepath.Join(srcPath, importPath), fsPath, nil)
110+
_ = mustCopyDir(filepath.Join(srcPath, importPath), fsPath, nil)
102111
}
103112

104113
tmplData, runShPath := map[string]interface{}{

revel/clean.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
package main
26

37
import (

revel/new.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
package main
26

37
import (
@@ -199,7 +203,7 @@ func copyNewAppFiles() {
199203
err = os.MkdirAll(appPath, 0777)
200204
panicOnError(err, "Failed to create directory "+appPath)
201205

202-
mustCopyDir(appPath, skeletonPath, map[string]interface{}{
206+
_ = mustCopyDir(appPath, skeletonPath, map[string]interface{}{
203207
// app.conf
204208
"AppName": appName,
205209
"BasePath": basePath,

revel/package.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
package main
26

37
import (
@@ -38,7 +42,7 @@ func packageApp(args []string) {
3842
}
3943

4044
// Determine the run mode.
41-
mode := "dev"
45+
mode := DefaultRunMode
4246
if len(args) >= 2 {
4347
mode = args[1]
4448
}
@@ -48,7 +52,9 @@ func packageApp(args []string) {
4852

4953
// Remove the archive if it already exists.
5054
destFile := filepath.Base(revel.BasePath) + ".tar.gz"
51-
os.Remove(destFile)
55+
if err := os.Remove(destFile); err != nil && !os.IsNotExist(err) {
56+
revel.ERROR.Fatal(err)
57+
}
5258

5359
// Collect stuff in a temp directory.
5460
tmpDir, err := ioutil.TempDir("", filepath.Base(revel.BasePath))

revel/rev.go

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
// The command line tool for running Revel apps.
26
package main
37

@@ -15,12 +19,16 @@ import (
1519
"github.com/agtorre/gocolorize"
1620
)
1721

22+
// DefaultRunMode for revel's application
23+
const DefaultRunMode = "dev"
24+
1825
// Command structure cribbed from the genius organization of the "go" command.
1926
type Command struct {
2027
Run func(args []string)
2128
UsageLine, Short, Long string
2229
}
2330

31+
// Name returns command name from usage line
2432
func (cmd *Command) Name() string {
2533
name := cmd.UsageLine
2634
i := strings.Index(name, " ")

revel/run.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
package main
26

37
import (
@@ -37,7 +41,7 @@ func runApp(args []string) {
3741
}
3842

3943
// Determine the run mode.
40-
mode := "dev"
44+
mode := DefaultRunMode
4145
if len(args) >= 2 {
4246
mode = args[1]
4347
}

0 commit comments

Comments
 (0)