Merge pull request #200 from hysios/master

add vgo support
This commit is contained in:
Alessio Pracchia 2018-08-23 11:42:24 +02:00 committed by GitHub
commit 528e33e1fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 14 deletions

View File

@ -1,15 +1,16 @@
package main package main
import ( import (
"github.com/oxequa/interact"
"github.com/oxequa/realize/realize"
"gopkg.in/urfave/cli.v2"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/hysios/realize/realize"
"github.com/oxequa/interact"
"gopkg.in/urfave/cli.v2"
) )
var r realize.Realize var r realize.Realize
@ -1125,6 +1126,7 @@ func start(c *cli.Context) (err error) {
if c.Bool("server") { if c.Bool("server") {
r.Server.Set(c.Bool("server"), c.Bool("open"), realize.Port, realize.Host) r.Server.Set(c.Bool("server"), c.Bool("open"), realize.Port, realize.Host)
} }
// check no-config and read // check no-config and read
if !c.Bool("no-config") { if !c.Bool("no-config") {
// read a config if exist // read a config if exist

View File

@ -1,9 +1,8 @@
package realize package realize
import ( import (
"fmt"
"github.com/fsnotify/fsnotify"
"errors" "errors"
"fmt"
"go/build" "go/build"
"log" "log"
"os" "os"
@ -12,13 +11,15 @@ import (
"strings" "strings"
"sync" "sync"
"time" "time"
"github.com/fsnotify/fsnotify"
) )
var ( var (
// RPrefix tool name // RPrefix tool name
RPrefix = "realize" RPrefix = "realize"
// RVersion current version // RVersion current version
RVersion = "2.0.2" RVersion = "2.0.3"
// RExt file extension // RExt file extension
RExt = ".yaml" RExt = ".yaml"
// RFile config file name // RFile config file name

View File

@ -114,6 +114,11 @@ func (p *Project) Before() {
p.parent.Before(Context{Project: p}) p.parent.Before(Context{Project: p})
return return
} }
if hasGoMod(Wdir()) {
p.Tools.vgo = true
}
// setup go tools // setup go tools
p.Tools.Setup() p.Tools.Setup()
// global commands before // global commands before

View File

@ -2,9 +2,10 @@ package realize
import ( import (
"errors" "errors"
"gopkg.in/urfave/cli.v2"
"path/filepath" "path/filepath"
"reflect" "reflect"
"gopkg.in/urfave/cli.v2"
) )
// Schema projects list // Schema projects list
@ -35,10 +36,16 @@ func (s *Schema) Remove(name string) error {
// New create a project using cli fields // New create a project using cli fields
func (s *Schema) New(c *cli.Context) Project { func (s *Schema) New(c *cli.Context) Project {
var vgo bool
name := filepath.Base(c.String("path")) name := filepath.Base(c.String("path"))
if len(name) == 0 || name == "." { if len(name) == 0 || name == "." {
name = filepath.Base(Wdir()) name = filepath.Base(Wdir())
} }
if hasGoMod(Wdir()) {
vgo = true
}
project := Project{ project := Project{
Name: name, Name: name,
Path: c.String("path"), Path: c.String("path"),
@ -64,6 +71,7 @@ func (s *Schema) New(c *cli.Context) Project {
Run: Tool{ Run: Tool{
Status: c.Bool("run"), Status: c.Bool("run"),
}, },
vgo: vgo,
}, },
Args: params(c), Args: params(c),
Watcher: Watch{ Watcher: Watch{

View File

@ -36,15 +36,23 @@ type Tools struct {
Install Tool `yaml:"install,omitempty" json:"install,omitempty"` Install Tool `yaml:"install,omitempty" json:"install,omitempty"`
Build Tool `yaml:"build,omitempty" json:"build,omitempty"` Build Tool `yaml:"build,omitempty" json:"build,omitempty"`
Run Tool `yaml:"run,omitempty" json:"run,omitempty"` Run Tool `yaml:"run,omitempty" json:"run,omitempty"`
vgo bool
} }
// Setup go tools // Setup go tools
func (t *Tools) Setup() { func (t *Tools) Setup() {
var gocmd string
if t.vgo {
gocmd = "vgo"
} else {
gocmd = "go"
}
// go clean // go clean
if t.Clean.Status { if t.Clean.Status {
t.Clean.name = "Clean" t.Clean.name = "Clean"
t.Clean.isTool = true t.Clean.isTool = true
t.Clean.cmd = replace([]string{"go", "clean"}, t.Clean.Method) t.Clean.cmd = replace([]string{gocmd, "clean"}, t.Clean.Method)
t.Clean.Args = split([]string{}, t.Clean.Args) t.Clean.Args = split([]string{}, t.Clean.Args)
} }
// go generate // go generate
@ -52,7 +60,7 @@ func (t *Tools) Setup() {
t.Generate.dir = true t.Generate.dir = true
t.Generate.isTool = true t.Generate.isTool = true
t.Generate.name = "Generate" t.Generate.name = "Generate"
t.Generate.cmd = replace([]string{"go", "generate"}, t.Generate.Method) t.Generate.cmd = replace([]string{gocmd, "generate"}, t.Generate.Method)
t.Generate.Args = split([]string{}, t.Generate.Args) t.Generate.Args = split([]string{}, t.Generate.Args)
} }
// go fmt // go fmt
@ -70,7 +78,7 @@ func (t *Tools) Setup() {
t.Vet.dir = true t.Vet.dir = true
t.Vet.name = "Vet" t.Vet.name = "Vet"
t.Vet.isTool = true t.Vet.isTool = true
t.Vet.cmd = replace([]string{"go", "vet"}, t.Vet.Method) t.Vet.cmd = replace([]string{gocmd, "vet"}, t.Vet.Method)
t.Vet.Args = split([]string{}, t.Vet.Args) t.Vet.Args = split([]string{}, t.Vet.Args)
} }
// go test // go test
@ -78,17 +86,17 @@ func (t *Tools) Setup() {
t.Test.dir = true t.Test.dir = true
t.Test.isTool = true t.Test.isTool = true
t.Test.name = "Test" t.Test.name = "Test"
t.Test.cmd = replace([]string{"go", "test"}, t.Test.Method) t.Test.cmd = replace([]string{gocmd, "test"}, t.Test.Method)
t.Test.Args = split([]string{}, t.Test.Args) t.Test.Args = split([]string{}, t.Test.Args)
} }
// go install // go install
t.Install.name = "Install" t.Install.name = "Install"
t.Install.cmd = replace([]string{"go", "install"}, t.Install.Method) t.Install.cmd = replace([]string{gocmd, "install"}, t.Install.Method)
t.Install.Args = split([]string{}, t.Install.Args) t.Install.Args = split([]string{}, t.Install.Args)
// go build // go build
if t.Build.Status { if t.Build.Status {
t.Build.name = "Build" t.Build.name = "Build"
t.Build.cmd = replace([]string{"go", "build"}, t.Build.Method) t.Build.cmd = replace([]string{gocmd, "build"}, t.Build.Method)
t.Build.Args = split([]string{}, t.Build.Args) t.Build.Args = split([]string{}, t.Build.Args)
} }
} }

View File

@ -2,10 +2,12 @@ package realize
import ( import (
"errors" "errors"
"gopkg.in/urfave/cli.v2"
"log" "log"
"os" "os"
"path"
"strings" "strings"
"gopkg.in/urfave/cli.v2"
) )
// Params parse one by one the given argumentes // Params parse one by one the given argumentes
@ -73,3 +75,12 @@ func Wdir() string {
} }
return dir return dir
} }
func hasGoMod(dir string) bool {
filename := path.Join(dir, "go.mod")
if _, err := os.Stat(filename); os.IsNotExist(err) {
return false
}
return true
}