-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathugen.go
55 lines (45 loc) · 893 Bytes
/
ugen.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
package main
import (
"fmt"
"log"
"os"
"runtime"
"strings"
uuid "github.com/satori/go.uuid"
"github.com/urfave/cli"
"github.com/hieuphq/ugen/src/clipboard"
)
var app = cli.NewApp()
func info() {
app.Name = "Generate UUID CLI"
app.Usage = "Helper to generate a UUID and copy to clipboard"
app.Author = "hieuphq"
app.Version = "0.0.1"
}
func main() {
info()
app.Flags = []cli.Flag{
cli.IntFlag{
Name: "amount, a",
Usage: "Number of UUID result",
Value: 1,
},
}
app.Action = func(c *cli.Context) error {
no := c.GlobalInt("a")
rs := []string{}
for idx := 0; idx < no; idx++ {
uid := uuid.NewV4()
rs = append(rs, uid.String())
}
osStr := runtime.GOOS
cb := clipboard.NewClipboard(osStr)
cb.Write(strings.Join(rs, "\n"))
fmt.Println("copied to clipboard")
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}