-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
56 lines (51 loc) · 1.18 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
package main
import (
"fmt"
"github.com/reallyliri/docker-decompose/decompose"
"github.com/urfave/cli/v2"
"log"
"os"
)
const (
Version = "0.1.1"
)
func declareCli() *cli.App {
cli.AppHelpTemplate =
`NAME:
{{.Name}} - {{.Version}} - {{.Usage}}
USAGE:
{{.Name}} {{if .Flags}}[Options]{{end}} [compose-file] [service, ...]
ARGS:
compose-file{{ "\t" }}path to a docker-compose.yaml file, defaults to docker-compose.yaml at current directory
service(s){{ "\t" }}zero or more service names to decompose, defaults to all services in the compose file
OPTIONS:
{{range .Flags}}{{.}}
{{end}}
`
return &cli.App{
Name: "docker-decompose",
Version: Version,
Usage: "Decompose docker compose files to docker build and run commands",
Writer: os.Stdout,
Flags: decompose.Flags(),
}
}
func main() {
app := declareCli()
app.Action = func(context *cli.Context) error {
opts := decompose.ParseOptions(context)
commands, err := decompose.Decompose(opts)
if err != nil {
return err
}
for _, command := range commands {
fmt.Printf(command)
fmt.Print("\n\n")
}
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatalf("run failed: %v", err)
}
}