-
Notifications
You must be signed in to change notification settings - Fork 103
/
main.go
89 lines (77 loc) · 1.69 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
package main
import (
"os"
"stripe-checker/src"
"github.com/urfave/cli/v2"
)
var (
app = &cli.App{}
cfg src.Cfg
card src.Card
filename string
output string
configPath string
separator string
)
func init() {
app.Name = "stripe-checker"
app.Usage = "credit card checker using stripe payment gateway."
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"cfg", "c"},
Value: "./config.cfg",
Usage: "config path to checker",
Destination: &configPath,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"out", "o"},
Value: "./lives.txt",
Usage: "output name",
Destination: &output,
},
&cli.StringFlag{
Name: "separator",
Aliases: []string{"sep", "s"},
Value: "|",
Usage: "separator that separate the credit card.",
Destination: &separator,
},
}
app.Commands = []*cli.Command{
{
Name: "once",
Aliases: []string{"oc", "onc"},
Usage: "run only one test in line",
Action: func(c *cli.Context) error {
cfg = src.LoadCfg(configPath)
line := c.Args().First()
if line != "" {
card = src.GetCardByLine(line, separator)
}
src.CheckProcess(card, cfg, output)
return nil
},
},
}
if len(os.Args) < 2 {
app.RunAndExitOnError()
os.Exit(0)
}
app.Action = func(ctx *cli.Context) error {
filename = ctx.Args().First()
cfg = src.LoadCfg(configPath)
src.OpenFileByName(filename, func(line string) {
if line != "" {
card = src.GetCardByLine(line, separator)
}
src.CheckProcess(card, cfg, output)
})
return nil
}
}
func main() {
err := app.Run(os.Args)
src.HandleError(err)
}