-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
140 lines (121 loc) · 2.74 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli"
"github.com/silmin/codc/combine"
"github.com/silmin/codc/convert"
"github.com/silmin/codc/exists"
)
func main() {
app := &cli.App{
Name: "codc | Combine OpenDataCam's data",
Usage: "combine json of opendatacam",
Version: "0.3.0",
Commands: []*cli.Command{
{
Name: "form",
Usage: "form default json to original formmat",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "src",
Aliases: []string{"s"},
Usage: "input json file",
Value: "input.json",
},
&cli.StringFlag{
Name: "dst",
Aliases: []string{"d"},
Usage: "output json file",
Value: "formd_input.json",
},
},
Action: func(context *cli.Context) error {
inFile := context.String("src")
outFile := context.String("dst")
if !exists.File(inFile) {
fmt.Println(inFile, "not exist.")
return nil
}
fmt.Println("input:", inFile)
isFormd, err := IsFormd(inFile)
if err != nil {
return err
}
if isFormd {
return nil
}
err = convert.FormJson(inFile, outFile)
if err != nil {
return err
}
fmt.Println("output:", outFile)
return nil
},
},
{
Name: "areas",
Usage: "combine any areas",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "src",
Aliases: []string{"s"},
Usage: "input json file",
Value: "formd_input.json",
},
&cli.StringFlag{
Name: "dst",
Aliases: []string{"d"},
Usage: "output json file",
Value: "output.json",
},
},
Action: func(context *cli.Context) error {
inFile := context.String("src")
outFile := context.String("dst")
if !exists.File(inFile) {
fmt.Println(inFile, "not exist.")
return nil
}
args := context.Args().Slice()
fmt.Println("input:", inFile)
fmt.Println("args:", args)
isFormd, err := IsFormd(inFile)
if err != nil {
return err
}
if !isFormd {
formdFile := "formd.json"
err := convert.FormJson(inFile, formdFile)
if err != nil {
return err
}
inFile = formdFile
}
figure, err := convert.File2Figure(inFile)
if err != nil {
return err
}
if !exists.Area(figure, args) {
fmt.Println("contains something that doesn't exist in", args)
return nil
}
figure, err = combine.Area(figure, args)
if err != nil {
return err
}
if err := convert.Figure2File(outFile, figure); err != nil {
return err
}
fmt.Println("output:", outFile)
return nil
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}