realize/realize.go

911 lines
28 KiB
Go
Raw Normal View History

2016-07-12 08:18:02 +00:00
package main
import (
2016-11-01 09:56:12 +00:00
"errors"
"fmt"
"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"
"time"
2016-07-12 08:18:02 +00:00
)
2016-11-01 09:56:12 +00:00
const (
name = "Realize"
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"
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
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{
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,
Outputs: outputs,
2016-12-18 23:30:58 +00:00
Logs: logs,
Errors: errs,
2016-11-01 09:56:12 +00:00
},
Server: c.Server{
Status: true,
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() {
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",
2016-11-01 09:56:12 +00:00
Email: "pracchia@hastegit",
2016-08-23 13:17:44 +00:00
},
{
Name: "Daniele Conventi",
2016-11-01 09:56:12 +00:00
Email: "conventi@hastegit",
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{
{
Name: "run",
Aliases: []string{"r"},
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{
&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 {
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
}
r.Blueprint.Projects = []w.Project{}
handle(r.Blueprint.Add(p))
2016-11-01 09:56:12 +00:00
}
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
},
{
Name: "add",
Category: "Configuration",
Aliases: []string{"a"},
Usage: "Add a project to an existing config file or create a new one.",
Flags: []cli.Flag{
&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."},
},
Action: func(p *cli.Context) (err error) {
fmt.Println(p.String("path"))
handle(r.Blueprint.Add(p))
handle(r.Record(r))
fmt.Println(r.Green.Bold("Your project was successfully added."))
return nil
},
Before: func(c *cli.Context) error {
return before()
},
},
2016-07-23 22:49:19 +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"},
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) {
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 {
if _, err := os.Stat(".realize/" + config); err != nil {
2017-03-19 23:19:05 +00:00
d.Skip()
}
2017-03-19 23:19:05 +00:00
d.SetDef(false, r.Green.Regular("(n)"))
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-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
val, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
} else if val {
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects = r.Blueprint.Projects[len(r.Blueprint.Projects):]
}
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
},
Quest: i.Quest{
Options: r.Yellow.Regular("[y/n]"),
2017-03-19 23:19:05 +00:00
Msg: "Would you want to customize the " + r.Colors.Magenta.Bold("settings") + " ?",
Resolve: func(d i.Context) bool {
val, _ := d.Ans().Bool()
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
},
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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
},
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()
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
},
Quest: i.Quest{
Options: r.Yellow.Regular("[int]"),
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-13 00:04:48 +00:00
r.Config.Legacy.Interval = time.Duration(val * 1000000000)
return nil
},
},
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
val, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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)"))
d.SetEnd("!done")
return nil
},
Quest: i.Quest{
Options: r.Yellow.Regular("[y/n]"),
Msg: "Would you want to " + r.Colors.Magenta.Regular("add a new project") + " ?",
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
},
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Name = val
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
},
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Path = r.Settings.Path(val)
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
},
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Fmt = 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 go test",
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
val, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Test = 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 go generate",
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
val, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Generate = val
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
},
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Bin = 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 go build",
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
val, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Build = val
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
},
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Bin = 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]"),
2017-03-19 23:19:05 +00:00
Msg: "Customize the watched paths",
Resolve: func(d i.Context) bool {
val, _ := d.Ans().Bool()
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]
}
return val
},
},
Subs: []*i.Question{
{
2017-03-19 23:19:05 +00:00
Before: func(d i.Context) error {
d.SetEnd("!")
return nil
},
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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()
return nil
},
},
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
_, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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]"),
2017-03-19 23:19:05 +00:00
Msg: "Customize the ignored paths",
Resolve: func(d i.Context) bool {
val, _ := d.Ans().Bool()
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]
}
return val
},
},
Subs: []*i.Question{
{
2017-03-19 23:19:05 +00:00
Before: func(d i.Context) error {
d.SetEnd("!")
return nil
},
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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()
return nil
},
},
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
_, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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]"),
2017-03-19 23:19:05 +00:00
Msg: "Add additionals arguments",
Resolve: func(d i.Context) bool {
val, _ := d.Ans().Bool()
return val
},
},
Subs: []*i.Question{
{
2017-03-19 23:19:05 +00:00
Before: func(d i.Context) error {
d.SetEnd("!")
return nil
},
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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()
return nil
},
},
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
_, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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]"),
2017-03-19 23:19:05 +00:00
Msg: "Add 'before' custom commands",
Resolve: func(d i.Context) bool {
val, _ := d.Ans().Bool()
return val
},
},
Subs: []*i.Question{
{
2017-03-19 23:19:05 +00:00
Before: func(d i.Context) error {
d.SetEnd("!")
return nil
},
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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()
return nil
},
},
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
_, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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]"),
2017-03-19 23:19:05 +00:00
Msg: "Add 'after' custom commands",
Resolve: func(d i.Context) bool {
val, _ := d.Ans().Bool()
return val
},
},
Subs: []*i.Question{
{
2017-03-19 23:19:05 +00:00
Before: func(d i.Context) error {
d.SetEnd("!")
return nil
},
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()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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()
return nil
},
},
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
_, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
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 watcher files preview",
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
val, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Run = 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 file output history",
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
val, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Streams.FileOut = 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 file logs history",
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
val, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Streams.FileLog = 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 file errors history",
},
2017-03-19 23:19:05 +00:00
Action: func(d i.Context) interface{} {
val, err := d.Ans().Bool()
if err != nil {
2017-03-19 23:19:05 +00:00
return d.Err()
}
2017-03-19 23:19:05 +00:00
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Streams.FileErr = val
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()
}
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
},
})
2016-11-01 09:56:12 +00:00
handle(r.Record(r))
fmt.Println(r.Green.Bold("Your project was successfully added."))
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"},
Usage: "Remove a project from a realize configuration.",
2016-07-26 17:04:13 +00:00
Flags: []cli.Flag{
&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))
fmt.Println(r.Green.Bold("Your project was successfully removed."))
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"},
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
},
{
Name: "clean",
Category: "Configuration",
Aliases: []string{"c"},
Usage: "Remove realize folder.",
Action: func(p *cli.Context) error {
handle(r.Settings.Remove())
fmt.Println(r.Green.Bold("Realize folder successfully removed."))
return nil
},
Before: func(c *cli.Context) error {
return before()
},
},
2016-07-12 18:03:22 +00:00
},
}
app.Run(os.Args)
2016-08-17 23:35:37 +00:00
}