2016-07-12 08:18:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-09-01 22:17:19 +00:00
|
|
|
r "github.com/tockins/realize/cli"
|
2016-08-30 17:44:26 +00:00
|
|
|
//_ "github.com/tockins/realize/server"
|
2016-09-01 22:17:19 +00:00
|
|
|
"fmt"
|
2016-08-17 23:35:37 +00:00
|
|
|
"gopkg.in/urfave/cli.v2"
|
2016-08-21 14:35:17 +00:00
|
|
|
"log"
|
2016-08-17 23:35:37 +00:00
|
|
|
"os"
|
2016-07-12 08:18:02 +00:00
|
|
|
)
|
|
|
|
|
2016-09-01 22:28:38 +00:00
|
|
|
var App r.Realize
|
|
|
|
|
2016-09-01 22:17:19 +00:00
|
|
|
func init() {
|
2016-09-01 22:28:38 +00:00
|
|
|
App = r.Realize{
|
2016-09-01 22:17:19 +00:00
|
|
|
Name: "Realize",
|
|
|
|
Version: "1.0",
|
|
|
|
Description: "A Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths",
|
|
|
|
Limit: 10000,
|
|
|
|
Blueprint: r.Blueprint{
|
|
|
|
Files: map[string]string{
|
|
|
|
"config": "r.config.yaml",
|
|
|
|
"output": "r.output.log",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
App.Increases()
|
|
|
|
r.App = App
|
|
|
|
}
|
|
|
|
|
2016-07-12 08:18:02 +00:00
|
|
|
func main() {
|
|
|
|
|
2016-08-04 22:59:41 +00:00
|
|
|
handle := func(err error) error {
|
2016-07-13 10:32:54 +00:00
|
|
|
if err != nil {
|
2016-08-21 07:16:01 +00:00
|
|
|
fmt.Println(r.Red(err.Error()))
|
2016-08-14 15:23:52 +00:00
|
|
|
return nil
|
2016-07-13 10:32:54 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-21 14:35:17 +00:00
|
|
|
header := func() error {
|
2016-09-01 22:28:38 +00:00
|
|
|
fmt.Println(r.Blue(App.Name) + " - " + r.Blue(App.Version))
|
|
|
|
fmt.Println(r.BlueS(App.Description) + "\n")
|
2016-08-21 14:35:17 +00:00
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
if gopath == "" {
|
|
|
|
log.Fatal(r.Red("$GOPATH isn't set up properly"))
|
|
|
|
}
|
|
|
|
return nil
|
2016-07-27 11:42:25 +00:00
|
|
|
}
|
|
|
|
|
2016-08-03 08:29:26 +00:00
|
|
|
cli := &cli.App{
|
2016-09-01 22:28:38 +00:00
|
|
|
Name: App.Name,
|
|
|
|
Version: App.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",
|
|
|
|
Email: "pracchia@hastega.it",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Daniele Conventi",
|
|
|
|
Email: "conventi@hastega.it",
|
2016-07-23 22:49:19 +00:00
|
|
|
},
|
|
|
|
},
|
2016-09-01 22:28:38 +00:00
|
|
|
Usage: App.Description,
|
2016-07-12 18:03:22 +00:00
|
|
|
Commands: []*cli.Command{
|
|
|
|
{
|
2016-08-17 23:35:37 +00:00
|
|
|
Name: "run",
|
2016-07-12 18:03:22 +00:00
|
|
|
Usage: "Build and watch file changes",
|
2016-08-21 21:31:16 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2016-09-01 22:28:38 +00:00
|
|
|
return handle(App.Blueprint.Run())
|
2016-08-21 21:31:16 +00:00
|
|
|
},
|
|
|
|
Before: func(c *cli.Context) error {
|
|
|
|
header()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "fast",
|
2016-08-31 12:08:15 +00:00
|
|
|
Usage: "Build and watch file changes for a single project without any Configuration file",
|
2016-08-21 18:15:01 +00:00
|
|
|
Flags: []cli.Flag{
|
2016-08-30 17:27:47 +00:00
|
|
|
&cli.StringFlag{Name: "path", Aliases: []string{"b"}, Value: "", Usage: "Project base path"},
|
2016-08-22 16:08:41 +00:00
|
|
|
&cli.BoolFlag{Name: "build", Value: false, Usage: "Enables the build"},
|
2016-08-23 13:31:28 +00:00
|
|
|
&cli.BoolFlag{Name: "no-run", Usage: "Disables the run"},
|
|
|
|
&cli.BoolFlag{Name: "no-bin", Usage: "Disables the installation"},
|
|
|
|
&cli.BoolFlag{Name: "no-fmt", Usage: "Disables the fmt (go fmt)"},
|
2016-08-27 21:57:26 +00:00
|
|
|
&cli.BoolFlag{Name: "test", Value: false, Usage: "Enable the tests"},
|
2016-08-31 12:08:15 +00:00
|
|
|
&cli.BoolFlag{Name: "Configuration", Value: false, Usage: "Take the defined settings if exist a Configuration file."},
|
2016-08-21 18:15:01 +00:00
|
|
|
},
|
2016-07-27 09:14:32 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2016-09-01 22:28:38 +00:00
|
|
|
App.Blueprint.Add(p)
|
|
|
|
return handle(App.Blueprint.Fast(p))
|
2016-07-12 18:03:22 +00:00
|
|
|
},
|
2016-07-27 11:42:25 +00:00
|
|
|
Before: func(c *cli.Context) error {
|
|
|
|
header()
|
|
|
|
return nil
|
|
|
|
},
|
2016-07-12 18:03:22 +00:00
|
|
|
},
|
2016-07-23 22:49:19 +00:00
|
|
|
{
|
|
|
|
Name: "add",
|
2016-08-31 12:08:15 +00:00
|
|
|
Category: "Configuration",
|
2016-08-17 23:35:37 +00:00
|
|
|
Aliases: []string{"a"},
|
|
|
|
Usage: "Add another project",
|
2016-07-23 22:49:19 +00:00
|
|
|
Flags: []cli.Flag{
|
2016-09-01 22:28:38 +00:00
|
|
|
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: App.Wdir(), Usage: "Project name"},
|
2016-08-22 16:08:41 +00:00
|
|
|
&cli.StringFlag{Name: "path", Aliases: []string{"b"}, Value: "/", Usage: "Project base path"},
|
2016-08-27 21:57:26 +00:00
|
|
|
&cli.BoolFlag{Name: "build", Value: false, Usage: "Enable the build"},
|
2016-08-23 13:31:28 +00:00
|
|
|
&cli.BoolFlag{Name: "no-run", Usage: "Disables the run"},
|
|
|
|
&cli.BoolFlag{Name: "no-bin", Usage: "Disables the installation"},
|
|
|
|
&cli.BoolFlag{Name: "no-fmt", Usage: "Disables the fmt (go fmt)"},
|
2016-08-27 21:57:26 +00:00
|
|
|
&cli.BoolFlag{Name: "test", Value: false, Usage: "Enable the tests"},
|
2016-07-23 22:49:19 +00:00
|
|
|
},
|
2016-07-27 09:14:32 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2016-09-01 22:28:38 +00:00
|
|
|
return handle(App.Blueprint.Insert(p))
|
2016-07-23 22:49:19 +00:00
|
|
|
},
|
2016-07-27 11:42:25 +00:00
|
|
|
Before: func(c *cli.Context) error {
|
|
|
|
header()
|
|
|
|
return nil
|
|
|
|
},
|
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",
|
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-09-01 22:28:38 +00:00
|
|
|
return handle(App.Blueprint.Remove(p))
|
2016-07-26 17:04:13 +00:00
|
|
|
},
|
2016-07-27 11:42:25 +00:00
|
|
|
Before: func(c *cli.Context) error {
|
|
|
|
header()
|
|
|
|
return nil
|
|
|
|
},
|
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: "Projects list",
|
2016-07-27 09:14:32 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2016-09-01 22:28:38 +00:00
|
|
|
return handle(App.Blueprint.List())
|
2016-07-26 17:04:13 +00:00
|
|
|
},
|
2016-07-27 11:42:25 +00:00
|
|
|
Before: func(c *cli.Context) error {
|
|
|
|
header()
|
|
|
|
return nil
|
|
|
|
},
|
2016-07-26 17:04:13 +00:00
|
|
|
},
|
2016-07-12 18:03:22 +00:00
|
|
|
},
|
|
|
|
}
|
2016-07-12 08:18:02 +00:00
|
|
|
|
2016-08-03 08:29:26 +00:00
|
|
|
cli.Run(os.Args)
|
2016-08-17 23:35:37 +00:00
|
|
|
}
|