new logic with struct pointers

This commit is contained in:
alessio 2016-07-24 00:49:19 +02:00
parent 83d9f183d1
commit 512defe2b0

55
main.go
View File

@ -11,14 +11,20 @@ func main() {
handle := func(err error) error{ handle := func(err error) error{
if err != nil { if err != nil {
return cli.Exit(err, 86) return cli.Exit(err.Error(), 86)
} }
return nil return nil
} }
app := &cli.App{ app := &cli.App{
Name: "realize", Name: "Realize",
Version: "1.0", Version: "v1.0",
Authors: []*cli.Author{
&cli.Author{
Name: "Alessio Pracchia",
Email: "pracchia@hastega.it",
},
},
Usage: "A sort of Webpack for Go. Run, build and watch file changes with custom paths", Usage: "A sort of Webpack for Go. Run, build and watch file changes with custom paths",
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
@ -32,22 +38,43 @@ func main() {
{ {
Name: "start", Name: "start",
Category: "config", Category: "config",
Aliases: []string{"s"},
Usage: "create the initial config file", Usage: "create the initial config file",
Action: func(c *cli.Context) error { Flags: []cli.Flag{
t := realize.Init() &cli.StringFlag{Name: "main", Aliases: []string{"m"}, Value: "main.go"},
_, err := t.Create() &cli.BoolFlag{Name: "build", Aliases: []string{"b"}, Value: true},
&cli.BoolFlag{Name: "run", Aliases: []string{"r"}, Value: true},
},
Action: func(params *cli.Context) error {
y := realize.Config{}
y.Init(params)
return handle(y.Create())
},
},
{
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 {
y := realize.Config{}
err := y.Read()
return handle(err) return handle(err)
}, },
}, },
}, },
Flags: []cli.Flag { //Flags: []cli.Flag {
&cli.StringFlag{ // &cli.StringFlag{
Name: "run", // Name: "run",
Value: "main.go", // Value: "main.go",
Usage: "main file of your project", // Usage: "main file of your project",
}, // },
}, //},
} }
app.Run(os.Args) app.Run(os.Args)