-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (79 loc) · 2.2 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"github.com/VegetableDoggies/plantuml-gen-for-go/puml"
"github.com/VegetableDoggies/plantuml-gen-for-go/utils/filepathx"
"github.com/urfave/cli/v2"
"log"
"os"
"path/filepath"
"time"
)
var flags = []cli.Flag{
&cli.StringFlag{
Name: "rootdir",
Aliases: []string{"r", "R"},
Usage: "The path of project or package",
Required: true,
},
&cli.StringSliceFlag{
Name: "excldirs",
Aliases: []string{"e", "E"},
Usage: "The excluded dirs",
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o", "O"},
Usage: "The output path",
},
&cli.BoolFlag{
Name: "isFlat",
Aliases: []string{"f", "F"},
Usage: "default false, If true, make the packages flat",
Value: false,
},
}
//go:generate go run main.go -r D:\Programs\Github组织\VegetableDoggies\plantuml-gen-for-go
func main() {
app := &cli.App{
Flags: flags,
Name: "go-puml-gen",
Usage: "to generate .puml files",
Action: func(cCtx *cli.Context) error {
rootdir, err := filepath.Abs(cCtx.String("rootdir"))
if err != nil {
log.Fatal("\n[ERROR] Wrong rootdir :", rootdir, err)
}
excldirs := cCtx.StringSlice("excldirs")
for i := range excldirs {
excldir, err := filepath.Abs(excldirs[i])
if err != nil {
log.Fatal("\n[ERROR] Wrong excldir :", excldirs[i], err)
}
excldirs[i] = excldir
}
isFlat := cCtx.Bool("isFlat")
output := cCtx.String("output")
if output == "" || filepathx.IsDir(output) {
if isFlat {
output = filepath.Join(rootdir, filepath.Base(rootdir)+time.Now().Format("20060102150405")+"F.puml")
} else {
output = filepath.Join(rootdir, filepath.Base(rootdir)+time.Now().Format("20060102150405")+".puml")
}
log.Printf("The default output path is active : %s\n", output)
}
file, err := os.Create(output)
if err != nil {
log.Fatal("\n[ERROR] Can't Create the file :", output, err)
}
defer file.Close()
if _, err = file.Write([]byte(puml.NewPortrait(rootdir, excldirs, isFlat).Puml)); err != nil {
log.Fatal("\n[ERROR] Can't Write to file :", output, err)
}
log.Printf("Success!\n\n>>> Output = %s\n\n", output)
return nil
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}