init cmd improved
This commit is contained in:
parent
8bad0c3cad
commit
f613fef73a
655
realize.go
655
realize.go
@ -192,44 +192,205 @@ func main() {
|
|||||||
Action: func(p *cli.Context) (err error) {
|
Action: func(p *cli.Context) (err error) {
|
||||||
i.Run(&i.Interact{
|
i.Run(&i.Interact{
|
||||||
Before: func(context i.Context) error {
|
Before: func(context i.Context) error {
|
||||||
r.Blueprint.Add(p)
|
|
||||||
context.SetErr(r.Red.Bold("INVALID INPUT"))
|
context.SetErr(r.Red.Bold("INVALID INPUT"))
|
||||||
context.SetPrfx(color.Output, r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]"))
|
context.SetPrfx(color.Output, r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]"))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Questions: []*i.Question{
|
Questions: []*i.Question{
|
||||||
{
|
{
|
||||||
Before: func(c i.Context) error {
|
Before: func(d i.Context) error {
|
||||||
if _, err := os.Stat(".realize/" + config); err != nil {
|
if _, err := os.Stat(".realize/" + config); err != nil {
|
||||||
c.Skip()
|
d.Skip()
|
||||||
}
|
}
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
Msg: "Would you want to overwrite the existing " + r.Colors.Magenta.Bold("Realize") + " config?",
|
||||||
Msg: "Would you want overwrite the existing Realize config?",
|
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().Bool()
|
val, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
} else if val {
|
} else if val {
|
||||||
err = r.Settings.Remove()
|
r.Blueprint.Projects = r.Blueprint.Projects[len(r.Blueprint.Projects):]
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(true, r.Green.Regular("(y)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
Msg: "Would you want to customize the " + r.Colors.Magenta.Bold("settings") + " ?",
|
||||||
Msg: "Would you want customize the general settings?",
|
Resolve: func(d i.Context) bool {
|
||||||
Resolve: func(c i.Context) bool {
|
val, _ := d.Ans().Bool()
|
||||||
val, _ := c.Ans().Bool()
|
return val
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Subs: []*i.Question{
|
||||||
|
{
|
||||||
|
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)",
|
||||||
|
},
|
||||||
|
Action: func(d i.Context) interface{} {
|
||||||
|
val, err := d.Ans().Int()
|
||||||
|
if err != nil {
|
||||||
|
return d.Err()
|
||||||
|
}
|
||||||
|
r.Config.Flimit = 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: "Enable legacy watch by polling",
|
||||||
|
Resolve: func(d i.Context) bool {
|
||||||
|
val, _ := d.Ans().Bool()
|
||||||
|
return val
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Subs: []*i.Question{
|
||||||
|
{
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
Action: func(d i.Context) interface{} {
|
||||||
|
val, err := d.Ans().Int()
|
||||||
|
if err != nil {
|
||||||
|
return d.Err()
|
||||||
|
}
|
||||||
|
r.Config.Legacy.Interval = time.Duration(val * 1000000000)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(d i.Context) interface{} {
|
||||||
|
val, err := d.Ans().Bool()
|
||||||
|
if err != nil {
|
||||||
|
return d.Err()
|
||||||
|
}
|
||||||
|
r.Config.Legacy.Status = 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: "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 {
|
if val {
|
||||||
r.Blueprint.Add(p)
|
r.Blueprint.Add(p)
|
||||||
}
|
}
|
||||||
@ -238,512 +399,458 @@ func main() {
|
|||||||
},
|
},
|
||||||
Subs: []*i.Question{
|
Subs: []*i.Question{
|
||||||
{
|
{
|
||||||
Quest: i.Quest{
|
Before: func(d i.Context) error {
|
||||||
Options: r.Yellow.Regular("[int]"),
|
d.SetDef(r.Settings.Wdir(), r.Green.Regular("("+r.Settings.Wdir()+")"))
|
||||||
Default: i.Default{Value: 0, Preview: true, Text: r.Green.Regular("(os default)")},
|
|
||||||
Msg: "Max number of open files (root required)",
|
|
||||||
},
|
|
||||||
Action: func(c i.Context) interface{} {
|
|
||||||
val, err := c.Ans().Int()
|
|
||||||
if err != nil {
|
|
||||||
return c.Err()
|
|
||||||
}
|
|
||||||
r.Config.Flimit = val
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
|
||||||
{
|
|
||||||
Quest: i.Quest{
|
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
|
||||||
Msg: "Enable legacy watch by polling",
|
|
||||||
Resolve: func(c i.Context) bool {
|
|
||||||
val, _ := c.Ans().Bool()
|
|
||||||
return val
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Subs: []*i.Question{
|
|
||||||
{
|
|
||||||
Quest: i.Quest{
|
|
||||||
Options: r.Yellow.Regular("[int]"),
|
|
||||||
Default: i.Default{Value: 1, Preview: true, Text: r.Green.Regular("(1s)")},
|
|
||||||
Msg: "Set polling interval in seconds",
|
|
||||||
},
|
|
||||||
Action: func(c i.Context) interface{} {
|
|
||||||
val, err := c.Ans().Int()
|
|
||||||
if err != nil {
|
|
||||||
return c.Err()
|
|
||||||
}
|
|
||||||
r.Config.Legacy.Interval = time.Duration(val * 1000000000)
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Action: func(c i.Context) interface{} {
|
|
||||||
val, err := c.Ans().Bool()
|
|
||||||
if err != nil {
|
|
||||||
return c.Err()
|
|
||||||
}
|
|
||||||
r.Config.Legacy.Status = val
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[string]"),
|
Options: r.Yellow.Regular("[string]"),
|
||||||
Default: i.Default{Value: r.Settings.Wdir(), Preview: true, Text: r.Green.Regular("(" + r.Settings.Wdir() + ")")},
|
|
||||||
Msg: "Project name",
|
Msg: "Project name",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().String()
|
val, err := d.Ans().String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Name = val
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Name = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
dir, _ := os.Getwd()
|
||||||
|
d.SetDef(dir, r.Green.Regular("("+dir+")"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[string]"),
|
Options: r.Yellow.Regular("[string]"),
|
||||||
Default: i.Default{Value: "", Preview: true, Text: r.Green.Regular("(current wdir)")},
|
|
||||||
Msg: "Project path",
|
Msg: "Project path",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().String()
|
val, err := d.Ans().String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Path = r.Settings.Path(val)
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Path = r.Settings.Path(val)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(true, r.Green.Regular("(y)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: true, Preview: true, Text: r.Green.Regular("(y)")},
|
|
||||||
Msg: "Enable go fmt",
|
Msg: "Enable go fmt",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().Bool()
|
val, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Fmt = val
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Fmt = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
|
||||||
Msg: "Enable go test",
|
Msg: "Enable go test",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().Bool()
|
val, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Test = val
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Test = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
|
||||||
Msg: "Enable go generate",
|
Msg: "Enable go generate",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().Bool()
|
val, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Generate = val
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Generate = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(true, r.Green.Regular("(y)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: true, Preview: true, Text: r.Green.Regular("(y)")},
|
|
||||||
Msg: "Enable go install",
|
Msg: "Enable go install",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().Bool()
|
val, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Bin = val
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Bin = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
|
||||||
Msg: "Enable go build",
|
Msg: "Enable go build",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().Bool()
|
val, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Build = val
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Build = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(true, r.Green.Regular("(y)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: true, Preview: true, Text: r.Green.Regular("(y)")},
|
|
||||||
Msg: "Enable go run",
|
Msg: "Enable go run",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().Bool()
|
val, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Run = val
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Bin = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
Msg: "Customize the watched paths",
|
||||||
Msg: "Would you want customize the watched paths?",
|
Resolve: func(d i.Context) bool {
|
||||||
Resolve: func(c i.Context) bool {
|
val, _ := d.Ans().Bool()
|
||||||
val, _ := c.Ans().Bool()
|
|
||||||
if val {
|
if val {
|
||||||
r.Blueprint.Projects[0].Watcher.Paths = r.Blueprint.Projects[0].Watcher.Paths[:len(r.Blueprint.Projects[0].Watcher.Paths)-1]
|
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
|
return val
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Subs: []*i.Question{
|
Subs: []*i.Question{
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetEnd("!")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[string]"),
|
Options: r.Yellow.Regular("[string]"),
|
||||||
Msg: "Insert a path to watch (insert '!' to stop)",
|
Msg: "Insert a path to watch (insert '!' to stop)",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().String()
|
val, err := d.Ans().String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
|
||||||
if val == "!" {
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
r.Blueprint.Projects[0].Watcher.Paths = append(r.Blueprint.Projects[0].Watcher.Paths, val)
|
|
||||||
c.Reload()
|
|
||||||
}
|
}
|
||||||
|
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
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
_, err := c.Ans().Bool()
|
_, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
Msg: "Customize the ignored paths",
|
||||||
Msg: "Would you want customize the ignored paths?",
|
Resolve: func(d i.Context) bool {
|
||||||
Resolve: func(c i.Context) bool {
|
val, _ := d.Ans().Bool()
|
||||||
val, _ := c.Ans().Bool()
|
|
||||||
if val {
|
if val {
|
||||||
r.Blueprint.Projects[0].Watcher.Ignore = r.Blueprint.Projects[0].Watcher.Ignore[:len(r.Blueprint.Projects[0].Watcher.Ignore)-1]
|
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
|
return val
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Subs: []*i.Question{
|
Subs: []*i.Question{
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetEnd("!")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[string]"),
|
Options: r.Yellow.Regular("[string]"),
|
||||||
Msg: "Insert a path to ignore (insert '!' to stop)",
|
Msg: "Insert a path to ignore (insert '!' to stop)",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().String()
|
val, err := d.Ans().String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
|
||||||
if val == "!" {
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
r.Blueprint.Projects[0].Watcher.Ignore = append(r.Blueprint.Projects[0].Watcher.Ignore, val)
|
|
||||||
c.Reload()
|
|
||||||
}
|
}
|
||||||
|
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
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
_, err := c.Ans().Bool()
|
_, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
Msg: "Add additionals arguments",
|
||||||
Msg: "Would you want add additional arguments?",
|
Resolve: func(d i.Context) bool {
|
||||||
Resolve: func(c i.Context) bool {
|
val, _ := d.Ans().Bool()
|
||||||
val, _ := c.Ans().Bool()
|
|
||||||
return val
|
return val
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Subs: []*i.Question{
|
Subs: []*i.Question{
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetEnd("!")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[string]"),
|
Options: r.Yellow.Regular("[string]"),
|
||||||
Msg: "Insert an argument (insert '!' to stop)",
|
Msg: "Insert an argument (insert '!' to stop)",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().String()
|
val, err := d.Ans().String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
|
||||||
if val == "!" {
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
r.Blueprint.Projects[0].Params = append(r.Blueprint.Projects[0].Params, val)
|
|
||||||
c.Reload()
|
|
||||||
}
|
}
|
||||||
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Params = append(r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Params, val)
|
||||||
|
d.Reload()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
_, err := c.Ans().Bool()
|
_, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
Msg: "Add 'before' custom commands",
|
||||||
Msg: "Would you want add 'before' custom commands?",
|
Resolve: func(d i.Context) bool {
|
||||||
Resolve: func(c i.Context) bool {
|
val, _ := d.Ans().Bool()
|
||||||
val, _ := c.Ans().Bool()
|
|
||||||
return val
|
return val
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Subs: []*i.Question{
|
Subs: []*i.Question{
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetEnd("!")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[string]"),
|
Options: r.Yellow.Regular("[string]"),
|
||||||
Msg: "Insert a command (insert '!' to stop)",
|
Msg: "Insert a command (insert '!' to stop)",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().String()
|
val, err := d.Ans().String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
|
||||||
if val == "!" {
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
r.Blueprint.Projects[0].Watcher.Scripts = append(r.Blueprint.Projects[0].Watcher.Scripts, w.Command{Type: "before", Command: val})
|
|
||||||
c.Reload()
|
|
||||||
}
|
}
|
||||||
|
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
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
_, err := c.Ans().Bool()
|
_, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
Msg: "Add 'after' custom commands",
|
||||||
Msg: "Would you want add 'after' custom commands?",
|
Resolve: func(d i.Context) bool {
|
||||||
Resolve: func(c i.Context) bool {
|
val, _ := d.Ans().Bool()
|
||||||
val, _ := c.Ans().Bool()
|
|
||||||
return val
|
return val
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Subs: []*i.Question{
|
Subs: []*i.Question{
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetEnd("!")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[string]"),
|
Options: r.Yellow.Regular("[string]"),
|
||||||
Msg: "Insert a command (insert '!' to stop)",
|
Msg: "Insert a command (insert '!' to stop)",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().String()
|
val, err := d.Ans().String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
|
||||||
if val == "!" {
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
r.Blueprint.Projects[0].Watcher.Scripts = append(r.Blueprint.Projects[0].Watcher.Scripts, w.Command{Type: "after", Command: val})
|
|
||||||
c.Reload()
|
|
||||||
}
|
}
|
||||||
|
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
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
_, err := c.Ans().Bool()
|
_, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
|
||||||
Msg: "Enable watcher files preview",
|
Msg: "Enable watcher files preview",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().Bool()
|
val, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Run = val
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Run = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Quest: i.Quest{
|
Before: func(d i.Context) error {
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
|
||||||
Msg: "Enable web server",
|
|
||||||
Resolve: func(c i.Context) bool {
|
|
||||||
val, _ := c.Ans().Bool()
|
|
||||||
return val
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Subs: []*i.Question{
|
|
||||||
{
|
|
||||||
Quest: i.Quest{
|
|
||||||
Options: r.Yellow.Regular("[int]"),
|
|
||||||
Default: i.Default{Value: 5001, Preview: true, Text: r.Green.Regular("(5001)")},
|
|
||||||
Msg: "Server port",
|
|
||||||
},
|
|
||||||
Action: func(c i.Context) interface{} {
|
|
||||||
val, err := c.Ans().Int()
|
|
||||||
if err != nil {
|
|
||||||
return c.Err()
|
|
||||||
}
|
|
||||||
r.Server.Port = int(val)
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Quest: i.Quest{
|
|
||||||
Options: r.Yellow.Regular("[string]"),
|
|
||||||
Default: i.Default{Value: "localhost", Preview: true, Text: r.Green.Regular("(localhost)")},
|
|
||||||
Msg: "Server host",
|
|
||||||
},
|
|
||||||
Action: func(c i.Context) interface{} {
|
|
||||||
val, err := c.Ans().String()
|
|
||||||
if err != nil {
|
|
||||||
return c.Err()
|
|
||||||
}
|
|
||||||
r.Server.Host = val
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Quest: i.Quest{
|
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
|
||||||
Msg: "Open in the current browser",
|
|
||||||
},
|
|
||||||
Action: func(c i.Context) interface{} {
|
|
||||||
val, err := c.Ans().Bool()
|
|
||||||
if err != nil {
|
|
||||||
return c.Err()
|
|
||||||
}
|
|
||||||
r.Server.Open = val
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Action: func(c i.Context) interface{} {
|
|
||||||
val, err := c.Ans().Bool()
|
|
||||||
if err != nil {
|
|
||||||
return c.Err()
|
|
||||||
}
|
|
||||||
r.Server.Status = val
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
|
||||||
{
|
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
|
||||||
Msg: "Enable file output history",
|
Msg: "Enable file output history",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().Bool()
|
val, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Streams.FileOut = val
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Streams.FileOut = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
|
||||||
Msg: "Enable file logs history",
|
Msg: "Enable file logs history",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().Bool()
|
val, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Streams.FileLog = val
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Streams.FileLog = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Before: func(d i.Context) error {
|
||||||
|
d.SetDef(false, r.Green.Regular("(n)"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
Quest: i.Quest{
|
Quest: i.Quest{
|
||||||
Options: r.Yellow.Regular("[y/n]"),
|
Options: r.Yellow.Regular("[y/n]"),
|
||||||
Default: i.Default{Value: false, Preview: true, Text: r.Green.Regular("(n)")},
|
|
||||||
Msg: "Enable file errors history",
|
Msg: "Enable file errors history",
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
val, err := c.Ans().Bool()
|
val, err := d.Ans().Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
}
|
}
|
||||||
r.Blueprint.Projects[0].Streams.FileErr = val
|
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Streams.FileErr = val
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c i.Context) interface{} {
|
Action: func(d i.Context) interface{} {
|
||||||
if _, err := c.Ans().Bool(); err != nil {
|
if val, err := d.Ans().Bool(); err != nil {
|
||||||
return c.Err()
|
return d.Err()
|
||||||
|
} else if val {
|
||||||
|
d.Reload()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
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
|
||||||
|
},
|
||||||
})
|
})
|
||||||
handle(r.Record(r))
|
handle(r.Record(r))
|
||||||
fmt.Println(r.Green.Bold("Your project was successfully added."))
|
fmt.Println(r.Green.Bold("Your project was successfully added."))
|
||||||
|
@ -23,8 +23,8 @@ func argsParam(params *cli.Context) []string {
|
|||||||
// Duplicates check projects with same name or same combinations of main/path
|
// Duplicates check projects with same name or same combinations of main/path
|
||||||
func duplicates(value Project, arr []Project) (Project, error) {
|
func duplicates(value Project, arr []Project) (Project, error) {
|
||||||
for _, val := range arr {
|
for _, val := range arr {
|
||||||
if value.Path == val.Path || value.Name == val.Name {
|
if value.Path == val.Path {
|
||||||
return val, errors.New("There is already a project called '" + val.Name + "'. Check your config file!")
|
return val, errors.New("There is already a project for '" + val.Path + "'. Check your config file!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Project{}, nil
|
return Project{}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user