commit
528e33e1fd
@ -1,15 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/oxequa/interact"
|
||||
"github.com/oxequa/realize/realize"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hysios/realize/realize"
|
||||
"github.com/oxequa/interact"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var r realize.Realize
|
||||
@ -1125,6 +1126,7 @@ func start(c *cli.Context) (err error) {
|
||||
if c.Bool("server") {
|
||||
r.Server.Set(c.Bool("server"), c.Bool("open"), realize.Port, realize.Host)
|
||||
}
|
||||
|
||||
// check no-config and read
|
||||
if !c.Bool("no-config") {
|
||||
// read a config if exist
|
||||
|
@ -1,9 +1,8 @@
|
||||
package realize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/build"
|
||||
"log"
|
||||
"os"
|
||||
@ -12,13 +11,15 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
)
|
||||
|
||||
var (
|
||||
// RPrefix tool name
|
||||
RPrefix = "realize"
|
||||
// RVersion current version
|
||||
RVersion = "2.0.2"
|
||||
RVersion = "2.0.3"
|
||||
// RExt file extension
|
||||
RExt = ".yaml"
|
||||
// RFile config file name
|
||||
|
@ -114,6 +114,11 @@ func (p *Project) Before() {
|
||||
p.parent.Before(Context{Project: p})
|
||||
return
|
||||
}
|
||||
|
||||
if hasGoMod(Wdir()) {
|
||||
p.Tools.vgo = true
|
||||
}
|
||||
|
||||
// setup go tools
|
||||
p.Tools.Setup()
|
||||
// global commands before
|
||||
|
@ -2,9 +2,10 @@ package realize
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
// Schema projects list
|
||||
@ -35,10 +36,16 @@ func (s *Schema) Remove(name string) error {
|
||||
|
||||
// New create a project using cli fields
|
||||
func (s *Schema) New(c *cli.Context) Project {
|
||||
var vgo bool
|
||||
name := filepath.Base(c.String("path"))
|
||||
if len(name) == 0 || name == "." {
|
||||
name = filepath.Base(Wdir())
|
||||
}
|
||||
|
||||
if hasGoMod(Wdir()) {
|
||||
vgo = true
|
||||
}
|
||||
|
||||
project := Project{
|
||||
Name: name,
|
||||
Path: c.String("path"),
|
||||
@ -64,6 +71,7 @@ func (s *Schema) New(c *cli.Context) Project {
|
||||
Run: Tool{
|
||||
Status: c.Bool("run"),
|
||||
},
|
||||
vgo: vgo,
|
||||
},
|
||||
Args: params(c),
|
||||
Watcher: Watch{
|
||||
|
@ -36,15 +36,23 @@ type Tools struct {
|
||||
Install Tool `yaml:"install,omitempty" json:"install,omitempty"`
|
||||
Build Tool `yaml:"build,omitempty" json:"build,omitempty"`
|
||||
Run Tool `yaml:"run,omitempty" json:"run,omitempty"`
|
||||
vgo bool
|
||||
}
|
||||
|
||||
// Setup go tools
|
||||
func (t *Tools) Setup() {
|
||||
var gocmd string
|
||||
if t.vgo {
|
||||
gocmd = "vgo"
|
||||
} else {
|
||||
gocmd = "go"
|
||||
}
|
||||
|
||||
// go clean
|
||||
if t.Clean.Status {
|
||||
t.Clean.name = "Clean"
|
||||
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)
|
||||
}
|
||||
// go generate
|
||||
@ -52,7 +60,7 @@ func (t *Tools) Setup() {
|
||||
t.Generate.dir = true
|
||||
t.Generate.isTool = true
|
||||
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)
|
||||
}
|
||||
// go fmt
|
||||
@ -70,7 +78,7 @@ func (t *Tools) Setup() {
|
||||
t.Vet.dir = true
|
||||
t.Vet.name = "Vet"
|
||||
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)
|
||||
}
|
||||
// go test
|
||||
@ -78,17 +86,17 @@ func (t *Tools) Setup() {
|
||||
t.Test.dir = true
|
||||
t.Test.isTool = true
|
||||
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)
|
||||
}
|
||||
// go 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)
|
||||
// go build
|
||||
if t.Build.Status {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,12 @@ package realize
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
// Params parse one by one the given argumentes
|
||||
@ -73,3 +75,12 @@ func Wdir() string {
|
||||
}
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user