2016-07-12 08:18:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-07-12 18:03:22 +00:00
|
|
|
"os"
|
2016-07-12 20:48:05 +00:00
|
|
|
"gopkg.in/urfave/cli.v2"
|
2016-08-14 15:23:52 +00:00
|
|
|
r "github.com/tockins/realize/realize"
|
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-14 15:23:52 +00:00
|
|
|
r.Fail(err.Error())
|
|
|
|
return nil
|
2016-07-13 10:32:54 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-04 22:59:41 +00:00
|
|
|
header := func() {
|
2016-08-03 08:29:26 +00:00
|
|
|
app.Information()
|
2016-07-27 11:42:25 +00:00
|
|
|
}
|
|
|
|
|
2016-08-03 08:29:26 +00:00
|
|
|
cli := &cli.App{
|
|
|
|
Name: app.Name,
|
|
|
|
Version: app.Version,
|
2016-07-23 22:49:19 +00:00
|
|
|
Authors: []*cli.Author{
|
|
|
|
&cli.Author{
|
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{
|
|
|
|
{
|
|
|
|
Name: "run",
|
|
|
|
Usage: "Build and watch file changes",
|
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-31 21:40:23 +00:00
|
|
|
y.Watch()
|
2016-07-12 18:03:22 +00:00
|
|
|
return nil
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "start",
|
|
|
|
Category: "config",
|
2016-07-23 22:49:19 +00:00
|
|
|
Aliases: []string{"s"},
|
2016-07-27 08:52:11 +00:00
|
|
|
Usage: "Create the initial config",
|
2016-07-23 22:49:19 +00:00
|
|
|
Flags: []cli.Flag{
|
2016-08-03 08:29:26 +00:00
|
|
|
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: "Sample App", Usage: "Project name \t"},
|
|
|
|
&cli.StringFlag{Name: "main", Aliases: []string{"m"}, Value: "main.go", Usage: "Project main file \t"},
|
|
|
|
&cli.StringFlag{Name: "base", Aliases: []string{"b"}, Value: "/", Usage: "Project base path \t"},
|
2016-07-31 21:40:23 +00:00
|
|
|
&cli.BoolFlag{Name: "build", Value: false},
|
|
|
|
&cli.BoolFlag{Name: "run", Value: true},
|
|
|
|
&cli.BoolFlag{Name: "bin", Value: true},
|
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.Create(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-07-27 09:14:32 +00:00
|
|
|
Aliases: []string{"a"},
|
2016-07-27 08:52:11 +00:00
|
|
|
Usage: "Add another project",
|
2016-07-23 22:49:19 +00:00
|
|
|
Flags: []cli.Flag{
|
2016-08-03 08:29:26 +00:00
|
|
|
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: "Sample App", Usage: "Project name \t"},
|
|
|
|
&cli.StringFlag{Name: "main", Aliases: []string{"m"}, Value: "main.go", Usage: "Project main file \t"},
|
|
|
|
&cli.StringFlag{Name: "base", Aliases: []string{"b"}, Value: "/", Usage: "Project base path \t"},
|
2016-07-31 21:40:23 +00:00
|
|
|
&cli.BoolFlag{Name: "build", Value: false},
|
|
|
|
&cli.BoolFlag{Name: "run", Value: true},
|
|
|
|
&cli.BoolFlag{Name: "bin", Value: true},
|
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-07-27 09:14:32 +00:00
|
|
|
Aliases: []string{"r"},
|
2016-07-27 08:52:11 +00:00
|
|
|
Usage: "Remove a project",
|
2016-07-26 17:04:13 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: "Sample App"},
|
|
|
|
},
|
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-07-27 09:14:32 +00:00
|
|
|
Aliases: []string{"l"},
|
2016-07-27 08:52:11 +00:00
|
|
|
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-07-12 08:18:02 +00:00
|
|
|
}
|