This commit is contained in:
alessio 2017-06-16 11:15:56 +02:00
parent 350bdbb4a6
commit e2c06878f5
6 changed files with 35 additions and 28 deletions

View File

@ -80,7 +80,6 @@ func main() {
if err := r.Read(&r); err != nil {
return err
}
// increase the file limit
if r.Config.Flimit != 0 {
if err := r.Flimit(); err != nil {
@ -111,6 +110,7 @@ func main() {
Description: "Run a toolchain on a project or a list of projects. If not exist a config file it creates a new one",
Flags: []cli.Flag{
&cli.StringFlag{Name: "path", Aliases: []string{"p"}, Value: "", Usage: "Project base path."},
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: "", Usage: "Run a project by its name."},
&cli.BoolFlag{Name: "test", Aliases: []string{"t"}, Value: false, Usage: "Enable go test."},
&cli.BoolFlag{Name: "generate", Aliases: []string{"g"}, Value: false, Usage: "Enable go generate."},
&cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build."},
@ -121,6 +121,14 @@ func main() {
&cli.BoolFlag{Name: "no-config", Aliases: []string{"nc"}, Value: false, Usage: "Ignore existing configurations."},
},
Action: func(p *cli.Context) error {
c := r
if p.String("name") != ""{
for index, project := range r.Blueprint.Projects{
if project.Name == p.String("name"){
c.Blueprint.Projects = []watcher.Project{r.Blueprint.Projects[index]}
}
}
}
if p.Bool("legacy") {
r.Config.Legacy = settings.Legacy{
Status: p.Bool("legacy"),
@ -136,13 +144,13 @@ func main() {
return err
}
}
if err := r.Server.Start(p); err != nil {
if err := c.Server.Start(p); err != nil {
return err
}
if err := r.Blueprint.Run(); err != nil {
if err := c.Blueprint.Run(p); err != nil {
return err
}
if err := r.Record(r); err != nil {
if err := r.Record(c); err != nil {
return err
}
return nil

View File

@ -3,7 +3,6 @@ package settings
import (
"os"
"time"
yaml "gopkg.in/yaml.v2"
)

View File

@ -9,14 +9,14 @@ import (
)
// Run launches the toolchain for each project
func (h *Blueprint) Run() error {
func (h *Blueprint) Run(p *cli.Context) error {
err := h.check()
if err == nil {
// loop projects
wg.Add(len(h.Projects))
for k, element := range h.Projects {
tools := tools{}
if element.Cmds.Fmt {
if element.Cmds.Fmt{
tools.Fmt = tool{
status: &h.Projects[k].Cmds.Fmt,
cmd: "gofmt",
@ -24,7 +24,7 @@ func (h *Blueprint) Run() error {
name: "Go Fmt",
}
}
if element.Cmds.Generate {
if element.Cmds.Generate{
tools.Generate = tool{
status: &h.Projects[k].Cmds.Generate,
cmd: "go",
@ -32,7 +32,7 @@ func (h *Blueprint) Run() error {
name: "Go Generate",
}
}
if element.Cmds.Test {
if element.Cmds.Test{
tools.Test = tool{
status: &h.Projects[k].Cmds.Test,
cmd: "go",

View File

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"fmt"
"github.com/tockins/realize/style"
"log"
"os"
"os/exec"
@ -12,7 +13,6 @@ import (
"strings"
"sync"
"time"
"github.com/tockins/realize/style"
)
// GoRun is an implementation of the bin execution

View File

@ -31,20 +31,20 @@ type Blueprint struct {
// Project defines the informations of a single project
type Project struct {
settings.Settings `yaml:"-"`
LastChangedOn time.Time `yaml:"-" json:"-"`
base string
Name string `yaml:"name" json:"name"`
Path string `yaml:"path" json:"path"`
Cmds Cmds `yaml:"cmds" json:"cmds"`
Args []string `yaml:"args,omitempty" json:"args,omitempty"`
Watcher Watcher `yaml:"watcher" json:"watcher"`
Streams Streams `yaml:"streams" json:"streams"`
Buffer Buffer `yaml:"-" json:"buffer"`
settings.Settings `yaml:"-"`
LastChangedOn time.Time `yaml:"-" json:"-"`
base string
Name string `yaml:"name" json:"name"`
Path string `yaml:"path" json:"path"`
Cmds Cmds `yaml:"commands" json:"commands"`
Args []string `yaml:"args,omitempty" json:"args,omitempty"`
Watcher Watcher `yaml:"watcher" json:"watcher"`
Streams Streams `yaml:"streams" json:"streams"`
Buffer Buffer `yaml:"-" json:"buffer"`
ErrorOutputPattern string `yaml:"errorOutputPattern" json:"errorOutputPattern"`
parent *Blueprint
path string
tools tools
parent *Blueprint
path string
tools tools
}
type tools struct {

View File

@ -3,19 +3,19 @@ package watcher
import (
"errors"
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/tockins/realize/style"
"log"
"math/big"
"os"
"os/signal"
"path/filepath"
"reflect"
"strconv"
"strings"
"sync"
"syscall"
"time"
"reflect"
"github.com/fsnotify/fsnotify"
"github.com/tockins/realize/style"
)
var msg string
@ -285,8 +285,8 @@ func (p *Project) build() error {
func (p *Project) tool(path string, tool tool) error {
if tool.status != nil {
v := reflect.ValueOf(tool.status).Elem()
if v.Interface().(bool) && (strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "")) {
if strings.HasSuffix(path, ".go"){
if v.Interface().(bool) && (strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "")) {
if strings.HasSuffix(path, ".go") {
tool.options = append(tool.options, path)
path = p.base
}