realize/main.go

80 lines
1.9 KiB
Go
Raw Normal View History

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
"fmt"
"gopkg.in/urfave/cli.v2"
"github.com/tockins/realize/realize"
2016-07-12 08:18:02 +00:00
)
func main() {
2016-07-13 10:32:54 +00:00
handle := func(err error) error{
if err != nil {
2016-07-23 22:49:19 +00:00
return cli.Exit(err.Error(), 86)
2016-07-13 10:32:54 +00:00
}
return nil
}
2016-07-12 18:03:22 +00:00
app := &cli.App{
2016-07-23 22:49:19 +00:00
Name: "Realize",
Version: "v1.0",
Authors: []*cli.Author{
&cli.Author{
Name: "Alessio Pracchia",
Email: "pracchia@hastega.it",
},
},
2016-07-12 18:03:22 +00:00
Usage: "A sort of Webpack for Go. Run, build and watch file changes with custom paths",
Commands: []*cli.Command{
{
Name: "run",
Usage: "Build and watch file changes",
Action: func(c *cli.Context) error {
fmt.Printf("Hello %q", c.String("run"))
return nil
},
},
{
Name: "start",
Category: "config",
2016-07-23 22:49:19 +00:00
Aliases: []string{"s"},
2016-07-12 18:03:22 +00:00
Usage: "create the initial config file",
2016-07-23 22:49:19 +00:00
Flags: []cli.Flag{
&cli.StringFlag{Name: "main", Aliases: []string{"m"}, Value: "main.go"},
&cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: true},
&cli.BoolFlag{Name: "run", Aliases: []string{"r"}, Value: true},
},
Action: func(params *cli.Context) error {
2016-07-24 23:02:18 +00:00
y := realize.New(params)
return handle(y.Create(params))
2016-07-12 18:03:22 +00:00
},
},
2016-07-23 22:49:19 +00:00
{
Name: "add",
Category: "config",
Aliases: []string{"s"},
Usage: "add another project in config file",
Flags: []cli.Flag{
&cli.StringFlag{Name: "main", Aliases: []string{"m"}, Value: "main.go"},
&cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: true},
&cli.BoolFlag{Name: "run", Aliases: []string{"r"}, Value: true},
},
Action: func(params *cli.Context) error {
2016-07-24 23:02:18 +00:00
y := realize.New(params)
y.Read()
return handle(y.Add(params))
2016-07-23 22:49:19 +00:00
},
2016-07-12 18:03:22 +00:00
},
},
2016-07-23 22:49:19 +00:00
//Flags: []cli.Flag {
// &cli.StringFlag{
// Name: "run",
// Value: "main.go",
// Usage: "main file of your project",
// },
//},
2016-07-12 18:03:22 +00:00
}
2016-07-12 08:18:02 +00:00
2016-07-12 18:03:22 +00:00
app.Run(os.Args)
2016-07-12 08:18:02 +00:00
}