2016-07-12 08:18:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-11-01 09:56:12 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2017-04-13 12:48:48 +00:00
|
|
|
"github.com/fatih/color"
|
|
|
|
"github.com/tockins/interact"
|
|
|
|
"github.com/tockins/realize/settings"
|
2017-04-13 13:49:51 +00:00
|
|
|
"github.com/tockins/realize/style"
|
2017-04-13 12:48:48 +00:00
|
|
|
"github.com/tockins/realize/watcher"
|
|
|
|
cli "gopkg.in/urfave/cli.v2"
|
2017-09-18 01:05:00 +00:00
|
|
|
"os"
|
2017-09-03 17:59:56 +00:00
|
|
|
"strconv"
|
2017-09-18 01:05:00 +00:00
|
|
|
"time"
|
2016-07-12 08:18:02 +00:00
|
|
|
)
|
|
|
|
|
2016-11-01 09:56:12 +00:00
|
|
|
const (
|
2017-09-03 17:59:56 +00:00
|
|
|
version = "1.4.1"
|
2016-11-01 09:56:12 +00:00
|
|
|
)
|
|
|
|
|
2017-08-27 11:45:06 +00:00
|
|
|
// Realize struct contains the general app informations
|
|
|
|
type realize struct {
|
|
|
|
settings.Settings `yaml:"settings,omitempty"`
|
|
|
|
Sync chan string `yaml:"-"`
|
2017-09-20 13:56:31 +00:00
|
|
|
blueprint watcher.Blueprint `yaml:"-"`
|
|
|
|
server server `yaml:"-"`
|
|
|
|
projects *[]watcher.Project `yaml:"projects" json:"projects"`
|
2017-08-27 11:45:06 +00:00
|
|
|
}
|
2016-11-01 09:56:12 +00:00
|
|
|
|
2017-08-27 11:45:06 +00:00
|
|
|
// New realize instance
|
|
|
|
var r realize
|
2017-08-23 08:05:35 +00:00
|
|
|
|
2017-08-27 11:45:06 +00:00
|
|
|
// Cli commands
|
|
|
|
func main() {
|
2017-03-12 22:46:58 +00:00
|
|
|
app := &cli.App{
|
2017-04-13 13:53:58 +00:00
|
|
|
Name: "Realize",
|
2017-08-27 11:45:06 +00:00
|
|
|
Version: version,
|
2016-07-23 22:49:19 +00:00
|
|
|
Authors: []*cli.Author{
|
2016-08-21 14:35:17 +00:00
|
|
|
{
|
2016-08-23 13:17:44 +00:00
|
|
|
Name: "Alessio Pracchia",
|
2017-04-01 17:33:21 +00:00
|
|
|
Email: "pracchia@hastega.it",
|
2016-08-23 13:17:44 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Daniele Conventi",
|
2017-04-01 17:33:21 +00:00
|
|
|
Email: "conventi@hastega.it",
|
2016-07-23 22:49:19 +00:00
|
|
|
},
|
|
|
|
},
|
2017-04-13 13:53:58 +00:00
|
|
|
Description: "A Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths",
|
2016-07-12 18:03:22 +00:00
|
|
|
Commands: []*cli.Command{
|
|
|
|
{
|
2017-04-13 13:53:58 +00:00
|
|
|
Name: "run",
|
|
|
|
Aliases: []string{"r"},
|
|
|
|
Description: "Run a toolchain on a project or a list of projects. If not exist a config file it creates a new one",
|
2016-08-21 18:15:01 +00:00
|
|
|
Flags: []cli.Flag{
|
2017-03-12 22:46:58 +00:00
|
|
|
&cli.StringFlag{Name: "path", Aliases: []string{"p"}, Value: "", Usage: "Project base path."},
|
2017-06-16 09:15:56 +00:00
|
|
|
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: "", Usage: "Run a project by its name."},
|
2017-03-12 22:46:58 +00:00
|
|
|
&cli.BoolFlag{Name: "test", Aliases: []string{"t"}, Value: false, Usage: "Enable go test."},
|
2017-09-17 21:37:39 +00:00
|
|
|
&cli.BoolFlag{Name: "fmt", Aliases: []string{"f"}, Value: false, Usage: "Enable go fmt."},
|
2017-03-12 22:46:58 +00:00
|
|
|
&cli.BoolFlag{Name: "generate", Aliases: []string{"g"}, Value: false, Usage: "Enable go generate."},
|
2017-09-17 21:37:39 +00:00
|
|
|
&cli.BoolFlag{Name: "legacy", Aliases: []string{"l"}, Value: false, Usage: "Watch by polling instead of watch by fsnotify."},
|
2017-03-12 22:46:58 +00:00
|
|
|
&cli.BoolFlag{Name: "server", Aliases: []string{"s"}, Value: false, Usage: "Enable server and open into the default browser."},
|
2017-09-17 21:37:39 +00:00
|
|
|
&cli.BoolFlag{Name: "install", Aliases: []string{"i"}, Value: false, Usage: "Enable go install."},
|
|
|
|
&cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build."},
|
|
|
|
&cli.BoolFlag{Name: "run", Aliases: []string{"nr"}, Value: false, Usage: "Enable go run"},
|
2017-03-12 22:46:58 +00:00
|
|
|
&cli.BoolFlag{Name: "no-config", Aliases: []string{"nc"}, Value: false, Usage: "Ignore existing configurations."},
|
2016-08-21 18:15:01 +00:00
|
|
|
},
|
2016-07-27 09:14:32 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2017-09-03 17:59:56 +00:00
|
|
|
polling(p, &r.Legacy)
|
2017-09-20 13:56:31 +00:00
|
|
|
if err := insert(p, &r.blueprint); err != nil {
|
2017-08-27 11:45:06 +00:00
|
|
|
return err
|
2017-04-13 14:09:53 +00:00
|
|
|
}
|
2017-09-17 22:15:21 +00:00
|
|
|
if !p.Bool("no-config") {
|
|
|
|
if err := r.Record(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
if err := r.server.start(p); err != nil {
|
2017-04-13 14:09:53 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
if err := r.blueprint.Run(p); err != nil {
|
2017-04-13 14:09:53 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-11-01 09:56:12 +00:00
|
|
|
return nil
|
2016-07-12 18:03:22 +00:00
|
|
|
},
|
2017-04-13 14:09:53 +00:00
|
|
|
Before: before,
|
2016-07-12 18:03:22 +00:00
|
|
|
},
|
2016-12-26 23:14:29 +00:00
|
|
|
{
|
2017-04-13 13:53:58 +00:00
|
|
|
Name: "add",
|
|
|
|
Category: "Configuration",
|
|
|
|
Aliases: []string{"a"},
|
|
|
|
Description: "Add a project to an existing config file or create a new one.",
|
2016-12-26 23:14:29 +00:00
|
|
|
Flags: []cli.Flag{
|
2017-03-12 22:46:58 +00:00
|
|
|
&cli.StringFlag{Name: "path", Aliases: []string{"p"}, Value: "", Usage: "Project base path."},
|
|
|
|
&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: "legacy", Aliases: []string{"l"}, Value: false, Usage: "Watch by polling instead of Watch by fsnotify."},
|
|
|
|
&cli.BoolFlag{Name: "server", Aliases: []string{"s"}, Value: false, Usage: "Enable server and open into the default browser."},
|
2017-09-17 21:37:39 +00:00
|
|
|
&cli.BoolFlag{Name: "install", Aliases: []string{"i"}, Value: false, Usage: "Enable go install"},
|
|
|
|
&cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build"},
|
|
|
|
&cli.BoolFlag{Name: "run", Aliases: []string{"r"}, Value: false, Usage: "Enable go run"},
|
2016-12-26 23:14:29 +00:00
|
|
|
},
|
2017-04-13 14:09:53 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2017-09-20 13:56:31 +00:00
|
|
|
if err := r.blueprint.Add(p); err != nil {
|
2017-04-13 14:09:53 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := r.Record(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-08-31 07:54:59 +00:00
|
|
|
fmt.Fprintln(style.Output, prefix(style.Green.Bold("Your project was successfully added.")))
|
2016-12-26 23:14:29 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 14:09:53 +00:00
|
|
|
Before: before,
|
2016-12-26 23:14:29 +00:00
|
|
|
},
|
2016-07-23 22:49:19 +00:00
|
|
|
{
|
2017-04-13 13:53:58 +00:00
|
|
|
Name: "init",
|
|
|
|
Category: "Configuration",
|
|
|
|
Aliases: []string{"a"},
|
|
|
|
Description: "Define a new config file with all options step by step",
|
2017-04-13 12:49:42 +00:00
|
|
|
Action: func(p *cli.Context) (actErr error) {
|
2017-04-13 12:48:48 +00:00
|
|
|
interact.Run(&interact.Interact{
|
|
|
|
Before: func(context interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
context.SetErr(style.Red.Bold("INVALID INPUT"))
|
|
|
|
context.SetPrfx(color.Output, style.Yellow.Bold("[")+"REALIZE"+style.Yellow.Bold("]"))
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Questions: []*interact.Question{
|
2017-03-12 22:46:58 +00:00
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-09-03 17:59:56 +00:00
|
|
|
if _, err := os.Stat(settings.Directory + "/" + settings.File); err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
d.Skip()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Would you want to overwrite the existing " + style.Magenta.Bold("Realize") + " config?",
|
2017-03-12 22:46:58 +00:00
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
} else if val {
|
2017-04-13 12:48:48 +00:00
|
|
|
r.Settings = settings.Settings{
|
2017-09-03 17:59:56 +00:00
|
|
|
File: settings.File,
|
2017-04-13 12:48:48 +00:00
|
|
|
Server: settings.Server{
|
2017-04-01 17:33:21 +00:00
|
|
|
Status: false,
|
|
|
|
Open: false,
|
2017-09-20 13:56:31 +00:00
|
|
|
Host: host,
|
|
|
|
Port: port,
|
2017-04-01 17:33:21 +00:00
|
|
|
},
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects = r.blueprint.Projects[len(r.blueprint.Projects):]
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Would you want to customize the " + ("settings") + "?",
|
2017-04-13 12:48:48 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Subs: []*interact.Question{
|
2017-03-12 22:46:58 +00:00
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(0, style.Green.Regular("(os default)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[int]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Max number of open files (root required)",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Int()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-03 17:59:56 +00:00
|
|
|
r.FileLimit = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Enable legacy watch by polling",
|
2017-04-13 12:48:48 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Subs: []*interact.Question{
|
2017-03-12 22:46:58 +00:00
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(1, style.Green.Regular("(1s)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[seconds]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Set polling interval in seconds",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Int()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-03 17:59:56 +00:00
|
|
|
r.Legacy.Interval = time.Duration(val * 1000000000)
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-09-03 17:59:56 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable logging files",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-03 17:59:56 +00:00
|
|
|
r.Files.Errors = settings.Resource{Name: settings.FileErr, Status: val}
|
|
|
|
r.Files.Outputs = settings.Resource{Name: settings.FileOut, Status: val}
|
|
|
|
r.Files.Logs = settings.Resource{Name: settings.FileLog, Status: val}
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-03-19 23:19:05 +00:00
|
|
|
Msg: "Enable web server",
|
2017-04-13 12:48:48 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, _ := d.Ans().Bool()
|
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Subs: []*interact.Question{
|
2017-03-19 23:19:05 +00:00
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-09-20 13:56:31 +00:00
|
|
|
d.SetDef(port, style.Green.Regular("("+strconv.Itoa(port)+")"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[int]"),
|
2017-03-19 23:19:05 +00:00
|
|
|
Msg: "Server port",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Int()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
r.Server.Port = int(val)
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-09-20 13:56:31 +00:00
|
|
|
d.SetDef(host, style.Green.Regular("("+host+")"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[string]"),
|
2017-03-19 23:19:05 +00:00
|
|
|
Msg: "Server host",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().String()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
r.Server.Host = val
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-03-19 23:19:05 +00:00
|
|
|
Msg: "Open in the current browser",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Bool()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
r.Server.Open = val
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Bool()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
r.Server.Status = val
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
_, err := d.Ans().Bool()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(true, style.Green.Regular("(y)"))
|
2017-04-01 17:33:21 +00:00
|
|
|
d.SetEnd("!")
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Would you want to " + style.Magenta.Regular("add a new project") + "? (insert '!' to stop)",
|
2017-04-13 12:48:48 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, _ := d.Ans().Bool()
|
|
|
|
if val {
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Add(p)
|
2017-03-19 23:19:05 +00:00
|
|
|
}
|
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Subs: []*interact.Question{
|
2017-03-19 23:19:05 +00:00
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(r.Settings.Wdir(), style.Green.Regular("("+r.Settings.Wdir()+")"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[string]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Project name",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().String()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Name = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-03-19 23:19:05 +00:00
|
|
|
dir, _ := os.Getwd()
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(dir, style.Green.Regular("("+dir+")"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[string]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Project path",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().String()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Path = r.Settings.Path(val)
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2017-09-03 17:59:56 +00:00
|
|
|
|
2017-03-12 22:46:58 +00:00
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(true, style.Green.Regular("(y)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-09-03 17:59:56 +00:00
|
|
|
Msg: "Enable go vet",
|
2017-03-12 22:46:58 +00:00
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Vet = val
|
2017-04-16 10:02:47 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef(true, style.Green.Regular("(y)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-09-03 17:59:56 +00:00
|
|
|
Msg: "Enable go fmt",
|
|
|
|
Resolve: func(d interact.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*interact.Question{
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef("", style.Green.Regular("(none)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Fmt additional arguments",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().String()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
if val != "" {
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Fmt.Args = append(r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Fmt.Args, val)
|
2017-09-03 17:59:56 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2017-04-16 10:02:47 +00:00
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().Bool()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Fmt.Status = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-09-03 17:59:56 +00:00
|
|
|
d.SetDef(true, style.Green.Regular("(y)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Enable go test",
|
2017-09-03 17:59:56 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*interact.Question{
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef("", style.Green.Regular("(none)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Test additional arguments",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().String()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
if val != "" {
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Test.Args = append(r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Test.Args, val)
|
2017-09-03 17:59:56 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Test.Status = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Enable go generate",
|
2017-09-03 17:59:56 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*interact.Question{
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef("", style.Green.Regular("(none)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Generate additional arguments",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().String()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
if val != "" {
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Generate.Args = append(r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Generate.Args, val)
|
2017-09-03 17:59:56 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Generate.Status = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(true, style.Green.Regular("(y)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Enable go install",
|
2017-09-03 17:59:56 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*interact.Question{
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef("", style.Green.Regular("(none)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Install additional arguments",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().String()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
if val != "" {
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Install.Args = append(r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Install.Args, val)
|
2017-09-03 17:59:56 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Install.Status = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Enable go build",
|
2017-09-03 17:59:56 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*interact.Question{
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef("", style.Green.Regular("(none)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Build additional arguments",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().String()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
if val != "" {
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Build.Args = append(r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Build.Args, val)
|
2017-09-03 17:59:56 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Build.Status = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(true, style.Green.Regular("(y)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Enable go run",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Cmds.Run = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-04-15 18:11:05 +00:00
|
|
|
Msg: "Customize watched paths",
|
2017-04-13 12:48:48 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if val {
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Paths = r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Paths[:len(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Paths)-1]
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Subs: []*interact.Question{
|
2017-03-12 22:46:58 +00:00
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-03-19 23:19:05 +00:00
|
|
|
d.SetEnd("!")
|
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[string]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Insert a path to watch (insert '!' to stop)",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().String()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Paths = append(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Paths, val)
|
2017-03-19 23:19:05 +00:00
|
|
|
d.Reload()
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
_, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-04-15 18:11:05 +00:00
|
|
|
Msg: "Customize ignored paths",
|
2017-04-13 12:48:48 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if val {
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Ignore = r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Ignore[:len(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Ignore)-1]
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Subs: []*interact.Question{
|
2017-03-12 22:46:58 +00:00
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-03-19 23:19:05 +00:00
|
|
|
d.SetEnd("!")
|
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[string]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Insert a path to ignore (insert '!' to stop)",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().String()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Ignore = append(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Ignore, val)
|
2017-03-19 23:19:05 +00:00
|
|
|
d.Reload()
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
_, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-09-03 17:59:56 +00:00
|
|
|
Msg: "Add an additional argument",
|
2017-04-13 12:48:48 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Subs: []*interact.Question{
|
2017-03-12 22:46:58 +00:00
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-03-19 23:19:05 +00:00
|
|
|
d.SetEnd("!")
|
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[string]"),
|
2017-09-03 17:59:56 +00:00
|
|
|
Msg: "Add another argument (insert '!' to stop)",
|
2017-03-12 22:46:58 +00:00
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().String()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Args = append(r.blueprint.Projects[len(r.blueprint.Projects)-1].Args, val)
|
2017-03-19 23:19:05 +00:00
|
|
|
d.Reload()
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
_, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-09-03 17:59:56 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(none)"))
|
|
|
|
d.SetEnd("!")
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-09-03 17:59:56 +00:00
|
|
|
Msg: "Add a 'before' custom command (insert '!' to stop)",
|
2017-04-13 12:48:48 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Subs: []*interact.Question{
|
2017-03-12 22:46:58 +00:00
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[string]"),
|
2017-09-03 17:59:56 +00:00
|
|
|
Msg: "Insert a command",
|
2017-03-12 22:46:58 +00:00
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().String()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts = append(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts, watcher.Command{Type: "before", Command: val})
|
2017-09-03 17:59:56 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef("", style.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Launch from a specific path",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().String()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts[len(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts)-1].Path = val
|
2017-09-03 17:59:56 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Tag as global command",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().Bool()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts[len(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts)-1].Global = val
|
2017-09-03 17:59:56 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Display command output",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().Bool()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts[len(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts)-1].Output = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-09-03 17:59:56 +00:00
|
|
|
val, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-03 17:59:56 +00:00
|
|
|
if val {
|
|
|
|
d.Reload()
|
|
|
|
}
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-09-03 17:59:56 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(none)"))
|
|
|
|
d.SetEnd("!")
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-09-03 17:59:56 +00:00
|
|
|
Msg: "Add an 'after' custom commands (insert '!' to stop)",
|
2017-04-13 12:48:48 +00:00
|
|
|
Resolve: func(d interact.Context) bool {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Subs: []*interact.Question{
|
2017-03-12 22:46:58 +00:00
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[string]"),
|
2017-09-03 17:59:56 +00:00
|
|
|
Msg: "Insert a command",
|
2017-03-12 22:46:58 +00:00
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().String()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts = append(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts, watcher.Command{Type: "after", Command: val})
|
2017-09-03 17:59:56 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef("", style.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Launch from a specific path",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().String()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts[len(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts)-1].Path = val
|
2017-09-03 17:59:56 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Tag as global command",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().Bool()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts[len(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts)-1].Global = val
|
2017-09-03 17:59:56 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Display command output",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().Bool()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts[len(r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Scripts)-1].Output = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-09-03 17:59:56 +00:00
|
|
|
val, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-03 17:59:56 +00:00
|
|
|
if val {
|
|
|
|
d.Reload()
|
|
|
|
}
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-04-13 12:48:48 +00:00
|
|
|
Before: func(d interact.Context) error {
|
2017-04-13 13:49:51 +00:00
|
|
|
d.SetDef(false, style.Green.Regular("(n)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Quest: interact.Quest{
|
2017-04-13 13:49:51 +00:00
|
|
|
Options: style.Yellow.Regular("[y/n]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Enable watcher files preview",
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
val, err := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
return d.Err()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].Watcher.Preview = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2017-06-16 09:48:25 +00:00
|
|
|
{
|
|
|
|
Before: func(d interact.Context) error {
|
|
|
|
d.SetDef("", style.Green.Regular("(none)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: interact.Quest{
|
|
|
|
Options: style.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Set an error output pattern",
|
|
|
|
},
|
|
|
|
Action: func(d interact.Context) interface{} {
|
|
|
|
val, err := d.Ans().String()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects[len(r.blueprint.Projects)-1].ErrorOutputPattern = val
|
2017-06-16 09:48:25 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
Action: func(d interact.Context) interface{} {
|
2017-03-19 23:19:05 +00:00
|
|
|
if val, err := d.Ans().Bool(); err != nil {
|
|
|
|
return d.Err()
|
|
|
|
} else if val {
|
|
|
|
d.Reload()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-04-13 12:48:48 +00:00
|
|
|
After: func(d interact.Context) error {
|
2017-03-19 23:19:05 +00:00
|
|
|
if val, _ := d.Qns().Get(0).Ans().Bool(); val {
|
2017-09-03 17:59:56 +00:00
|
|
|
actErr = r.Settings.Remove(settings.Directory)
|
2017-04-13 12:49:42 +00:00
|
|
|
if actErr != nil {
|
|
|
|
return actErr
|
2017-03-19 23:19:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
})
|
2017-04-13 14:09:53 +00:00
|
|
|
if err := r.Record(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-09-18 01:05:00 +00:00
|
|
|
fmt.Fprintln(style.Output, prefix(style.Green.Bold(" Your configuration was successful.")))
|
2016-11-01 09:56:12 +00:00
|
|
|
return nil
|
2016-07-23 22:49:19 +00:00
|
|
|
},
|
2017-04-13 14:09:53 +00:00
|
|
|
Before: before,
|
2016-07-12 18:03:22 +00:00
|
|
|
},
|
2016-07-26 17:04:13 +00:00
|
|
|
{
|
2017-04-13 13:53:58 +00:00
|
|
|
Name: "remove",
|
|
|
|
Category: "Configuration",
|
|
|
|
Aliases: []string{"r"},
|
|
|
|
Description: "Remove a project from a realize configuration.",
|
2016-07-26 17:04:13 +00:00
|
|
|
Flags: []cli.Flag{
|
2016-08-21 07:16:01 +00:00
|
|
|
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: ""},
|
2016-07-26 17:04:13 +00:00
|
|
|
},
|
2016-07-27 09:14:32 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2017-09-20 13:56:31 +00:00
|
|
|
if err := r.blueprint.Remove(p); err != nil {
|
2017-04-13 14:09:53 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := r.Record(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-08-31 07:54:59 +00:00
|
|
|
fmt.Fprintln(style.Output, prefix(style.Green.Bold("Your project was successfully removed.")))
|
2016-11-01 09:56:12 +00:00
|
|
|
return nil
|
2016-07-26 17:04:13 +00:00
|
|
|
},
|
2017-04-13 14:09:53 +00:00
|
|
|
Before: before,
|
2016-07-26 17:04:13 +00:00
|
|
|
},
|
|
|
|
{
|
2017-04-13 13:53:58 +00:00
|
|
|
Name: "list",
|
|
|
|
Category: "Configuration",
|
|
|
|
Aliases: []string{"l"},
|
|
|
|
Description: "Print projects list.",
|
2016-07-27 09:14:32 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2017-09-20 13:56:31 +00:00
|
|
|
return r.blueprint.List()
|
2016-07-27 11:42:25 +00:00
|
|
|
},
|
2017-04-13 14:09:53 +00:00
|
|
|
Before: before,
|
2016-07-26 17:04:13 +00:00
|
|
|
},
|
2016-12-26 23:14:29 +00:00
|
|
|
{
|
2017-04-13 13:53:58 +00:00
|
|
|
Name: "clean",
|
|
|
|
Category: "Configuration",
|
|
|
|
Aliases: []string{"c"},
|
|
|
|
Description: "Remove realize folder.",
|
2016-12-26 23:14:29 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2017-09-03 17:59:56 +00:00
|
|
|
if err := r.Settings.Remove(settings.Directory); err != nil {
|
2017-04-13 14:09:53 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-08-31 07:54:59 +00:00
|
|
|
fmt.Fprintln(style.Output, prefix(style.Green.Bold("Realize folder successfully removed.")))
|
2016-12-26 23:14:29 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-04-13 14:09:53 +00:00
|
|
|
Before: before,
|
2016-12-26 23:14:29 +00:00
|
|
|
},
|
2016-07-12 18:03:22 +00:00
|
|
|
},
|
|
|
|
}
|
2017-04-13 14:09:53 +00:00
|
|
|
if err := app.Run(os.Args); err != nil {
|
2017-08-27 11:45:06 +00:00
|
|
|
print(style.Red.Bold(err))
|
2017-04-13 14:09:53 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
2016-08-17 23:35:37 +00:00
|
|
|
}
|
2017-08-27 11:45:06 +00:00
|
|
|
|
|
|
|
// Prefix a given string
|
|
|
|
func prefix(s string) string {
|
|
|
|
if s != "" {
|
|
|
|
return fmt.Sprint(style.Yellow.Bold("[")+"REALIZE"+style.Yellow.Bold("]"), s)
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before is launched before each command
|
|
|
|
func before(*cli.Context) error {
|
|
|
|
// Before of every exec of a cli method
|
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
if gopath == "" {
|
|
|
|
return errors.New("$GOPATH isn't set properly")
|
|
|
|
}
|
|
|
|
r = realize{
|
|
|
|
Sync: make(chan string),
|
|
|
|
Settings: settings.Settings{
|
2017-09-03 17:59:56 +00:00
|
|
|
File: settings.File,
|
2017-08-27 11:45:06 +00:00
|
|
|
Server: settings.Server{
|
|
|
|
Status: false,
|
|
|
|
Open: false,
|
2017-09-20 13:56:31 +00:00
|
|
|
Host: host,
|
|
|
|
Port: port,
|
2017-08-27 11:45:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint = watcher.Blueprint{
|
2017-08-27 11:45:06 +00:00
|
|
|
Settings: &r.Settings,
|
|
|
|
Sync: r.Sync,
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.server = server{
|
|
|
|
Blueprint: &r.blueprint,
|
2017-08-27 11:45:06 +00:00
|
|
|
Settings: &r.Settings,
|
|
|
|
Sync: r.Sync,
|
|
|
|
}
|
2017-09-20 13:56:31 +00:00
|
|
|
r.projects = &r.blueprint.Projects
|
2017-08-27 11:45:06 +00:00
|
|
|
// read if exist
|
|
|
|
r.Read(&r)
|
|
|
|
// increase the file limit
|
2017-09-03 17:59:56 +00:00
|
|
|
if r.FileLimit != 0 {
|
2017-08-27 11:45:06 +00:00
|
|
|
if err := r.Flimit(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for polling option
|
|
|
|
func polling(c *cli.Context, s *settings.Legacy) {
|
|
|
|
if c.Bool("legacy") {
|
2017-09-03 17:59:56 +00:00
|
|
|
s.Interval = settings.Interval
|
2017-08-27 11:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert a project if there isn't already one
|
|
|
|
func insert(c *cli.Context, b *watcher.Blueprint) error {
|
2017-09-18 01:05:00 +00:00
|
|
|
if c.Bool("no-config") {
|
2017-09-20 13:56:31 +00:00
|
|
|
r.blueprint.Projects = []watcher.Project{}
|
2017-09-18 01:05:00 +00:00
|
|
|
}
|
2017-08-27 11:45:06 +00:00
|
|
|
if len(b.Projects) <= 0 {
|
|
|
|
if err := b.Add(c); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|