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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ puff uuid --version 7 --time 1687689000
puff uuid --version 7 --time "2025-06-15T10:30:00.123Z"
01977323-90bb-72bb-89d6-86c1cbdd8912

# Print UUIDs with custom prefix
puff uuid -n 2 --compact --prefix "0x"
0x3826b9cce03c926dbebb0c0ed7467356
0x27751047cd3e1314500210ce1477b9ec

# Print UUIDs with custom suffix
puff uuid -n 2 --compact --suffix ".png"
8659b17b768a4ec5b48d1bac08279750.png
Expand All @@ -111,7 +116,11 @@ YPjRDxaUYFkurRAhz0MUzzl8Hh3Y0Z79DZcrJX5R/4g=
puff base64 --url-safe
7KtUKGFAvVHoDdsQDIuRtQ

# Print a URL-safe base64-encoded with custom suffix
# Print a URL-safe base64-encoded value with custom prefix
puff base64 --url-safe --prefix "bucket-x-"
bucket-x-tyIADpZWmW5W04QlCK9TPQ

# Print a URL-safe base64-encoded value with custom suffix
puff base64 --url-safe --suffix ".png"
BvOqihvrdg2kmtPQaxKx6A.png
```
Expand Down
21 changes: 17 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
delimiterParam = "delimiter"
numParam = "num"
outputParam = "output"
prefixParam = "prefix"
suffixParam = "suffix"
timeParam = "time"
urlSafeParam = "url-safe"
Expand Down Expand Up @@ -117,6 +118,7 @@ func printError(w io.Writer, err error) {
// delimiter, except the final value.
func generateHex(c *cli.Context) error {
iterations := c.Int(numParam)
prefix := c.String(prefixParam)
suffix := c.String(suffixParam)

if iterations <= 0 {
Expand All @@ -141,7 +143,7 @@ func generateHex(c *cli.Context) error {
delimiter = defaultDelimiter
}

fmt.Printf("%s%s%s", hex.EncodeToString(src), suffix, delimiter)
fmt.Printf("%s%s%s%s", prefix, hex.EncodeToString(src), suffix, delimiter)
}

return nil
Expand All @@ -153,6 +155,7 @@ func generateUUID(c *cli.Context) error {
version := c.Int(uuidVersionParam)
compact := c.Bool(compactParam)
iterations := c.Int(numParam)
prefix := c.String(prefixParam)
suffix := c.String(suffixParam)

if version != uuidV4 && version != uuidV7 {
Expand Down Expand Up @@ -195,7 +198,7 @@ func generateUUID(c *cli.Context) error {
delimiter = defaultDelimiter
}

fmt.Printf("%s%s%s", line, suffix, delimiter)
fmt.Printf("%s%s%s%s", prefix, line, suffix, delimiter)
}

return nil
Expand All @@ -208,6 +211,7 @@ func generateBase64(c *cli.Context) error {
iterations := c.Int(numParam)
delimiter := resolveDelimiter(c.String(delimiterParam))
urlSafe := c.Bool(urlSafeParam)
prefix := c.String(prefixParam)
suffix := c.String(suffixParam)

if len(delimiter) == 0 {
Expand All @@ -226,9 +230,9 @@ func generateBase64(c *cli.Context) error {
}

if urlSafe {
fmt.Printf("%s%s%s", base64.RawURLEncoding.EncodeToString(src), suffix, delimiter)
fmt.Printf("%s%s%s%s", prefix, base64.RawURLEncoding.EncodeToString(src), suffix, delimiter)
} else {
fmt.Printf("%s%s%s", base64.StdEncoding.EncodeToString(src), suffix, delimiter)
fmt.Printf("%s%s%s%s", prefix, base64.StdEncoding.EncodeToString(src), suffix, delimiter)
}
}

Expand Down Expand Up @@ -310,6 +314,12 @@ func main() {
Value: defaultDelimiter,
}

prefixFlag := &cli.StringFlag{
Name: "prefix",
Aliases: []string{"p"},
Usage: "optional value to prepend to the values",
}

suffixFlag := &cli.StringFlag{
Name: "suffix",
Aliases: []string{"s"},
Expand All @@ -330,6 +340,7 @@ func main() {
Value: 1,
},
delimiterFlag,
prefixFlag,
suffixFlag,
}

Expand Down Expand Up @@ -376,6 +387,7 @@ func main() {
Usage: "timestamp for UUID v7 (iso8601 or unix timestamp)",
},
delimiterFlag,
prefixFlag,
suffixFlag,
},
},
Expand All @@ -401,6 +413,7 @@ func main() {
Usage: "use url-safe encoding",
},
delimiterFlag,
prefixFlag,
suffixFlag,
},
},
Expand Down