Initial rewrite of revel/cmd to provide vendor support and enhanced CLI options

This commit is contained in:
NotZippy
2018-09-13 13:21:10 -07:00
parent d2ac018544
commit d0baaeb9e9
40 changed files with 4435 additions and 1125 deletions

View File

@@ -12,7 +12,14 @@ import (
"fmt"
"runtime"
"github.com/revel/revel"
"github.com/revel/cmd/model"
"go/build"
"go/token"
"go/parser"
"go/ast"
"io/ioutil"
"path/filepath"
"github.com/revel/cmd/utils"
)
var cmdVersion = &Command{
@@ -28,11 +35,46 @@ For example:
}
func init() {
cmdVersion.Run = versionApp
cmdVersion.RunWith = versionApp
}
func versionApp(args []string) {
fmt.Printf("Version(s):")
fmt.Printf("\n Revel v%v (%v)", revel.Version, revel.BuildDate)
// Displays the version of go and Revel
func versionApp(c *model.CommandConfig) {
revelPkg, err := build.Import(model.RevelImportPath, c.Version.ImportPath, build.FindOnly)
if err != nil {
utils.Logger.Errorf("Failed to find Revel with error:", "error", err)
}
fset := token.NewFileSet() // positions are relative to fset
version, err := ioutil.ReadFile(filepath.Join(revelPkg.Dir,"version.go"))
if err != nil {
utils.Logger.Errorf("Failed to find Revel version:", "error", err)
}
// Parse src but stop after processing the imports.
f, err := parser.ParseFile(fset, "", version, parser.ParseComments)
if err != nil {
utils.Logger.Errorf("Failed to parse Revel version error:", "error", err)
}
// Print the imports from the file's AST.
for _, s := range f.Decls {
genDecl, ok := s.(*ast.GenDecl)
if !ok {
continue
}
if genDecl.Tok != token.CONST {
continue
}
for _, a := range genDecl.Specs {
spec := a.(*ast.ValueSpec)
r := spec.Values[0].(*ast.BasicLit)
fmt.Printf("Revel %s = %s\n",spec.Names[0].Name,r.Value)
}
}
fmt.Printf("\n %s %s/%s\n\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
}