Skip to content

Commit

Permalink
Merge pull request #18 for v0.12.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Jul 9, 2018
2 parents 4f863f5 + 17cb56d commit 536f960
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 161 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ aah - A secure, flexible, rapid Go web framework.

### News

* aah CLI <a href="https://github.com/go-aah/tools/releases/latest"><img src="https://img.shields.io/badge/version-0.11.0-blue.svg" alt="Release Version"></a> [released](https://github.com/go-aah/tools/releases/latest) and tagged on Jul 06, 2018.
* aah CLI <a href="https://github.com/go-aah/tools/releases/latest"><img src="https://img.shields.io/badge/version-0.12.0-blue.svg" alt="Release Version"></a> [released](https://github.com/go-aah/tools/releases/latest) and tagged on Jul 08, 2018.

Visit official website https://aahframework.org to learn more about `aah` framework.
42 changes: 16 additions & 26 deletions aah/aah.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ var (
var errStopHere = errors.New("stop here")

func checkPrerequisites() error {
gocmdName := goCmdName()
// check go is installed or not
if !ess.LookExecutable("go") {
return errors.New("Unable to find Go executable in PATH")
if !ess.LookExecutable(gocmdName) {
return fmt.Errorf("Unable to find '%s' executable in PATH", gocmdName)
}

var err error
Expand All @@ -61,36 +62,16 @@ func checkPrerequisites() error {
}

// Go executable
gocmdName := goCmdName()
if gocmd, err = exec.LookPath(gocmdName); err != nil {
return err
}

gosrcDir = filepath.Join(gopath, "src")

// git
if gitcmd, err = exec.LookPath("git"); err != nil {
return err
}

// aah
if aahVer, err = aahVersion(); err == errVersionNotExists {
if collectYesOrNo(reader, "aah framework is not installed in GOPATH, would you like to install [Y]es or [N]o") {
args := []string{"get"}
if gocmdName == "go" {
args = append(args, "-u")
}
args = append(args, "aahframework.org/aah.v0")
if _, err := execCmd(gocmd, args, false); err != nil {
return err
}
aahVer, _ = aahVersion()
fmt.Printf("\naah framework successfully installed in GOPATH\n\n")
return nil
}
fmt.Printf("\nOkay, you could do it manually, run '%s get aahframework.org/aah.v0'\n", gocmdName)
return errStopHere
}
gosrcDir = filepath.Join(gopath, "src")

return nil
}
Expand Down Expand Up @@ -135,6 +116,14 @@ func main() {
migrateCmd,
}

// Global flags
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "y, yes",
Usage: `Automatic yes to prompts. Assume "yes" as answer to all prompts and run non-interactively.`,
},
}

sort.Sort(cli.FlagsByName(app.Flags))
_ = app.Run(os.Args)
}
Expand All @@ -144,13 +133,14 @@ func main() {
//___________________________________

func printHeader(c *cli.Context) error {
hdrCont := fmt.Sprintf("aah framework v%s", aahVer)
aahVer, _ = aahVersion(c)
hdr := fmt.Sprintf("aah framework v%s", aahVer)
improveRpt := "# Report improvements/bugs at https://aahframework.org/issues #"
cnt := len(improveRpt)
sp := (cnt - len(hdrCont)) / 2
sp := ((cnt - len(hdr)) / 2) - 1

fmt.Println(chr2str("-", cnt))
fmt.Println(chr2str(" ", sp) + hdrCont)
fmt.Println(chr2str(" ", sp) + hdr)
fmt.Println(chr2str("-", cnt))
fmt.Printf(improveRpt + "\n\n")

Expand Down
30 changes: 6 additions & 24 deletions aah/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package main

import (
"bufio"
"bytes"
"errors"
"fmt"
Expand Down Expand Up @@ -232,30 +231,12 @@ var notExistRegex = regexp.MustCompile(`cannot find package "(.*)" in any of`)
// go list -f '{{ join .Imports "\n" }}' aah-app/import/path/app/...
//
func checkAndGetAppDeps(appImportPath string, cfg *config.Config) error {
importPath := path.Join(appImportPath, "app", "...")
args := []string{"list", "-f", "{{.Imports}}", importPath}
output, err := execCmd(gocmd, args, false)
if err != nil {
return err
}

pkgList := make(map[string]string)
replacer := strings.NewReplacer("[", "", "]", "")
scanner := bufio.NewScanner(strings.NewReader(output))
for scanner.Scan() {
if ln := replacer.Replace(strings.TrimSpace(scanner.Text())); ln != "" {
for _, p := range strings.Fields(ln) {
if p := strings.TrimSpace(p); p != "" {
pkgList[p] = p
}
}
}
debList := libDependencyImports(path.Join(appImportPath, "app", "..."))
if len(debList) == 0 {
return nil
}

args = []string{"list"}
for _, p := range pkgList {
args = append(args, p)
}
args := append([]string{"list"}, debList...)
b, _ := exec.Command(gocmd, args...).CombinedOutput()
notExistsPkgs := []string{}
matches := notExistRegex.FindAllStringSubmatch(string(b), -1)
Expand All @@ -264,7 +245,8 @@ func checkAndGetAppDeps(appImportPath string, cfg *config.Config) error {
}

if cfg.BoolDefault("build.dep_get", true) && len(notExistsPkgs) > 0 {
cliLog.Info("Getting application dependencies ...", notExistsPkgs)
cliLog.Infof("Getting application dependencies ...\n---> %s",
strings.Join(notExistsPkgs, "\n---> "))
if err := goGet(notExistsPkgs...); err != nil {
return err
}
Expand Down
15 changes: 10 additions & 5 deletions aah/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func generateSystemdScript(c *cli.Context) error {

fileName := fmt.Sprintf("%s.service", aah.AppName())
destFile := filepath.Join(aah.AppBaseDir(), fileName)
if checkAndConfirmOverwrite(destFile) {
if checkAndConfirmOverwrite(c, destFile) {
return nil
}

Expand Down Expand Up @@ -143,13 +143,13 @@ func generateDockerScript(c *cli.Context) error {

devFileName := "Dockerfile.dev"
devDestFile := filepath.Join(aah.AppBaseDir(), devFileName)
if checkAndConfirmOverwrite(devDestFile) {
if checkAndConfirmOverwrite(c, devDestFile) {
return nil
}

prodFileName := "Dockerfile.prod"
prodDestFile := filepath.Join(aah.AppBaseDir(), prodFileName)
if checkAndConfirmOverwrite(prodDestFile) {
if checkAndConfirmOverwrite(c, prodDestFile) {
return nil
}

Expand Down Expand Up @@ -198,12 +198,17 @@ func generateDockerScript(c *cli.Context) error {
return nil
}

func checkAndConfirmOverwrite(destFile string) bool {
func checkAndConfirmOverwrite(c *cli.Context, destFile string) bool {
if ess.IsFileExists(destFile) {
cliLog.Warnf("File: %s already exists, it will be overwritten.", destFile)
if c.GlobalBool("y") || c.GlobalBool("yes") {
fmt.Println("\nWould you like to continue? [y/N]: y")
return true
}

var input string
for {
input = readInput(reader, "\nWould you like to continue [Y]es or [N]o, default is 'N'? ")
input = readInput(reader, "\nWould you like to continue? [y/N]: ")
input = strings.ToLower(strings.TrimSpace(input))
if ess.IsStrEmpty(input) || input == "n" {
// do not overwrite the file, abort
Expand Down
5 changes: 4 additions & 1 deletion aah/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"bytes"
"fmt"
"go/format"
"io/ioutil"
"os"
Expand Down Expand Up @@ -73,7 +74,9 @@ func migrateCodeAction(c *cli.Context) error {
cliLog = initCLILogger(projectCfg)

cliLog.Warn("Migrate command does not take file backup. It assumes application use version control.")
if !collectYesOrNo(reader, "Would you like to continue ([Y]es or [N]o)? default is 'N'") {
if c.GlobalBool("y") || c.GlobalBool("yes") {
fmt.Println("\nWould 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
}
Expand Down
20 changes: 10 additions & 10 deletions aah/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func newAction(c *cli.Context) error {

switch appType {
case typeWeb:
collectInputsForWebApp(app)
collectInputsForWebApp(c, app)
case typeAPI:
collectInputsForAPIApp(app)
collectInputsForAPIApp(c, app)
}

// Process it
Expand Down Expand Up @@ -143,7 +143,7 @@ func collectAppType(reader *bufio.Reader) string {
// Collecting inputs for Web App
//______________________________________________________________________________

func collectInputsForWebApp(app *appTmplData) {
func collectInputsForWebApp(c *cli.Context, app *appTmplData) {
viewEngine(reader, app)

authScheme(reader, app)
Expand All @@ -157,16 +157,16 @@ func collectInputsForWebApp(app *appTmplData) {
sessionInfo(reader, app)

// In the web application user may like to have API also WebSocket within it.
collectAppSubTypesChoice(reader, app)
collectAppSubTypesChoice(c, reader, app)

app.CORSEnable = collectYesOrNo(reader, "Would you like to enable CORS ([Y]es or [N]o)? default is 'N'")
app.CORSEnable = collectYesOrNo(reader, "Would you like to enable CORS? [y/N]")
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Collecting inputs for API App
//______________________________________________________________________________

func collectInputsForAPIApp(app *appTmplData) {
func collectInputsForAPIApp(c *cli.Context, app *appTmplData) {
authScheme(reader, app)

if app.AuthScheme == authBasic {
Expand All @@ -175,20 +175,20 @@ func collectInputsForAPIApp(app *appTmplData) {

passwordHashAlgorithm(reader, app)

app.CORSEnable = collectYesOrNo(reader, "Would you like to enable CORS ([Y]es or [N]o)? default is 'N'")
app.CORSEnable = collectYesOrNo(reader, "Would you like to enable CORS? [y/N]")
}

func collectAppSubTypesChoice(reader *bufio.Reader, app *appTmplData) {
func collectAppSubTypesChoice(c *cli.Context, reader *bufio.Reader, app *appTmplData) {
app.SubTypes = make([]string, 0)

// API choice
choice := collectYesOrNo(reader, "Would you like to add API [/api/v1/*] within your Web App ([Y]es or [N]o)? default is 'N'")
choice := collectYesOrNo(reader, "Would you like to add API (/api/v1/*) within your Web App? [y/N]")
if choice {
app.SubTypes = append(app.SubTypes, typeAPI)
}

// WebSocket choice
choice = collectYesOrNo(reader, "Would you like to add WebSocket [/ws/*] within your Web App ([Y]es or [N]o)? default is 'N'")
choice = collectYesOrNo(reader, "Would you like to add WebSocket (/ws/*) within your Web App? [y/N]")
if choice {
app.SubTypes = append(app.SubTypes, typeWebSocket)
}
Expand Down
12 changes: 9 additions & 3 deletions aah/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func switchAction(c *cli.Context) error {
return doRefresh(branchName)
}

return doSwitch(branchName, strings.ToLower(firstNonEmpty(c.String("v"), c.String("version"))))
return doSwitch(c, branchName, strings.ToLower(firstNonEmpty(c.String("v"), c.String("version"))))
}

func whoami(branchName string) error {
Expand Down Expand Up @@ -106,14 +106,20 @@ func doRefresh(branchName string) error {
return nil
}

func doSwitch(branchName, target string) error {
func doSwitch(c *cli.Context, branchName, target string) error {
fname := friendlyName(branchName)
if target == fname {
cliLog.Infof("Currently you're on aah '%s' version.\n", fname)
cliLog.Infof("To switch to release version. Run 'aah s -v release'\n")

if fname == "edge" {
ans := collectYesOrNo(reader, "Would you like to refresh 'edge' to latest updates? ([Y]es or [N]o), default is 'N'")
var ans bool
if c.GlobalBool("y") || c.GlobalBool("yes") {
fmt.Println("\nWould you like to refresh 'edge' to latest updates? [y/N]: y")
ans = true
} else {
ans = collectYesOrNo(reader, "Would you like to refresh 'edge' to latest updates? [y/N]")
}
fmt.Println()
if ans {
doRefresh(branchName)
Expand Down
Loading

0 comments on commit 536f960

Please sign in to comment.