2016-07-12 08:18:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-11-01 09:56:12 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2017-03-12 22:46:58 +00:00
|
|
|
"github.com/fatih/color"
|
|
|
|
i "github.com/tockins/interact"
|
2016-11-01 09:56:12 +00:00
|
|
|
s "github.com/tockins/realize/server"
|
|
|
|
c "github.com/tockins/realize/settings"
|
|
|
|
w "github.com/tockins/realize/watcher"
|
2016-08-17 23:35:37 +00:00
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
"os"
|
2017-03-12 22:46:58 +00:00
|
|
|
"time"
|
2016-07-12 08:18:02 +00:00
|
|
|
)
|
|
|
|
|
2016-11-01 09:56:12 +00:00
|
|
|
const (
|
|
|
|
name = "Realize"
|
2016-12-26 23:14:29 +00:00
|
|
|
version = "1.3"
|
2016-11-01 09:56:12 +00:00
|
|
|
description = "A Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths"
|
|
|
|
config = "realize.yaml"
|
2016-12-26 23:14:29 +00:00
|
|
|
outputs = "outputs.log"
|
2016-12-18 23:30:58 +00:00
|
|
|
errs = "errors.log"
|
|
|
|
logs = "logs.log"
|
2016-11-01 09:56:12 +00:00
|
|
|
host = "localhost"
|
2016-12-18 23:30:58 +00:00
|
|
|
port = 5001
|
2017-03-12 22:46:58 +00:00
|
|
|
interval = 200
|
2016-11-01 09:56:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var r realize
|
|
|
|
|
|
|
|
// Realize struct contains the general app informations
|
|
|
|
type realize struct {
|
|
|
|
c.Settings `yaml:"settings,omitempty"`
|
|
|
|
Name, Description, Author, Email, Host, Version string `yaml:"-"`
|
|
|
|
Sync chan string `yaml:"-"`
|
|
|
|
Blueprint w.Blueprint `yaml:"-"`
|
|
|
|
Server s.Server `yaml:"-"`
|
2016-11-20 16:58:52 +00:00
|
|
|
Projects *[]w.Project `yaml:"projects" json:"projects"`
|
2016-11-01 09:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Realize struct initialization
|
|
|
|
func init() {
|
|
|
|
r = realize{
|
|
|
|
Name: name,
|
|
|
|
Version: version,
|
|
|
|
Description: description,
|
|
|
|
Sync: make(chan string),
|
|
|
|
Settings: c.Settings{
|
2017-03-12 22:46:58 +00:00
|
|
|
Config: c.Config{
|
|
|
|
Create: true,
|
|
|
|
},
|
2016-11-01 09:56:12 +00:00
|
|
|
Resources: c.Resources{
|
2016-12-18 23:30:58 +00:00
|
|
|
Config: config,
|
2016-12-26 23:14:29 +00:00
|
|
|
Outputs: outputs,
|
2016-12-18 23:30:58 +00:00
|
|
|
Logs: logs,
|
|
|
|
Errors: errs,
|
2016-11-01 09:56:12 +00:00
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Server: c.Server{
|
2017-03-20 00:14:56 +00:00
|
|
|
Status: false,
|
2017-03-12 22:46:58 +00:00
|
|
|
Open: false,
|
|
|
|
Host: host,
|
|
|
|
Port: port,
|
|
|
|
},
|
2016-11-01 09:56:12 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
r.Blueprint = w.Blueprint{
|
|
|
|
Settings: &r.Settings,
|
|
|
|
Sync: r.Sync,
|
|
|
|
}
|
|
|
|
r.Server = s.Server{
|
|
|
|
Blueprint: &r.Blueprint,
|
|
|
|
Settings: &r.Settings,
|
|
|
|
Sync: r.Sync,
|
|
|
|
}
|
|
|
|
r.Projects = &r.Blueprint.Projects
|
2016-09-01 22:17:19 +00:00
|
|
|
|
2016-11-01 09:56:12 +00:00
|
|
|
// read if exist
|
|
|
|
r.Read(&r)
|
|
|
|
|
|
|
|
// increase the file limit
|
|
|
|
if r.Config.Flimit != 0 {
|
|
|
|
r.Flimit()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before of every exec of a cli method
|
|
|
|
func before() error {
|
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
if gopath == "" {
|
|
|
|
return handle(errors.New("$GOPATH isn't set up properly"))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle errors
|
|
|
|
func handle(err error) error {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(r.Red.Bold(err.Error()))
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cli commands
|
2016-07-12 08:18:02 +00:00
|
|
|
func main() {
|
2017-03-12 22:46:58 +00:00
|
|
|
app := &cli.App{
|
2016-11-01 09:56:12 +00:00
|
|
|
Name: r.Name,
|
|
|
|
Version: r.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
|
|
|
},
|
|
|
|
},
|
2016-11-01 09:56:12 +00:00
|
|
|
Usage: r.Description,
|
2016-07-12 18:03:22 +00:00
|
|
|
Commands: []*cli.Command{
|
|
|
|
{
|
2016-12-26 23:14:29 +00:00
|
|
|
Name: "run",
|
|
|
|
Aliases: []string{"r"},
|
2017-03-12 22:46:58 +00:00
|
|
|
Usage: "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."},
|
|
|
|
&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."},
|
|
|
|
&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."},
|
|
|
|
&cli.BoolFlag{Name: "no-run", Aliases: []string{"nr"}, Value: false, Usage: "Disable go run"},
|
|
|
|
&cli.BoolFlag{Name: "no-install", Aliases: []string{"ni"}, Value: false, Usage: "Disable go install"},
|
|
|
|
&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-03-12 22:46:58 +00:00
|
|
|
if p.Bool("legacy") {
|
|
|
|
r.Config.Legacy = c.Legacy{
|
|
|
|
Status: p.Bool("legacy"),
|
|
|
|
Interval: interval,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if p.Bool("no-config") || len(r.Blueprint.Projects) <= 0 {
|
|
|
|
if p.Bool("no-config") {
|
|
|
|
r.Config.Create = false
|
|
|
|
}
|
2016-12-26 23:14:29 +00:00
|
|
|
r.Blueprint.Projects = []w.Project{}
|
|
|
|
handle(r.Blueprint.Add(p))
|
2016-11-01 09:56:12 +00:00
|
|
|
}
|
2017-03-20 00:52:29 +00:00
|
|
|
if p.Bool("server") {
|
|
|
|
handle(r.Server.Start(p))
|
|
|
|
}
|
2016-11-14 07:59:47 +00:00
|
|
|
handle(r.Blueprint.Run())
|
2016-11-20 16:58:52 +00:00
|
|
|
handle(r.Record(r))
|
2016-11-01 09:56:12 +00:00
|
|
|
return nil
|
2016-07-12 18:03:22 +00:00
|
|
|
},
|
2016-07-27 11:42:25 +00:00
|
|
|
Before: func(c *cli.Context) error {
|
2016-11-01 09:56:12 +00:00
|
|
|
return before()
|
2016-07-27 11:42:25 +00:00
|
|
|
},
|
2016-07-12 18:03:22 +00:00
|
|
|
},
|
2016-12-26 23:14:29 +00:00
|
|
|
{
|
2017-03-12 22:46:58 +00:00
|
|
|
Name: "add",
|
2016-12-26 23:14:29 +00:00
|
|
|
Category: "Configuration",
|
2017-03-12 22:46:58 +00:00
|
|
|
Aliases: []string{"a"},
|
|
|
|
Usage: "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: "build", Aliases: []string{"b"}, Value: false, Usage: "Enable go build."},
|
|
|
|
&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."},
|
|
|
|
&cli.BoolFlag{Name: "no-run", Aliases: []string{"nr"}, Value: false, Usage: "Disable go run"},
|
|
|
|
&cli.BoolFlag{Name: "no-fmt", Aliases: []string{"nf"}, Value: false, Usage: "Disable go fmt."},
|
|
|
|
&cli.BoolFlag{Name: "no-install", Aliases: []string{"ni"}, Value: false, Usage: "Disable go install"},
|
|
|
|
&cli.BoolFlag{Name: "no-config", Aliases: []string{"nc"}, Value: false, Usage: "Ignore existing configurations."},
|
2016-12-26 23:14:29 +00:00
|
|
|
},
|
|
|
|
Action: func(p *cli.Context) (err error) {
|
2017-03-12 22:46:58 +00:00
|
|
|
fmt.Println(p.String("path"))
|
|
|
|
handle(r.Blueprint.Add(p))
|
2016-12-26 23:14:29 +00:00
|
|
|
handle(r.Record(r))
|
2017-03-19 23:31:52 +00:00
|
|
|
fmt.Println(r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]"), r.Green.Bold("Your project was successfully added."))
|
2016-12-26 23:14:29 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Before: func(c *cli.Context) error {
|
|
|
|
return before()
|
|
|
|
},
|
|
|
|
},
|
2016-07-23 22:49:19 +00:00
|
|
|
{
|
2017-03-12 22:46:58 +00:00
|
|
|
Name: "init",
|
2016-08-31 12:08:15 +00:00
|
|
|
Category: "Configuration",
|
2016-08-17 23:35:37 +00:00
|
|
|
Aliases: []string{"a"},
|
2017-03-12 22:46:58 +00:00
|
|
|
Usage: "Define a new config file with all options step by step",
|
2016-11-01 09:56:12 +00:00
|
|
|
Action: func(p *cli.Context) (err error) {
|
2017-03-12 22:46:58 +00:00
|
|
|
i.Run(&i.Interact{
|
|
|
|
Before: func(context i.Context) error {
|
|
|
|
context.SetErr(r.Red.Bold("INVALID INPUT"))
|
|
|
|
context.SetPrfx(color.Output, r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Questions: []*i.Question{
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
2017-03-12 22:46:58 +00:00
|
|
|
if _, err := os.Stat(".realize/" + config); err != nil {
|
2017-03-19 23:19:05 +00:00
|
|
|
d.Skip()
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
2017-03-19 23:19:05 +00:00
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
2017-03-19 23:19:05 +00:00
|
|
|
Msg: "Would you want to overwrite the existing " + r.Colors.Magenta.Bold("Realize") + " config?",
|
2017-03-12 22:46:58 +00:00
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-01 17:33:21 +00:00
|
|
|
r.Settings = c.Settings{
|
|
|
|
Config: c.Config{
|
|
|
|
Create: true,
|
|
|
|
},
|
|
|
|
Resources: c.Resources{
|
|
|
|
Config: config,
|
|
|
|
Outputs: outputs,
|
|
|
|
Logs: logs,
|
|
|
|
Errors: errs,
|
|
|
|
},
|
|
|
|
Server: c.Server{
|
|
|
|
Status: false,
|
|
|
|
Open: false,
|
|
|
|
Host: host,
|
|
|
|
Port: port,
|
|
|
|
},
|
|
|
|
}
|
2017-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects = r.Blueprint.Projects[len(r.Blueprint.Projects):]
|
2017-03-12 22:46:58 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
2017-03-20 00:39:25 +00:00
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
2017-04-01 17:10:45 +00:00
|
|
|
Msg: "Would you want to customize the " + r.Colors.Magenta.Bold("settings") + "?",
|
2017-03-19 23:19:05 +00:00
|
|
|
Resolve: func(d i.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*i.Question{
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(0, r.Green.Regular("(os default)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[int]"),
|
|
|
|
Msg: "Max number of open files (root required)",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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
|
|
|
}
|
|
|
|
r.Config.Flimit = val
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable legacy watch by polling",
|
2017-03-19 23:19:05 +00:00
|
|
|
Resolve: func(d i.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*i.Question{
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(1, r.Green.Regular("(1s)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
2017-04-01 17:10:45 +00:00
|
|
|
Options: r.Yellow.Regular("[seconds]"),
|
2017-03-12 22:46:58 +00:00
|
|
|
Msg: "Set polling interval in seconds",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-13 00:04:48 +00:00
|
|
|
r.Config.Legacy.Interval = time.Duration(val * 1000000000)
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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
|
|
|
}
|
|
|
|
r.Config.Legacy.Status = val
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable web server",
|
|
|
|
Resolve: func(d i.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*i.Question{
|
|
|
|
{
|
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(5001, r.Green.Regular("(5001)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[int]"),
|
|
|
|
Msg: "Server port",
|
|
|
|
},
|
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
val, err := d.Ans().Int()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
r.Server.Port = int(val)
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef("localhost", r.Green.Regular("(localhost)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Server host",
|
|
|
|
},
|
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
val, err := d.Ans().String()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
r.Server.Host = val
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Open in the current browser",
|
|
|
|
},
|
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
val, err := d.Ans().Bool()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
r.Server.Open = val
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
val, err := d.Ans().Bool()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
r.Server.Status = val
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
_, err := d.Ans().Bool()
|
|
|
|
if err != nil {
|
|
|
|
return d.Err()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(true, r.Green.Regular("(y)"))
|
2017-04-01 17:33:21 +00:00
|
|
|
d.SetEnd("!")
|
2017-03-19 23:19:05 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
2017-04-01 17:33:21 +00:00
|
|
|
Msg: "Would you want to " + r.Colors.Magenta.Regular("add a new project") + "? (insert '!' to stop)",
|
2017-03-19 23:19:05 +00:00
|
|
|
Resolve: func(d i.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
|
|
|
if val {
|
|
|
|
r.Blueprint.Add(p)
|
|
|
|
}
|
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*i.Question{
|
|
|
|
{
|
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(r.Settings.Wdir(), r.Green.Regular("("+r.Settings.Wdir()+")"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Project name",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Name = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
dir, _ := os.Getwd()
|
|
|
|
d.SetDef(dir, r.Green.Regular("("+dir+")"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Project path",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +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-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(true, r.Green.Regular("(y)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable go fmt",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Fmt = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable go test",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Test = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable go generate",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Generate = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(true, r.Green.Regular("(y)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable go install",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Bin = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable go build",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Build = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(true, r.Green.Regular("(y)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable go run",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-20 00:39:25 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Run = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
2017-03-19 23:19:05 +00:00
|
|
|
Msg: "Customize the watched paths",
|
|
|
|
Resolve: func(d i.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if val {
|
2017-03-19 23:19:05 +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
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*i.Question{
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetEnd("!")
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Insert a path to watch (insert '!' to stop)",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Watcher.Paths = append(r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Watcher.Paths, val)
|
|
|
|
d.Reload()
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
_, 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-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
2017-03-19 23:19:05 +00:00
|
|
|
Msg: "Customize the ignored paths",
|
|
|
|
Resolve: func(d i.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
if val {
|
2017-03-19 23:19:05 +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
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*i.Question{
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetEnd("!")
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Insert a path to ignore (insert '!' to stop)",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Watcher.Ignore = append(r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Watcher.Ignore, val)
|
|
|
|
d.Reload()
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
_, 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-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
2017-03-19 23:19:05 +00:00
|
|
|
Msg: "Add additionals arguments",
|
|
|
|
Resolve: func(d i.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*i.Question{
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetEnd("!")
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Insert an argument (insert '!' to stop)",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Params = append(r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Params, val)
|
|
|
|
d.Reload()
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
_, 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-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
2017-03-19 23:19:05 +00:00
|
|
|
Msg: "Add 'before' custom commands",
|
|
|
|
Resolve: func(d i.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*i.Question{
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetEnd("!")
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Insert a command (insert '!' to stop)",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Watcher.Scripts = append(r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Watcher.Scripts, w.Command{Type: "before", Command: val})
|
|
|
|
d.Reload()
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
_, 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-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
2017-03-19 23:19:05 +00:00
|
|
|
Msg: "Add 'after' custom commands",
|
|
|
|
Resolve: func(d i.Context) bool {
|
|
|
|
val, _ := d.Ans().Bool()
|
2017-03-12 22:46:58 +00:00
|
|
|
return val
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subs: []*i.Question{
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetEnd("!")
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[string]"),
|
|
|
|
Msg: "Insert a command (insert '!' to stop)",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Watcher.Scripts = append(r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Watcher.Scripts, w.Command{Type: "after", Command: val})
|
|
|
|
d.Reload()
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
_, 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-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable watcher files preview",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-20 00:39:25 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Watcher.Preview = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable file output history",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Streams.FileOut = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable file logs history",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Streams.FileLog = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-03-19 23:19:05 +00:00
|
|
|
Before: func(d i.Context) error {
|
|
|
|
d.SetDef(false, r.Green.Regular("(n)"))
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
Quest: i.Quest{
|
|
|
|
Options: r.Yellow.Regular("[y/n]"),
|
|
|
|
Msg: "Enable file errors history",
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Streams.FileErr = val
|
2017-03-12 22:46:58 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-19 23:19:05 +00:00
|
|
|
Action: func(d i.Context) interface{} {
|
|
|
|
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-03-19 23:19:05 +00:00
|
|
|
After: func(d i.Context) error {
|
|
|
|
if val, _ := d.Qns().Get(0).Ans().Bool(); val {
|
|
|
|
err = r.Settings.Remove()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
2017-03-12 22:46:58 +00:00
|
|
|
})
|
2016-11-01 09:56:12 +00:00
|
|
|
handle(r.Record(r))
|
2017-04-01 17:10:45 +00:00
|
|
|
fmt.Println(r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]"), r.Green.Bold("Your configuration was successful."))
|
2016-11-01 09:56:12 +00:00
|
|
|
return nil
|
2016-07-23 22:49:19 +00:00
|
|
|
},
|
2016-07-27 11:42:25 +00:00
|
|
|
Before: func(c *cli.Context) error {
|
2016-11-01 09:56:12 +00:00
|
|
|
return before()
|
2016-07-27 11:42:25 +00:00
|
|
|
},
|
2016-07-12 18:03:22 +00:00
|
|
|
},
|
2016-07-26 17:04:13 +00:00
|
|
|
{
|
|
|
|
Name: "remove",
|
2016-08-31 12:08:15 +00:00
|
|
|
Category: "Configuration",
|
2016-08-17 23:35:37 +00:00
|
|
|
Aliases: []string{"r"},
|
2017-03-12 22:46:58 +00:00
|
|
|
Usage: "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 {
|
2016-11-01 09:56:12 +00:00
|
|
|
handle(r.Blueprint.Remove(p))
|
|
|
|
handle(r.Record(r))
|
2017-03-19 23:31:52 +00:00
|
|
|
fmt.Println(r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]"), r.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
|
|
|
},
|
2016-07-27 11:42:25 +00:00
|
|
|
Before: func(c *cli.Context) error {
|
2016-11-01 09:56:12 +00:00
|
|
|
return before()
|
2016-07-27 11:42:25 +00:00
|
|
|
},
|
2016-07-26 17:04:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "list",
|
2016-08-31 12:08:15 +00:00
|
|
|
Category: "Configuration",
|
2016-08-17 23:35:37 +00:00
|
|
|
Aliases: []string{"l"},
|
2017-03-12 22:46:58 +00:00
|
|
|
Usage: "Print projects list.",
|
2016-07-27 09:14:32 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2016-11-01 09:56:12 +00:00
|
|
|
return handle(r.Blueprint.List())
|
2016-07-26 17:04:13 +00:00
|
|
|
},
|
2016-07-27 11:42:25 +00:00
|
|
|
Before: func(c *cli.Context) error {
|
2016-11-01 09:56:12 +00:00
|
|
|
return before()
|
2016-07-27 11:42:25 +00:00
|
|
|
},
|
2016-07-26 17:04:13 +00:00
|
|
|
},
|
2016-12-26 23:14:29 +00:00
|
|
|
{
|
|
|
|
Name: "clean",
|
|
|
|
Category: "Configuration",
|
|
|
|
Aliases: []string{"c"},
|
2017-03-12 22:46:58 +00:00
|
|
|
Usage: "Remove realize folder.",
|
2016-12-26 23:14:29 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
|
|
|
handle(r.Settings.Remove())
|
2017-03-19 23:31:52 +00:00
|
|
|
fmt.Println(r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]"), r.Green.Bold("Realize folder successfully removed."))
|
2016-12-26 23:14:29 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Before: func(c *cli.Context) error {
|
|
|
|
return before()
|
|
|
|
},
|
|
|
|
},
|
2016-07-12 18:03:22 +00:00
|
|
|
},
|
|
|
|
}
|
2017-03-12 22:46:58 +00:00
|
|
|
app.Run(os.Args)
|
2016-08-17 23:35:37 +00:00
|
|
|
}
|