-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (58 loc) · 1.34 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"os"
"strings"
"github.com/angrypie/tie/tasks"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "Creating microservices on top of golang packages (package as a service)"
app.UsageText = "Use inside directory with tiel.yaml or let tie decide automaticaly"
app.Action = defaultCommand
//TODO log all temporary files to be able to remove them with clean command.
app.Commands = []cli.Command{
{
Name: "clean",
Usage: "Clean binaries",
Action: cleanCommand,
},
}
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "gen",
Usage: "set true to generate code without build and clean",
},
}
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
}
}
func defaultCommand(c *cli.Context) error {
err := tasks.ReadConfigFile(".", c.Bool("gen"))
if err != nil {
if err != tasks.ErrConfigNotFound {
return err
}
fmt.Println("Can't find tie.yaml in current directory")
err := tasks.ReadDirAsConfig(".", c.Bool("gen"))
if err != nil {
fmt.Println(err)
}
}
return err
}
func cleanCommand(c *cli.Context) error {
removed, err := tasks.CleanBinary(".")
if err != nil {
return err
}
if length := len(removed); length != 0 {
fmt.Printf("Deleted %d files: %s\n", len(removed), strings.Join(removed, ", "))
} else {
fmt.Printf("Nothing to clean\n")
}
return nil
}