Tool updates

Updated tool to give more meaningful errors
Added file system as an option to fetch the skeleton from
This commit is contained in:
NotZippy
2018-10-18 17:07:48 -07:00
parent 554e62574d
commit 87c9e56322
6 changed files with 73 additions and 30 deletions

View File

@@ -65,7 +65,7 @@ func newApp(name string, command model.COMMAND, precall func(c *model.CommandCon
if precall != nil {
precall(c)
}
if !c.UpdateImportPath() {
if c.UpdateImportPath()!=nil {
a.Fail("Unable to update import path")
}
c.InitGoPaths()

View File

@@ -65,6 +65,13 @@ func newApp(c *model.CommandConfig) (err error) {
if err == nil || !utils.Empty(c.AppPath) {
return utils.NewBuildError("Abort: Import path already exists.", "path", c.ImportPath)
}
// checking and setting skeleton
if err=setSkeletonPath(c);err!=nil {
return
}
// Create application path
if err := os.MkdirAll(c.AppPath, os.ModePerm); err != nil {
return utils.NewBuildError("Abort: Unable to create app path.", "path", c.AppPath)
}
@@ -115,18 +122,12 @@ func newApp(c *model.CommandConfig) (err error) {
}
// checking and setting application
if err = setApplicationPath(c); err != nil {
return err
}
// At this point the versions can be set
c.SetVersions()
// checking and setting skeleton
if err=setSkeletonPath(c);err!=nil {
return
}
// copy files to new app directory
if err = copyNewAppFiles(c);err != nil {
return
@@ -201,11 +202,28 @@ func setSkeletonPath(c *model.CommandConfig) (err error) {
}
// First check to see the protocol of the string
if sp, err := url.Parse(c.New.SkeletonPath); err == nil {
sp, err := url.Parse(c.New.SkeletonPath)
if err == nil {
utils.Logger.Info("Detected skeleton path", "path", sp)
switch strings.ToLower(sp.Scheme) {
// TODO Add support for https, http, ftp, file
// TODO Add support for https, http, ftp
case "" :
sp.Scheme="file"
fallthrough
case "file" :
fullpath := sp.String()[7:]
if !filepath.IsAbs(fullpath) {
fullpath, err = filepath.Abs(fullpath)
if err!=nil {
return
}
}
c.New.SkeletonPath = fullpath
utils.Logger.Info("Set skeleton path to ", fullpath)
if !utils.DirExists(fullpath) {
return fmt.Errorf("Failed to find skeleton in filepath %s %s", fullpath, sp.String())
}
case "git":
if err := newLoadFromGit(c, sp); err != nil {
return err
@@ -237,7 +255,7 @@ func newLoadFromGit(c *model.CommandConfig, sp *url.URL) (err error) {
utils.Logger.Info("Exec:", "args", getCmd.Args)
getOutput, err := getCmd.CombinedOutput()
if err != nil {
utils.Logger.Fatal("Abort: could not clone the Skeleton source code: ","output", getOutput, "path", c.New.SkeletonPath)
utils.Logger.Fatal("Abort: could not clone the Skeleton source code: ","output", string(getOutput), "path", c.New.SkeletonPath)
}
outputPath := targetPath
if len(pathpart) > 1 {

View File

@@ -20,6 +20,7 @@ import (
"github.com/revel/cmd/logger"
"github.com/revel/cmd/model"
"github.com/revel/cmd/utils"
"bytes"
)
const (
@@ -70,14 +71,17 @@ func main() {
wd, _ := os.Getwd()
utils.InitLogger(wd, logger.LvlError)
parser := flags.NewParser(c, flags.HelpFlag|flags.PassDoubleDash)
if err := ParseArgs(c, parser, os.Args[1:]); err != nil {
fmt.Fprint(os.Stderr, err.Error())
if len(os.Args)<2 {
parser.WriteHelp(os.Stdout)
os.Exit(1)
}
if err := ParseArgs(c, parser, os.Args[1:]); err != nil {
fmt.Fprint(os.Stderr, err.Error() +"\n")
os.Exit(1)
}
// Switch based on the verbose flag
if len(c.Verbose)>1 {
utils.InitLogger(wd, logger.LvlDebug)
@@ -87,8 +91,10 @@ func main() {
utils.InitLogger(wd, logger.LvlWarn)
}
if !c.UpdateImportPath() {
utils.Logger.Fatal("Unable to determine application path")
if err := c.UpdateImportPath();err!=nil {
utils.Logger.Error(err.Error())
parser.WriteHelp(os.Stdout)
os.Exit(1)
}
command := Commands[c.Index]
@@ -136,12 +142,12 @@ func ParseArgs(c *model.CommandConfig, parser *flags.Parser, args []string) (err
}
}
if c.Index == 0 {
err = fmt.Errorf("Unknown command %v", extraArgs)
} else if len(extraArgs) > 0 {
if len(extraArgs) > 0 {
utils.Logger.Info("Found additional arguements, setting them")
if !Commands[c.Index].UpdateConfig(c, extraArgs) {
err = fmt.Errorf("Invalid command line arguements %v", extraArgs)
buffer := &bytes.Buffer{}
parser.WriteHelp(buffer)
err = fmt.Errorf("Invalid command line arguements %v\n%s", extraArgs, buffer.String())
}
}

View File

@@ -13,6 +13,7 @@ import (
"github.com/revel/cmd/utils"
"go/build"
"os"
"path/filepath"
)
var cmdRun = &Command{
@@ -72,7 +73,7 @@ func updateRunConfig(c *model.CommandConfig, args []string) bool {
// 3. revel run [run-mode] [port]
// Check to see if the import path evaluates out to something that may be on a gopath
if _, err := build.Import(args[0], "", build.FindOnly); err == nil {
if runIsImportPath(args[0]) {
// 1st arg is the import path
c.Run.ImportPath = args[0]
@@ -93,12 +94,7 @@ func updateRunConfig(c *model.CommandConfig, args []string) bool {
// 1. revel run [import-path]
// 2. revel run [port]
// 3. revel run [run-mode]
_, err := build.Import(args[0], "", build.FindOnly)
if err != nil {
utils.Logger.Warn("Unable to run using an import path, assuming import path is working directory %s %s", "Argument", args[0], "error", err.Error())
}
utils.Logger.Info("Trying to build with", args[0], err)
if err == nil {
if runIsImportPath(args[0]) {
// 1st arg is the import path
c.Run.ImportPath = args[0]
} else if _, err := strconv.Atoi(args[0]); err == nil {
@@ -116,6 +112,14 @@ func updateRunConfig(c *model.CommandConfig, args []string) bool {
return true
}
// Returns true if this is an absolute path or a relative gopath
func runIsImportPath(pathToCheck string) bool {
if _, err := build.Import(pathToCheck, "", build.FindOnly);err==nil {
return true
}
return filepath.IsAbs(pathToCheck)
}
// Called to run the app
func runApp(c *model.CommandConfig) (err error) {
if c.Run.Mode == "" {