mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-11 18:54:31 +00:00
Patchset for 21
Added Version -u to update the checked out libaraies Enhanced new skeleton toto support http https and git schemas when cloning the skeleton repo. Enhanced version command to fetch server version from master branch Enhanced version command to update local repository if a new version exists on the server
This commit is contained in:
@@ -44,6 +44,7 @@ type (
|
||||
SrcRoot string // The source root
|
||||
AppPath string // The application path (absolute)
|
||||
AppName string // The application name
|
||||
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
|
||||
@@ -87,6 +88,7 @@ type (
|
||||
// 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"`
|
||||
}
|
||||
)
|
||||
@@ -124,7 +126,6 @@ func (c *CommandConfig) UpdateImportPath() error {
|
||||
}
|
||||
// For an absolute path
|
||||
currentPath, _ = filepath.Abs(importPath)
|
||||
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@@ -136,7 +137,10 @@ func (c *CommandConfig) UpdateImportPath() error {
|
||||
if len(importPath) > 4 && strings.ToLower(importPath[0:4]) == "src/" {
|
||||
importPath = importPath[4:]
|
||||
} else if importPath == "src" {
|
||||
return fmt.Errorf("Invlaid import path, working dir is in GOPATH root")
|
||||
if c.Index != VERSION {
|
||||
return fmt.Errorf("Invlaid import path, working dir is in GOPATH root")
|
||||
}
|
||||
importPath = ""
|
||||
}
|
||||
utils.Logger.Info("Updated import path", "path", importPath)
|
||||
}
|
||||
@@ -167,18 +171,19 @@ func (c *CommandConfig) UpdateImportPath() error {
|
||||
|
||||
// Used to initialize the package resolver
|
||||
func (c *CommandConfig) InitPackageResolver() {
|
||||
useVendor := utils.DirExists(filepath.Join(c.AppPath, "vendor"))
|
||||
c.Vendored = utils.DirExists(filepath.Join(c.AppPath, "vendor"))
|
||||
if c.Index == NEW && c.New.Vendored {
|
||||
useVendor = true
|
||||
c.Vendored = true
|
||||
}
|
||||
utils.Logger.Info("InitPackageResolver", "useVendor", useVendor, "path", c.AppPath)
|
||||
|
||||
utils.Logger.Info("InitPackageResolver", "useVendor", c.Vendored, "path", c.AppPath)
|
||||
|
||||
var (
|
||||
depPath string
|
||||
err error
|
||||
)
|
||||
|
||||
if useVendor {
|
||||
if c.Vendored {
|
||||
utils.Logger.Info("Vendor folder detected, scanning for deps in path")
|
||||
depPath, err = exec.LookPath("dep")
|
||||
if err != nil {
|
||||
@@ -194,8 +199,8 @@ func (c *CommandConfig) InitPackageResolver() {
|
||||
//useVendor := utils.DirExists(filepath.Join(c.AppPath, "vendor"))
|
||||
|
||||
var getCmd *exec.Cmd
|
||||
utils.Logger.Info("Request for package ", "package", pkgName, "use vendor", useVendor)
|
||||
if useVendor {
|
||||
utils.Logger.Info("Request for package ", "package", pkgName, "use vendor", c.Vendored)
|
||||
if c.Vendored {
|
||||
utils.Logger.Info("Using dependency manager to import package", "package", pkgName)
|
||||
|
||||
if depPath == "" {
|
||||
@@ -206,7 +211,15 @@ func (c *CommandConfig) InitPackageResolver() {
|
||||
utils.Logger.Error("Missing package", "package", pkgName)
|
||||
return fmt.Errorf("Missing package %s", pkgName)
|
||||
}
|
||||
getCmd = exec.Command(depPath, "ensure", "-add", pkgName)
|
||||
// Check to see if the package exists locally
|
||||
_, err := build.Import(pkgName, c.AppPath, build.FindOnly)
|
||||
if err != nil {
|
||||
getCmd = exec.Command(depPath, "ensure", "-add", pkgName)
|
||||
} else {
|
||||
getCmd = exec.Command(depPath, "ensure", "-update", pkgName)
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
utils.Logger.Info("No vendor folder detected, not using dependency manager to import package", "package", pkgName)
|
||||
getCmd = exec.Command(c.GoCmd, "get", "-u", pkgName)
|
||||
@@ -225,6 +238,7 @@ func (c *CommandConfig) InitPackageResolver() {
|
||||
|
||||
// lookup and set Go related variables
|
||||
func (c *CommandConfig) InitGoPaths() {
|
||||
utils.Logger.Info("InitGoPaths")
|
||||
// lookup go path
|
||||
c.GoPath = build.Default.GOPATH
|
||||
if c.GoPath == "" {
|
||||
|
||||
@@ -92,6 +92,7 @@ func (w *WrappedRevelCallback) PackageResolver(pkgName string) error {
|
||||
|
||||
// RevelImportPath Revel framework import path
|
||||
var RevelImportPath = "github.com/revel/revel"
|
||||
var RevelModulesImportPath = "github.com/revel/modules"
|
||||
|
||||
// This function returns a container object describing the revel application
|
||||
// eventually this type of function will replace the global variables.
|
||||
@@ -226,7 +227,7 @@ func (rp *RevelContainer) loadModules(callback RevelCallback) (err error) {
|
||||
|
||||
modulePath, err := rp.ResolveImportPath(moduleImportPath)
|
||||
if err != nil {
|
||||
utils.Logger.Info("Missing module ", "module", moduleImportPath, "error",err)
|
||||
utils.Logger.Info("Missing module ", "module_import_path", moduleImportPath, "error",err)
|
||||
callback.PackageResolver(moduleImportPath)
|
||||
modulePath, err = rp.ResolveImportPath(moduleImportPath)
|
||||
if err != nil {
|
||||
|
||||
@@ -13,6 +13,8 @@ type Version struct {
|
||||
Minor int
|
||||
Maintenance int
|
||||
Suffix string
|
||||
BuildDate string
|
||||
MinGoVersion string
|
||||
}
|
||||
|
||||
// The compatibility list
|
||||
@@ -27,6 +29,13 @@ var versionRegExp = regexp.MustCompile(`([^\d]*)?([0-9]*)\.([0-9]*)(\.([0-9]*))?
|
||||
// Parse the version and return it as a Version object
|
||||
func ParseVersion(version string) (v *Version, err error) {
|
||||
|
||||
v = &Version{}
|
||||
return v, v.ParseVersion(version)
|
||||
}
|
||||
|
||||
// Parse the version and return it as a Version object
|
||||
func (v *Version)ParseVersion(version string) (err error) {
|
||||
|
||||
parsedResult := versionRegExp.FindAllStringSubmatch(version, -1)
|
||||
if len(parsedResult) != 1 {
|
||||
err = errors.Errorf("Invalid version %s", version)
|
||||
@@ -36,7 +45,7 @@ func ParseVersion(version string) (v *Version, err error) {
|
||||
err = errors.Errorf("Invalid version %s", version)
|
||||
return
|
||||
}
|
||||
v = &Version{}
|
||||
|
||||
v.Prefix = parsedResult[0][1]
|
||||
v.Major = v.intOrZero(parsedResult[0][2])
|
||||
v.Minor = v.intOrZero(parsedResult[0][3])
|
||||
@@ -45,7 +54,6 @@ func ParseVersion(version string) (v *Version, err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Returns 0 or an int value for the string, errors are returned as 0
|
||||
func (v *Version) intOrZero(input string) (value int) {
|
||||
if input != "" {
|
||||
@@ -105,6 +113,12 @@ func (v *Version) Newer(o *Version) bool {
|
||||
}
|
||||
|
||||
// Convert the version to a string
|
||||
func (v *Version) String() string {
|
||||
func (v *Version) VersionString() string {
|
||||
return fmt.Sprintf("%s%d.%d.%d%s", v.Prefix, v.Major, v.Minor, v.Maintenance, v.Suffix)
|
||||
}
|
||||
|
||||
// Convert the version build date and go version to a string
|
||||
func (v *Version) String() string {
|
||||
return fmt.Sprintf("Version: %s%d.%d.%d%s\nBuild Date: %s\n Minimium Go Version: %s",
|
||||
v.Prefix, v.Major, v.Minor, v.Maintenance, v.Suffix, v.BuildDate, v.MinGoVersion)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user