Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ jobs:
test:
strategy:
matrix:
go-version: [~1.17, ^1]
go-version: [~1.19, ^1]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
GO111MODULE: "on"
steps:
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
**/*.bak

.vscode/
.claude/
.codex/

dist/
fname
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ pleasant-joy
eligible-tenant
```

Generate names as a JSON array (useful for scripting):

```sh
$ fname --format json --quantity 3
["influential-length","direct-ear","cultural-storage"]

$ fname -f json
["extinct-green"]
```

### Library

#### Install
Expand Down Expand Up @@ -147,13 +157,42 @@ import (
)

func main() {
rng := fname.NewGenerator(fname.WithDelimiter("__"), fname.WithSize(3))
sizeOpt, err := fname.WithSize(3)
if err != nil {
panic(err)
}
rng := fname.NewGenerator(fname.WithDelimiter("__"), sizeOpt)
phrase, err := rng.Generate()
fmt.Println(phrase)
// => "established__shark__destroyed"
}
```

#### Custom Dictionary

```go
package main

import (
"fmt"

"github.com/splode/fname"
)

func main() {
dict := fname.NewCustomDictionary(
[]string{"blazing", "frozen"}, // adjectives
nil, // adverbs (uses default)
[]string{"comet", "nebula"}, // nouns
nil, // verbs (uses default)
)
rng := fname.NewGenerator(fname.WithDictionary(dict))
phrase, err := rng.Generate()
fmt.Println(phrase)
// => "blazing-nebula"
}
```

## Disclaimers

fname is not cryptographically secure, and should not be used for anything that requires a truly unique identifier. It is meant to be a fun, human-friendly alternative to UUIDs.
Expand Down
42 changes: 33 additions & 9 deletions cmd/fname/fname.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
_ "embed"
"encoding/json"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -45,19 +46,20 @@ func main() {
var (
casing string = "lower"
delimiter string = "-"
format string = "plain"
help bool
ver bool
quantity int = 1
size uint = 2
seed int64 = -1
// TODO: add option to use custom dictionary
quantity int = 1
size uint = 2
seed int64
)

pflag.StringVarP(&casing, "casing", "c", casing, "set the casing of the generated name <title|upper|lower>")
pflag.StringVarP(&delimiter, "delimiter", "d", delimiter, "set the delimiter used to join words")
pflag.StringVarP(&format, "format", "f", format, "set the output format <plain|json>")
pflag.IntVarP(&quantity, "quantity", "q", quantity, "set the number of names to generate")
pflag.UintVarP(&size, "size", "z", size, "set the number of words in the generated name (minimum 2, maximum 4)")
pflag.Int64VarP(&seed, "seed", "s", seed, "random generator seed")
pflag.Int64VarP(&seed, "seed", "s", 0, "random generator seed")
pflag.BoolVarP(&help, "help", "h", help, "show fname usage")
pflag.BoolVarP(&ver, "version", "v", ver, "show fname version")
pflag.Parse()
Expand All @@ -72,27 +74,49 @@ func main() {
os.Exit(0)
}

c, err := fname.CasingFromString(casing)
if quantity <= 0 {
log.Fatalf("error: quantity must be greater than 0, got %d", quantity)
}

if format != "plain" && format != "json" {
log.Fatalf("error: invalid format %q, must be plain or json", format)
}

c, err := fname.ParseCasing(casing)
handleError(err)

opts := []fname.GeneratorOption{
fname.WithCasing(c),
fname.WithDelimiter(delimiter),
}

if seed != -1 {
if pflag.Lookup("seed").Changed {
opts = append(opts, fname.WithSeed(seed))
}
if size != 2 {
opts = append(opts, fname.WithSize(size))
sizeOpt, err := fname.WithSize(size)
handleError(err)
opts = append(opts, sizeOpt)
}

rng := fname.NewGenerator(opts...)

names := make([]string, 0, quantity)
for i := 0; i < quantity; i++ {
name, err := rng.Generate()
handleError(err)
fmt.Println(name)
names = append(names, name)
}

switch format {
case "json":
out, err := json.Marshal(names)
handleError(err)
fmt.Println(string(out))
default:
for _, name := range names {
fmt.Println(name)
}
}
}

Expand Down
21 changes: 0 additions & 21 deletions data/adjective
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ certified
cerulean
challenging
changeable
characteristic
charged
charismatic
charmed
Expand All @@ -198,10 +197,7 @@ chaste
cheap
cheerful
cheery
chemical
cherry
chic
chief
childish
chilled
chilling
Expand All @@ -216,7 +212,6 @@ chubby
circular
civic
civil
civilian
civilized
clammy
clandestine
Expand Down Expand Up @@ -280,7 +275,6 @@ constant
constitutional
constructive
contemplative
content
continental
continuous
contradictory
Expand All @@ -290,7 +284,6 @@ conventional
convivial
cool
cooperative
copper
corporate
correct
cosmic
Expand Down Expand Up @@ -424,7 +417,6 @@ elliptical
eloquent
elusive
elysian
emerald
emotional
emphatic
empirical
Expand Down Expand Up @@ -645,7 +637,6 @@ glowing
glum
glutinous
gnomish
gold
golden
good
gooey
Expand Down Expand Up @@ -817,7 +808,6 @@ jealous
jingoistic
jittery
jocular
joint
jolly
jolting
jovial
Expand Down Expand Up @@ -872,7 +862,6 @@ likely
limited
linear
lined
linen
linguistic
liquid
literal
Expand Down Expand Up @@ -958,7 +947,6 @@ milky
mindful
minimum
minor
mint
minty
miraculous
mirthful
Expand Down Expand Up @@ -1104,7 +1092,6 @@ passive
past
pastel
pastoral
patient
patriotic
peaceful
pearly
Expand Down Expand Up @@ -1153,8 +1140,6 @@ pithy
placid
plain
planetary
plastic
platinum
plausible
pleasant
plentiful
Expand Down Expand Up @@ -1219,7 +1204,6 @@ pyrrhic
quaint
qualified
qualitative
quality
quantitative
quantum
quick
Expand Down Expand Up @@ -1269,11 +1253,9 @@ relevant
reliable
religious
repetitious
representative
reptilian
requisite
reserved
resident
residential
resilient
resolute
Expand Down Expand Up @@ -1308,7 +1290,6 @@ rotten
rough
round
routine
ruby
ruddy
runic
rural
Expand Down Expand Up @@ -1380,7 +1361,6 @@ shy
sick
significant
silly
silver
similar
simplistic
sincere
Expand Down Expand Up @@ -1704,7 +1684,6 @@ weary
weekly
welcome
welcoming
well
wet
whimsical
whiskered
Expand Down
Loading
Loading