-
Notifications
You must be signed in to change notification settings - Fork 3
/
HcyConverter.go
66 lines (58 loc) · 1.2 KB
/
HcyConverter.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
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "hcyconverter",
Usage: "Convert HttpCanary zip achieve to Postman Collection",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Value: "./",
Usage: "Output Path",
},
},
Action: func(c *cli.Context) error {
var name string
if c.NArg() > 0 {
name = c.Args().Get(0)
} else {
log.Fatal("Input File not specified")
}
if !strings.HasSuffix(name, ".zip") {
log.Fatal("Only HttpCanary zip achieve supported.")
}
outputPath := c.String("output")
_, err := os.Stat(name)
if err != nil {
log.Fatal("Invalid Input File")
}
file, err := os.Stat(outputPath)
if err != nil {
if os.IsNotExist(err) {
err := os.MkdirAll(outputPath, 0755)
if err != nil {
fmt.Println(err)
log.Fatal("Error Creating output directory")
}
} else {
log.Fatal("Invalid output directory")
}
}
if !file.IsDir() {
log.Fatal("Invalid output directory")
}
return toPostman(name, outputPath)
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}