-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain.go
42 lines (37 loc) · 816 Bytes
/
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
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package main
import (
"encoding/json"
"fmt"
"github.com/olongfen/gen-id/generator"
"github.com/spf13/cobra"
"math/rand"
"os"
)
var rootCmd = &cobra.Command{
Use: "gen-id",
Short: "auto generate id card",
Long: "auto generate id card",
}
func main() {
var (
count int
data []*generator.GeneratorData
)
rootCmd.PersistentFlags().IntVar(&count, "count", 1, "gen count (default is 1)")
execute()
for i := 0; i < count; i++ {
data = append(data, generator.NewGeneratorData(nil))
}
filePath := fmt.Sprintf("./gen_%d.json", rand.Int())
file, _ := os.OpenFile(filePath, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0755)
_data, _ := json.Marshal(data)
file.Write(_data)
}
func execute() {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}