Skip to content

Commit

Permalink
go-aah/aah#200 removed cmd switch and update. go1.11 use case update …
Browse files Browse the repository at this point in the history
…on cmd new, migrate and verion
  • Loading branch information
jeevatkm committed Sep 6, 2018
1 parent 2a86d5c commit e47e5a8
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 442 deletions.
4 changes: 2 additions & 2 deletions aah/aah.go
Expand Up @@ -20,8 +20,8 @@ import (
)

const (
permRWXRXRX = 0755
permRWRWRW = 0666
permRWXRXRX = os.FileMode(0755)
permRWRWRW = os.FileMode(0666)
importPrefix = "aahframe.work/aah"
aahImportPath = "aahframe.work/aah"
)
Expand Down
2 changes: 1 addition & 1 deletion aah/compile.go
Expand Up @@ -240,7 +240,7 @@ func checkAndGetAppDeps(appImportPath string, cfg *config.Config) error {
}

args := append([]string{"list"}, debList...)
b, _ := exec.Command(gocmd, args...).CombinedOutput()
b, _ := exec.Command(gocmd, args...).CombinedOutput() // #nosec
notExistsPkgs := []string{}
matches := notExistRegex.FindAllStringSubmatch(string(b), -1)
for _, m := range matches {
Expand Down
61 changes: 28 additions & 33 deletions aah/migrate.go
Expand Up @@ -65,67 +65,62 @@ var migrateCmd = cli.Command{
}

func migrateCodeAction(c *cli.Context) error {
if ess.IsStrEmpty(aahVer) {
logFatalf("Ensure you're in application base directory or supplying import path argument")
if !ess.IsFileExists(aahProjectIdentifier) {
logFatalf("Ensure you're in aah application base directory")
}

grammarFile := filepath.Join(aahPath(), aahGrammarIdentifier)
if err := os.Remove(grammarFile); err != nil && !os.IsNotExist(err) {
logFatal(err)
}
cliLog.Info("Fetching migrate configuration: ", aahGrammarFetchLoc)
if err := fetchFile(grammarFile, aahGrammarFetchLoc); err != nil {
logFatal(err)
}
grammarCfg, err := config.LoadFile(grammarFile)
if err != nil {
logFatal(err)
}
cliLog.Info("Loaded migrate configuration: ", grammarFile)

importPath := appImportPath(c)
if err := aah.Init(importPath); err != nil {
logFatal(err)
}

projectCfg := aahProjectCfg(aah.AppBaseDir())
cliLog.Info("Loaded aah project file: ", filepath.Join(aah.AppBaseDir(), aahProjectIdentifier))
cliLog = initCLILogger(projectCfg)

cliLog.Warn("Migrate command does not take file backup. Command assumes application use version control.")
if c.GlobalBool("y") || c.GlobalBool("yes") {
fmt.Println("\nWould you like to continue? [y/N]: y")
fmt.Println("Would you like to continue? [y/N]: y")
} else if !collectYesOrNo(reader, "Would you like to continue? [y/N]") {
cliLog.Info("Okay, I respect your choice. Bye.")
return nil
}

grammerIdentifier := "migrate-" + strings.Join(strings.Split(Version, ".")[:2], ".") + ".conf"
fmt.Println("grammerIdentifier", grammerIdentifier)

return nil

grammarFile := filepath.Join(aahPath(), aahGrammarIdentifier)
if !ess.IsFileExists(grammarFile) {
cliLog.Info("Fetch migrate configuration from ", aahGrammarFetchLoc)
if err := fetchFile(grammarFile, aahGrammarFetchLoc); err != nil {
logFatal(err)
}
}

grammarCfg, err := config.LoadFile(grammarFile)
if err != nil {
logFatal(err)
}

cliLog.Info("\nNote:")
cliLog.Info("-----")
cliLog.Info("Command works based on `migrate.conf` file. If you identify a new grammar entry, \n" +
cliLog.Info("Command works based on 'migrate.conf' file. If you identify a new grammar entry, \n" +
"create an issue at https://aahframework.org/issues.\n")

cliLog.Infof("Loaded migrate configuration: %s", grammarFile)
cliLog.Infof("Loaded aah project file: %s", filepath.Join(aah.AppBaseDir(), aahProjectIdentifier))
cliLog.Infof("Migrate starts for '%s' [%s]", aah.AppName(), aah.AppImportPath())

// Go Source files
cliLog.Infof("Go source code migrate starts ...")
if migrateGoSrcFiles(projectCfg, grammarCfg) == 0 {
cliLog.Info(" It seems application Go source code are up-to-date")
cliLog.Info(" |-- It seems application Go source code are up-to-date")
} else {
cliLog.Infof("Go source code migrate successful")
}
cliLog.Infof("Go source code migrate successful")

// View files
if ess.IsFileExists(filepath.Join(aah.AppBaseDir(), "views")) {
// View files
cliLog.Infof("View file migrate starts ...")
if migrateViewFiles(projectCfg, grammarCfg) == 0 {
cliLog.Info(" It seems application view files are up-to-date")
cliLog.Info(" |-- It seems application view files are up-to-date")
} else {
cliLog.Infof("View file migrate successful")
}
cliLog.Infof("View file migrate successful")
}

cliLog.Infof("Migrate successful for '%s' [%s]\n", aah.AppName(), aah.AppImportPath())
Expand Down Expand Up @@ -197,7 +192,7 @@ func migrateFile(f string, fixer *strings.Replacer) bool {

if filepath.Ext(f) == ".go" {
// format go src file
var err error
// var err error
if modFileBytes, err = format.Source(modFileBytes); err != nil {
logErrorf("While formating: %s", err)
cliLog.Infof(" |-- skipped: %s", df)
Expand All @@ -213,7 +208,7 @@ func migrateFile(f string, fixer *strings.Replacer) bool {

if err = ioutil.WriteFile(f, modFileBytes, permRWRWRW); err != nil {
logError(err)
cliLog.Infof(" |-- [ERROR] processed: %s", df)
cliLog.Infof(" |-- [ERROR] processing: %s", df)
} else {
cliLog.Infof(" |-- processed: %s", df)
}
Expand Down
32 changes: 22 additions & 10 deletions aah/new.go
Expand Up @@ -7,11 +7,9 @@ package main
import (
"bufio"
"fmt"
"go/build"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -86,7 +84,7 @@ func newAction(c *cli.Context) error {
fmt.Printf("You shall run your application via the command: 'aah run --importpath %s'\n", app.ImportPath)
fmt.Println("\nGo to https://docs.aahframework.org to learn more and customize your aah application.")

aahInventory.AddProject(app.ImportPath, app.BaseDir)
_ = aahInventory.AddProject(app.ImportPath, app.BaseDir)

if app.BasicAuthMode == basicFileRealm {
fmt.Println("\nNext step:")
Expand Down Expand Up @@ -503,8 +501,7 @@ func checkAndGenerateInitgoFile(importPath, baseDir string) {

appTmplBaseDir := inferAppTmplBaseDir()
if ess.IsStrEmpty(appTmplBaseDir) {
aahToolsPath := aahToolsPath()
appTmplBaseDir = filepath.Join(aahToolsPath.Dir, "app-template")
logFatal("Unable to find aah app template at $HOME/.aah/app-templates")
}
appType := typeAPI
if ess.IsFileExists(filepath.Join(baseDir, "views")) {
Expand All @@ -524,10 +521,25 @@ func checkAndGenerateInitgoFile(importPath, baseDir string) {
}
}

func aahToolsPath() *build.Package {
aahToolsPath, err := build.Import(path.Join(libImportPath("tools"), "aah"), "", build.FindOnly)
if err != nil {
logFatal(err)
func inferAppTmplBaseDir() string {
aahBasePath := aahPath()
baseDir := filepath.Join(aahBasePath, "app-templates", "generic")
if ess.IsFileExists(baseDir) {
if err := gitPull(baseDir); err == nil {
return baseDir
}
if err := os.RemoveAll(baseDir); err != nil {
logError(err)
return ""
}
}

tmplRepo := "https://github.com/go-aah/app-templates.git"
cliLog.Infof("Downloading aah quick start app templates from %s", tmplRepo)
gitArgs := []string{"clone", tmplRepo, filepath.Dir(baseDir)}
if _, err := execCmd(gitcmd, gitArgs, false); err != nil {
logErrorf("Unable to download aah app-template from %s", tmplRepo)
return ""
}
return aahToolsPath
return baseDir
}
171 changes: 0 additions & 171 deletions aah/switch.go

This file was deleted.

0 comments on commit e47e5a8

Please sign in to comment.