Added flag to copy to clipboard
This commit is contained in:
parent
1af2cfafa4
commit
b7b4f799e7
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,4 +19,4 @@
|
||||
|
||||
# Go workspace file
|
||||
go.work
|
||||
usergen
|
||||
dist/*
|
||||
2
go.mod
2
go.mod
@ -1,3 +1,5 @@
|
||||
module github.com/mickeyr/usergen
|
||||
|
||||
go 1.22.0
|
||||
|
||||
require github.com/atotto/clipboard v0.1.4 // indirect
|
||||
|
||||
2
go.sum
Normal file
2
go.sum
Normal file
@ -0,0 +1,2 @@
|
||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
23
main.go
23
main.go
@ -1,12 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"embed"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
"github.com/atotto/clipboard"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -18,6 +21,7 @@ var (
|
||||
)
|
||||
|
||||
var count int
|
||||
var copy bool
|
||||
|
||||
func init() {
|
||||
nounsContents, _ := res.ReadFile("resources/nouns.txt")
|
||||
@ -26,18 +30,27 @@ func init() {
|
||||
verbsContents, _ := res.ReadFile("resources/verbs.txt")
|
||||
verbs = strings.Split(string(verbsContents), "\n")
|
||||
|
||||
flag.IntVar(&count, "count", 10, "number of nouns and verbs to print")
|
||||
|
||||
flag.IntVar(&count, "n", 5, "number of nouns and verbs to print")
|
||||
flag.BoolVar(©, "c", false, "copies the output to the clipboard")
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
fmt.Println("count is ", count)
|
||||
var output bytes.Buffer
|
||||
|
||||
// Print the first 10 nouns and verbs
|
||||
for i := 0; i < count; i++ {
|
||||
if i > 0 {
|
||||
output.WriteString("\n")
|
||||
}
|
||||
randomNounIdx, _ := rand.Int(rand.Reader, big.NewInt(int64(len((nouns)))))
|
||||
randomVerbIdx, _ := rand.Int(rand.Reader, big.NewInt(int64(len((verbs)))))
|
||||
fmt.Printf("%s-%s\n", nouns[randomNounIdx.Int64()], verbs[randomVerbIdx.Int64()])
|
||||
var username = fmt.Sprintf("%s-%s", nouns[randomNounIdx.Int64()], verbs[randomVerbIdx.Int64()])
|
||||
output.WriteString(username)
|
||||
}
|
||||
|
||||
if copy {
|
||||
clipboard.WriteAll(output.String())
|
||||
}
|
||||
|
||||
fmt.Println(output.String())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user