2016-07-12 08:18:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-08-21 14:35:17 +00:00
|
|
|
"fmt"
|
2016-08-14 15:23:52 +00:00
|
|
|
r "github.com/tockins/realize/realize"
|
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-08-21 07:16:01 +00:00
|
|
|
"strings"
|
2016-07-12 08:18:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
2016-08-14 15:23:52 +00:00
|
|
|
app := r.Init()
|
2016-08-03 08:29:26 +00:00
|
|
|
|
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-08-03 08:29:26 +00:00
|
|
|
app.Information()
|
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-21 14:35:17 +00:00
|
|
|
wd := func() string {
|
|
|
|
dir, err := os.Getwd()
|
|
|
|
if err != nil {
|
2016-08-21 21:59:42 +00:00
|
|
|
log.Fatal(r.Red(err))
|
2016-08-21 07:16:01 +00:00
|
|
|
}
|
|
|
|
wd := strings.Split(dir, "/")
|
|
|
|
return wd[len(wd)-1]
|
|
|
|
}
|
|
|
|
|
2016-08-03 08:29:26 +00:00
|
|
|
cli := &cli.App{
|
2016-08-17 23:35:37 +00:00
|
|
|
Name: app.Name,
|
2016-08-03 08:29:26 +00:00
|
|
|
Version: app.Version,
|
2016-07-23 22:49:19 +00:00
|
|
|
Authors: []*cli.Author{
|
2016-08-21 14:35:17 +00:00
|
|
|
{
|
2016-08-03 08:29:26 +00:00
|
|
|
Name: app.Author,
|
|
|
|
Email: app.Email,
|
2016-07-23 22:49:19 +00:00
|
|
|
},
|
|
|
|
},
|
2016-08-03 08:29:26 +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 {
|
|
|
|
y := r.New(p)
|
|
|
|
return handle(y.Watch())
|
|
|
|
},
|
|
|
|
Before: func(c *cli.Context) error {
|
|
|
|
header()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "fast",
|
|
|
|
Usage: "Build and watch file changes for a single project without any config file",
|
2016-08-21 18:15:01 +00:00
|
|
|
Flags: []cli.Flag{
|
2016-08-21 21:31:16 +00:00
|
|
|
&cli.BoolFlag{Name: "build", Value: false, Usage: "Enable go build"},
|
|
|
|
&cli.BoolFlag{Name: "run", Usage: "Disable go run"},
|
|
|
|
&cli.BoolFlag{Name: "bin", Usage: "Disable go install"},
|
|
|
|
&cli.BoolFlag{Name: "fmt", Usage: "Disable gofmt"},
|
2016-08-22 11:45:42 +00:00
|
|
|
&cli.BoolFlag{Name: "config", Value: false, Usage: "If there is a config file with a project for the current directory take that configuration"},
|
2016-08-21 18:15:01 +00:00
|
|
|
},
|
2016-07-27 09:14:32 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2016-08-14 15:23:52 +00:00
|
|
|
y := r.New(p)
|
2016-08-21 21:59:42 +00:00
|
|
|
y.Projects[0].Path = "/"
|
2016-08-21 21:31:16 +00:00
|
|
|
return handle(y.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",
|
|
|
|
Category: "config",
|
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-08-22 11:45:42 +00:00
|
|
|
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: wd(), Usage: "Project name \t"},
|
2016-08-21 21:59:42 +00:00
|
|
|
&cli.StringFlag{Name: "path", Aliases: []string{"b"}, Value: "/", Usage: "Project base path \t"},
|
2016-08-21 14:35:17 +00:00
|
|
|
&cli.BoolFlag{Name: "build", Value: false, Usage: "Enable go build"},
|
|
|
|
&cli.BoolFlag{Name: "run", Usage: "Disable go run"},
|
|
|
|
&cli.BoolFlag{Name: "bin", Usage: "Disable go install"},
|
2016-08-21 15:13:30 +00:00
|
|
|
&cli.BoolFlag{Name: "fmt", Usage: "Disable gofmt"},
|
2016-07-23 22:49:19 +00:00
|
|
|
},
|
2016-07-27 09:14:32 +00:00
|
|
|
Action: func(p *cli.Context) error {
|
2016-08-14 15:23:52 +00:00
|
|
|
y := r.New(p)
|
2016-07-27 09:14:32 +00:00
|
|
|
return handle(y.Add(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",
|
|
|
|
Category: "config",
|
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-08-14 15:23:52 +00:00
|
|
|
y := r.New(p)
|
2016-07-27 09:14:32 +00:00
|
|
|
return handle(y.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",
|
|
|
|
Category: "config",
|
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-08-14 15:23:52 +00:00
|
|
|
y := r.New(p)
|
2016-07-26 17:04:13 +00:00
|
|
|
return handle(y.List())
|
|
|
|
},
|
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
|
|
|
}
|