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 workspace file
|
||||||
go.work
|
go.work
|
||||||
usergen
|
dist/*
|
||||||
2
go.mod
2
go.mod
@ -1,3 +1,5 @@
|
|||||||
module github.com/mickeyr/usergen
|
module github.com/mickeyr/usergen
|
||||||
|
|
||||||
go 1.22.0
|
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"embed"
|
"embed"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/atotto/clipboard"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -18,6 +21,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var count int
|
var count int
|
||||||
|
var copy bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
nounsContents, _ := res.ReadFile("resources/nouns.txt")
|
nounsContents, _ := res.ReadFile("resources/nouns.txt")
|
||||||
@ -26,18 +30,27 @@ func init() {
|
|||||||
verbsContents, _ := res.ReadFile("resources/verbs.txt")
|
verbsContents, _ := res.ReadFile("resources/verbs.txt")
|
||||||
verbs = strings.Split(string(verbsContents), "\n")
|
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() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
fmt.Println("count is ", count)
|
var output bytes.Buffer
|
||||||
|
|
||||||
// Print the first 10 nouns and verbs
|
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
|
if i > 0 {
|
||||||
|
output.WriteString("\n")
|
||||||
|
}
|
||||||
randomNounIdx, _ := rand.Int(rand.Reader, big.NewInt(int64(len((nouns)))))
|
randomNounIdx, _ := rand.Int(rand.Reader, big.NewInt(int64(len((nouns)))))
|
||||||
randomVerbIdx, _ := rand.Int(rand.Reader, big.NewInt(int64(len((verbs)))))
|
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