-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuuid_cli.go
43 lines (35 loc) · 1.02 KB
/
uuid_cli.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
package main
import (
"fmt"
"github.com/corka149/uuid_cli/generator"
"github.com/spf13/cobra"
"math/rand"
"os"
"time"
)
func main() {
config := generator.UuidConfig{}
rootCmd := cobra.Command{
Use: "uuid",
Short: "Creates UUIDs with different combinations",
Long: "A quick and easy way to generate UUIDs for different cases.",
Run: func(cmd *cobra.Command, args []string) {
unixNano := time.Now().UnixNano()
source := rand.NewSource(unixNano)
r := rand.New(source)
u, err := generator.GenUuid(config, r)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(u)
},
}
rootCmd.PersistentFlags().BoolVarP(&config.RandomCase, "random-case", "r", false, "Use random case for characters in UUID")
rootCmd.PersistentFlags().BoolVarP(&config.ReplaceAmbiguous, "replace-ambiguous", "a", false, "Replace ambiguous 0 by Q")
rootCmd.PersistentFlags().IntVarP(&config.Chars, "chars", "c", -1, "Amount of characters")
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}