diff --git a/model/command/build.go b/model/command/build.go new file mode 100644 index 0000000..61e3cbb --- /dev/null +++ b/model/command/build.go @@ -0,0 +1,10 @@ +package command +type ( + Build struct { + ImportCommand + TargetPath string `short:"t" long:"target-path" description:"Path to target folder. Folder will be completely deleted if it exists" required:"false"` + Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"` + CopySource bool `short:"s" long:"include-source" description:"Copy the source code as well"` + } + +) diff --git a/model/command/clean.go b/model/command/clean.go new file mode 100644 index 0000000..644cca7 --- /dev/null +++ b/model/command/clean.go @@ -0,0 +1,6 @@ +package command +type ( + Clean struct { + ImportCommand + } +) diff --git a/model/command/import_command.go b/model/command/import_command.go new file mode 100644 index 0000000..8e86f29 --- /dev/null +++ b/model/command/import_command.go @@ -0,0 +1,7 @@ +package command + +type ( + ImportCommand struct { + ImportPath string `short:"a" long:"application-path" description:"Path to application folder" required:"false"` + } +) diff --git a/model/command/new.go b/model/command/new.go new file mode 100644 index 0000000..25f3de2 --- /dev/null +++ b/model/command/new.go @@ -0,0 +1,11 @@ +package command +type ( + New struct { + ImportCommand + SkeletonPath string `short:"s" long:"skeleton" description:"Path to skeleton folder (Must exist on GO PATH)" required:"false"` + Package string `short:"p" long:"package" description:"The package name, this becomes the repfix to the app name, if defined vendored is set to true" required:"false"` + NotVendored bool `short:"V" long:"vendor" description:"True if project should not be configured with a go.mod"` + Run bool `short:"r" long:"run" description:"True if you want to run the application right away"` + } + +) \ No newline at end of file diff --git a/model/command/package.go b/model/command/package.go new file mode 100644 index 0000000..264ea12 --- /dev/null +++ b/model/command/package.go @@ -0,0 +1,9 @@ +package command +type ( + Package struct { + ImportCommand + TargetPath string `short:"t" long:"target-path" description:"Full path and filename of target package to deploy" required:"false"` + Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"` + CopySource bool `short:"s" long:"include-source" description:"Copy the source code as well"` + } +) \ No newline at end of file diff --git a/model/command/run.go b/model/command/run.go new file mode 100644 index 0000000..1c745e6 --- /dev/null +++ b/model/command/run.go @@ -0,0 +1,9 @@ +package command +type ( + Run struct { + ImportCommand + Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"` + Port int `short:"p" long:"port" default:"-1" description:"The port to listen" ` + NoProxy bool `short:"n" long:"no-proxy" description:"True if proxy server should not be started. This will only update the main and routes files on change"` + } +) \ No newline at end of file diff --git a/model/command/test_command.go b/model/command/test_command.go new file mode 100644 index 0000000..0822441 --- /dev/null +++ b/model/command/test_command.go @@ -0,0 +1,9 @@ +package command + +type ( + Test struct { + ImportCommand + Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"` + Function string `short:"f" long:"suite-function" description:"The suite.function"` + } +) \ No newline at end of file diff --git a/model/command/version.go b/model/command/version.go new file mode 100644 index 0000000..627f505 --- /dev/null +++ b/model/command/version.go @@ -0,0 +1,7 @@ +package command +type ( + Version struct { + ImportCommand + Update bool `short:"u" long:"Update the framework and modules" required:"false"` + } +) diff --git a/model/command_config.go b/model/command_config.go index ef1fd9a..db248f3 100644 --- a/model/command_config.go +++ b/model/command_config.go @@ -14,6 +14,7 @@ import ( "os/exec" "path/filepath" "strings" + "github.com/revel/cmd/model/command" ) // The constants @@ -48,50 +49,20 @@ type ( Vendored bool // True if the application is vendored PackageResolver func(pkgName string) error // a packge resolver for the config BuildFlags []string `short:"X" long:"build-flags" description:"These flags will be used when building the application. May be specified multiple times, only applicable for Build, Run, Package, Test commands"` - // The new command - New struct { - ImportPath string `short:"a" long:"application-path" description:"Path to application folder" required:"false"` - SkeletonPath string `short:"s" long:"skeleton" description:"Path to skeleton folder (Must exist on GO PATH)" required:"false"` - Package string `short:"p" long:"package" description:"The package name, this becomes the repfix to the app name, if defined vendored is set to true" required:"false"` - NotVendored bool `short:"V" long:"vendor" description:"True if project should not be configured with a go.mod"` - Run bool `short:"r" long:"run" description:"True if you want to run the application right away"` - } `command:"new"` + + New command.New `command:"new"` // The new command // The build command - Build struct { - TargetPath string `short:"t" long:"target-path" description:"Path to target folder. Folder will be completely deleted if it exists" required:"false"` - ImportPath string `short:"a" long:"application-path" description:"Path to application folder" required:"false"` - Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"` - CopySource bool `short:"s" long:"include-source" description:"Copy the source code as well"` - } `command:"build"` + Build command.Build `command:"build"` // The run command - Run struct { - ImportPath string `short:"a" long:"application-path" description:"Path to application folder" required:"false"` - Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"` - Port int `short:"p" long:"port" default:"-1" description:"The port to listen" ` - NoProxy bool `short:"n" long:"no-proxy" description:"True if proxy server should not be started. This will only update the main and routes files on change"` - } `command:"run"` + Run command.Run `command:"run"` // The package command - Package struct { - TargetPath string `short:"t" long:"target-path" description:"Full path and filename of target package to deploy" required:"false"` - Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"` - ImportPath string `short:"a" long:"application-path" description:"Path to application folder" required:"false"` - CopySource bool `short:"s" long:"include-source" description:"Copy the source code as well"` - } `command:"package"` + Package command.Package `command:"package"` // The clean command - Clean struct { - ImportPath string `short:"a" long:"application-path" description:"Path to application folder" required:"false"` - } `command:"clean"` + Clean command.Clean `command:"clean"` // The test command - Test struct { - Mode string `short:"m" long:"run-mode" description:"The mode to run the application in"` - ImportPath string `short:"a" long:"application-path" description:"Path to application folder" required:"false"` - Function string `short:"f" long:"suite-function" description:"The suite.function"` - } `command:"test"` + Test command.Test `command:"test"` // The version command - Version struct { - ImportPath string `short:"a" long:"application-path" description:"Path to application folder" required:"false"` - Update bool `short:"u" long:"Update the framework and modules" required:"false"` - } `command:"version"` + Version command.Version `command:"version"` } ) diff --git a/revel/clean.go b/revel/clean.go index 6f428bd..285ea93 100644 --- a/revel/clean.go +++ b/revel/clean.go @@ -8,7 +8,7 @@ import ( "fmt" "github.com/revel/cmd/model" "github.com/revel/cmd/utils" - "go/build" + "os" "path/filepath" ) @@ -50,14 +50,10 @@ func updateCleanConfig(c *model.CommandConfig, args []string) bool { // Clean the source directory of generated files func cleanApp(c *model.CommandConfig) (err error) { - appPkg, err := build.Import(c.ImportPath, "", build.FindOnly) - if err != nil { - utils.Logger.Fatal("Abort: Failed to find import path:", "error", err) - } purgeDirs := []string{ - filepath.Join(appPkg.Dir, "app", "tmp"), - filepath.Join(appPkg.Dir, "app", "routes"), + filepath.Join(c.AppPath, "app", "tmp"), + filepath.Join(c.AppPath, "app", "routes"), } for _, dir := range purgeDirs {