2016-09-01 22:17:19 +00:00
|
|
|
package cli
|
2016-08-31 12:08:15 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2016-12-17 10:43:27 +00:00
|
|
|
// Run launches the toolchain for each project
|
2016-08-31 12:08:15 +00:00
|
|
|
func (h *Blueprint) Run() error {
|
2016-11-01 09:56:12 +00:00
|
|
|
err := h.check()
|
2016-08-31 12:08:15 +00:00
|
|
|
if err == nil {
|
|
|
|
// loop projects
|
|
|
|
wg.Add(len(h.Projects))
|
2016-10-14 08:47:43 +00:00
|
|
|
for k := range h.Projects {
|
|
|
|
h.Projects[k].parent = h
|
2016-12-25 17:08:22 +00:00
|
|
|
h.Projects[k].path = h.Projects[k].Path
|
2016-12-26 23:14:29 +00:00
|
|
|
if h.Legacy.Status {
|
2016-12-21 23:28:08 +00:00
|
|
|
go h.Projects[k].watchByPolling()
|
|
|
|
} else {
|
2016-12-25 17:08:22 +00:00
|
|
|
go h.Projects[k].watchByNotify()
|
2016-12-21 23:28:08 +00:00
|
|
|
}
|
2016-08-31 12:08:15 +00:00
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a new project
|
2016-11-01 09:56:12 +00:00
|
|
|
func (h *Blueprint) Add(p *cli.Context) error {
|
|
|
|
project := Project{
|
2017-03-12 22:46:58 +00:00
|
|
|
Name: h.Name(p.String("name"), p.String("path")),
|
|
|
|
Path: h.Path(p.String("path")),
|
2016-12-26 23:14:29 +00:00
|
|
|
Fmt: !p.Bool("no-fmt"),
|
|
|
|
Generate: p.Bool("generate"),
|
|
|
|
Test: p.Bool("test"),
|
|
|
|
Build: p.Bool("build"),
|
|
|
|
Bin: !p.Bool("no-bin"),
|
|
|
|
Run: !p.Bool("no-run"),
|
|
|
|
Params: argsParam(p),
|
2016-08-31 12:08:15 +00:00
|
|
|
Watcher: Watcher{
|
2016-11-20 17:38:42 +00:00
|
|
|
Paths: []string{"/"},
|
|
|
|
Ignore: []string{"vendor"},
|
|
|
|
Exts: []string{".go"},
|
2016-12-26 23:14:29 +00:00
|
|
|
Preview: p.Bool("preview"),
|
|
|
|
Scripts: []Command{},
|
2016-11-11 16:21:54 +00:00
|
|
|
},
|
2016-12-26 23:14:29 +00:00
|
|
|
Streams: Streams{
|
|
|
|
CliOut: true,
|
|
|
|
FileOut: false,
|
|
|
|
FileLog: false,
|
|
|
|
FileErr: false,
|
2016-08-31 12:08:15 +00:00
|
|
|
},
|
|
|
|
}
|
2016-11-01 09:56:12 +00:00
|
|
|
if _, err := duplicates(project, h.Projects); err != nil {
|
2016-08-31 12:08:15 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-11-01 09:56:12 +00:00
|
|
|
h.Projects = append(h.Projects, project)
|
2016-08-31 12:08:15 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean duplicate projects
|
|
|
|
func (h *Blueprint) Clean() {
|
|
|
|
arr := h.Projects
|
|
|
|
for key, val := range arr {
|
|
|
|
if _, err := duplicates(val, arr[key+1:]); err != nil {
|
|
|
|
h.Projects = append(arr[:key], arr[key+1:]...)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove a project
|
2016-11-01 09:56:12 +00:00
|
|
|
func (h *Blueprint) Remove(p *cli.Context) error {
|
|
|
|
for key, val := range h.Projects {
|
|
|
|
if p.String("name") == val.Name {
|
|
|
|
h.Projects = append(h.Projects[:key], h.Projects[key+1:]...)
|
|
|
|
return nil
|
2016-08-31 12:08:15 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-01 09:56:12 +00:00
|
|
|
return errors.New("No project found.")
|
2016-08-31 12:08:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// List of all the projects
|
|
|
|
func (h *Blueprint) List() error {
|
2016-11-01 09:56:12 +00:00
|
|
|
err := h.check()
|
2016-08-31 12:08:15 +00:00
|
|
|
if err == nil {
|
|
|
|
for _, val := range h.Projects {
|
2016-11-01 09:56:12 +00:00
|
|
|
fmt.Println(h.Blue.Bold("|"), h.Blue.Bold(strings.ToUpper(val.Name)))
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t", h.Yellow.Regular("Base Path"), ":", h.Magenta.Regular(val.Path))
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t", h.Yellow.Regular("Fmt"), ":", h.Magenta.Regular(val.Fmt))
|
2016-12-26 23:14:29 +00:00
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t", h.Yellow.Regular("Generate"), ":", h.Magenta.Regular(val.Generate))
|
2016-11-01 09:56:12 +00:00
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t", h.Yellow.Regular("Test"), ":", h.Magenta.Regular(val.Test))
|
2016-12-26 23:14:29 +00:00
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t", h.Yellow.Regular("Install"), ":", h.Magenta.Regular(val.Bin))
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t", h.Yellow.Regular("Build"), ":", h.Magenta.Regular(val.Build))
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t", h.Yellow.Regular("Run"), ":", h.Magenta.Regular(val.Run))
|
2016-11-11 16:21:54 +00:00
|
|
|
if len(val.Params) > 0 {
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t", h.Yellow.Regular("Params"), ":", h.Magenta.Regular(val.Params))
|
|
|
|
}
|
2016-11-01 09:56:12 +00:00
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t", h.Yellow.Regular("Watcher"), ":")
|
2016-12-26 23:14:29 +00:00
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t", h.Yellow.Regular("Preview"), ":", h.Magenta.Regular(val.Watcher.Preview))
|
2016-11-11 16:21:54 +00:00
|
|
|
if len(val.Watcher.Exts) > 0 {
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t", h.Yellow.Regular("Extensions"), ":", h.Magenta.Regular(val.Watcher.Exts))
|
|
|
|
}
|
|
|
|
if len(val.Watcher.Paths) > 0 {
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t", h.Yellow.Regular("Paths"), ":", h.Magenta.Regular(val.Watcher.Paths))
|
|
|
|
}
|
|
|
|
if len(val.Watcher.Ignore) > 0 {
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t", h.Yellow.Regular("Ignored paths"), ":", h.Magenta.Regular(val.Watcher.Ignore))
|
|
|
|
}
|
2016-12-26 23:14:29 +00:00
|
|
|
if len(val.Watcher.Scripts) > 0 {
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t", h.Yellow.Regular("Scripts"), ":")
|
|
|
|
for _, v := range val.Watcher.Scripts {
|
|
|
|
if v.Command != "" {
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t\t", h.Magenta.Regular("-"), h.Yellow.Regular("Command"), ":", h.Magenta.Regular(v.Command))
|
|
|
|
if v.Path != "" {
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t\t", h.Yellow.Regular("Path"), ":", h.Magenta.Regular(v.Path))
|
|
|
|
}
|
|
|
|
if v.Type != "" {
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t\t", h.Yellow.Regular("Type"), ":", h.Magenta.Regular(v.Type))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t", h.Yellow.Regular("Streams"), ":")
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t", h.Yellow.Regular("Cli Out"), ":", h.Magenta.Regular(val.Streams.CliOut))
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t", h.Yellow.Regular("File Out"), ":", h.Magenta.Regular(val.Streams.FileOut))
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t", h.Yellow.Regular("File Log"), ":", h.Magenta.Regular(val.Streams.FileLog))
|
|
|
|
fmt.Println(h.Magenta.Regular("|"), "\t\t", h.Yellow.Regular("File Err"), ":", h.Magenta.Regular(val.Streams.FileErr))
|
2016-08-31 12:08:15 +00:00
|
|
|
}
|
2016-11-01 09:56:12 +00:00
|
|
|
return nil
|
2016-08-31 12:08:15 +00:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
2016-10-21 15:30:12 +00:00
|
|
|
|
2016-11-14 07:59:47 +00:00
|
|
|
// Check whether there is a project
|
2016-11-01 09:56:12 +00:00
|
|
|
func (h *Blueprint) check() error {
|
|
|
|
if len(h.Projects) > 0 {
|
|
|
|
h.Clean()
|
|
|
|
return nil
|
|
|
|
}
|
2016-12-17 10:43:27 +00:00
|
|
|
return errors.New("There are no projects. The config file is empty.")
|
2016-11-01 09:56:12 +00:00
|
|
|
}
|