Skip to content

Commit

Permalink
Merge pull request #9 for v0.7 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Aug 1, 2017
2 parents e751e7c + 4299100 commit c045d89
Show file tree
Hide file tree
Showing 23 changed files with 1,134 additions and 496 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ go:

go_import_path: aahframework.org/tools.v0/aah

install:
- git config --global http.https://aahframework.org.followRedirects true
- go get -t -v ./...

script:
- bash <(curl -s https://aahframework.org/go-test)

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Home of all aah framework CLI tools.
## aah CLI Tool
[![Build Status](https://travis-ci.org/go-aah/tools.svg?branch=master)](https://travis-ci.org/go-aah/tools) [![Go Report Card](https://goreportcard.com/badge/aahframework.org/tools.v0)](https://goreportcard.com/report/aahframework.org/tools.v0/aah)
[![Powered by Go](https://img.shields.io/badge/powered_by-go-blue.svg)](https://golang.org)
[![Version](https://img.shields.io/badge/version-0.6-blue.svg)](https://github.com/go-aah/tools/releases/latest)
[![License](https://img.shields.io/github/license/go-aah/tools.svg)](LICENSE)
[![Version](https://img.shields.io/badge/version-0.7-blue.svg)](https://github.com/go-aah/tools/releases/latest)
[![License](https://img.shields.io/github/license/go-aah/tools.svg)](LICENSE) [![Twitter](https://img.shields.io/badge/twitter-@aahframework-55acee.svg)](https://twitter.com/aahframework)

***Release [v0.6](https://github.com/go-aah/tools/releases/latest) tagged on Jun 07, 2017***
***Release [v0.7](https://github.com/go-aah/tools/releases/latest) tagged on Aug 01, 2017***

aah framework - A scalable, performant, rapid development Web framework for Go.

Expand Down
161 changes: 113 additions & 48 deletions aah/aah.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
// go-aah/tools source code and usage is governed by a MIT style
// go-aah/tools/aah source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

package main

import (
"flag"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
"strings"

"gopkg.in/urfave/cli.v1"

"aahframework.org/aah.v0"
"aahframework.org/ahttp.v0"
"aahframework.org/aruntime.v0"
"aahframework.org/config.v0"
"aahframework.org/essentials.v0"
"aahframework.org/i18n.v0"
"aahframework.org/log.v0"
"aahframework.org/router.v0"
"aahframework.org/security.v0"
"aahframework.org/test.v0"
"aahframework.org/view.v0"
)

// Version no. of aah framework CLI tool
const Version = "0.6"
const Version = "0.7"

const (
header = `–––––––––––––––––––––––––––––––––––––––––––––––––––––
Expand All @@ -36,88 +47,142 @@ var (
gopath string
gocmd string
gosrcDir string
subCmds commands

// abstract it, so we can do unit test
fatal = log.Fatal
fatalf = log.Fatalf
exit = os.Exit
)

// aah cli tool entry point
func main() {
// if panic happens, recover and abort nicely :)
defer func() {
if r := recover(); r != nil {
cfg, _ := config.ParseString(``)
strace := aruntime.NewStacktrace(r, cfg)
strace.Print(os.Stdout)
exit(2)
}
}()

func checkPrerequisites() error {
// check go is installed or not
if !ess.LookExecutable("go") {
fatal("Unable to find Go executable in PATH")
return errors.New("Unable to find Go executable in PATH")
}

var err error

// get GOPATH, refer https://godoc.org/aahframework.org/essentials.v0#GoPath
if gopath, err = ess.GoPath(); err != nil {
fatal(err)
return err
}

if gocmd, err = exec.LookPath("go"); err != nil {
fatal(err)
return err
}

flag.Parse()
args := flag.Args()
gosrcDir = filepath.Join(gopath, "src")

printHeader()
if len(args) == 0 {
displayUsage()
}
return nil
}

// find the command
cmd, err := subCmds.Find(args[0])
if err != nil {
commandNotFound(args[0])
// aah cli tool entry point
func main() {
// if panic happens, recover and abort nicely :)
defer func() {
if r := recover(); r != nil {
cfg, _ := config.ParseString(``)
strace := aruntime.NewStacktrace(r, cfg)
strace.Print(os.Stdout)
exit(2)
}
}()

if err := checkPrerequisites(); err != nil {
fatal(err)
}

// Validate command arguments count
if len(args)-1 > cmd.ArgsCount {
fatal("Too many arguments given. Run 'aah help command'.\n\n")
app := cli.NewApp()
app.Name = "aah"
app.Usage = "framework CLI tool"
app.Version = Version
app.Author = "Jeevanandam M."
app.Email = "jeeva@myjeeva.com"
app.Copyright = "Copyright (c) Jeevanandam M. <jeeva@myjeeva.com>"

app.Before = printHeader
app.Commands = []cli.Command{
newCmd,
runCmd,
buildCmd,
listCmd,
cleanCmd,
}

// running command
cmd.Run(args[1:])
sort.Sort(cli.FlagsByName(app.Flags))
_ = app.Run(os.Args)
return
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Unexported methods
//___________________________________

func printHeader() {
if !isWindowsOS() {
fmt.Fprintf(os.Stdout, fmt.Sprintf("\033[1;32m%v\033[0m\n", header), aah.Version)
return
func printHeader(c *cli.Context) error {
if isWindowsOS() {
fmt.Fprintf(c.App.Writer, header, aah.Version)
} else {
fmt.Fprintf(c.App.Writer, fmt.Sprintf("\033[1;32m%v\033[0m", header), aah.Version)
}
fmt.Fprintf(os.Stdout, header, aah.Version)
fmt.Fprintf(c.App.Writer, "# Report improvements/bugs at https://github.com/go-aah/aah/issues\n\n")
return nil
}

func init() {
// Adding list of commands. The order here is the order in
// which commands are printed by 'aah help'.
subCmds = commands{
newCmd,
runCmd,
buildCmd,
listCmd,
versionCmd,
helpCmd,
cli.HelpFlag = cli.BoolFlag{
Name: "h, help",
Usage: "show help",
}

cli.VersionFlag = cli.BoolFlag{
Name: "v, version",
Usage: "print aah framework version and go version",
}

cli.VersionPrinter = func(c *cli.Context) {
_ = printHeader(c)
fmt.Fprint(c.App.Writer, "Version(s):\n")
fmt.Fprintf(c.App.Writer, "\t%-17s v%s\n", "aah framework", aah.Version)
fmt.Fprintf(c.App.Writer, "\t%-17s v%s\n", "aah cli tool", Version)
fmt.Fprintf(c.App.Writer, "\t%-17s %s\n", "Modules: ", strings.Join(
[]string{
"config v" + config.Version, "essentials v" + ess.Version,
"ahttp v" + ahttp.Version, "router v" + router.Version,
"security v" + security.Version}, ", "))
fmt.Fprintf(c.App.Writer, "\t%-17s %s\n", "", strings.Join(
[]string{"i18n v" + i18n.Version, "view v" + view.Version,
"log v" + log.Version, "test v" + test.Version, "aruntime v" + aruntime.Version,
}, ", "))
fmt.Println()
fmt.Fprintf(c.App.Writer, "\t%-17s %s\n", fmt.Sprintf("go[%s/%s]",
runtime.GOOS, runtime.GOARCH), runtime.Version()[2:])
fmt.Println()
}

cli.AppHelpTemplate = `Usage:
{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}
{{if .Commands}}
Commands:
{{range .Commands}}{{if not .HideHelp}} {{join .Names ", "}}{{ "\t " }}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
Global Options:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}
`

cli.CommandHelpTemplate = `Name:
{{.HelpName}} - {{.Usage}}
Usage:
{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{if .Category}}
Category:
{{.Category}}{{end}}{{if .Description}}
Description:
{{.Description}}{{end}}{{if .VisibleFlags}}
Options:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}
`
}
1 change: 1 addition & 0 deletions aah/app-template/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
aah.go
*.pid
build/
vendor/*/

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
Expand Down
18 changes: 18 additions & 0 deletions aah/app-template/aah.project.atmpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,21 @@ build {
# refer: https://golang.org/pkg/path/filepath/#Match
excludes = ["*.go", "*_test.go", ".*", "*.bak", "*.tmp", "vendor", "app", "build", "tests", "logs"]
}

# Hot-Reload is development purpose to help developer.
# Read more about implementation here - https://github.com/go-aah/aah/issues/4
#
# NOTE: Do not use hot-reload feature for production purpose, it's not recommended.
hot_reload {
# Default value is `true`.
enable = true

# Watch configuration - files/directories exclusion list.
watch {
# Note: static directory not required to be monitored, since server delivers
# up-to-date file on environment profile `dev`.
dir_excludes = [".*"]

file_excludes = [".*", "_test.go", "LICENSE", "README.md"]
}
}
9 changes: 4 additions & 5 deletions aah/app-template/app/controllers/app.go.atmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package controllers

import (
"aahframework.org/aah.v0"
"aahframework.org/aah.v0-unstable"
"{{.AppImportPath}}/app/models"
)

Expand All @@ -12,17 +12,16 @@ type App struct {

// Index method is application {{ if eq .AppType "web" -}}home page.{{ else }}root API endpoint.{{- end }}
func (a *App) Index() {
{{ if eq .AppType "web" -}}
{{- if eq .AppType "web" }}
data := aah.Data{
"Greet": models.Greet{
Message: "Welcome to aah framework - Web Application",
},
}

a.Reply().Ok().HTML(data)
{{ else }}
{{- else }}
a.Reply().Ok().JSON(models.Greet{
Message: "Welcome to aah framework - API application",
})
{{- end -}}
}){{ end }}
}
Loading

0 comments on commit c045d89

Please sign in to comment.