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
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
[![go workflow](https://github.com/chronohq/puff/actions/workflows/go.yml/badge.svg)](https://github.com/chronohq/puff/actions/workflows/go.yml)
[![mit license](https://img.shields.io/badge/license-MIT-green)](/LICENSE)

Puff is a command-line tool designed to quickly generate random values
in various formats such as hexadecimal strings, UUIDs, and binary blobs.
Whether for testing, cryptographic purposes, or data seeding, Puff makes
the process straightforward.
Puff is a command-line tool for quickly generating random values in formats like hexadecimal strings, UUIDs, and binary blobs.
It’s built on Go’s standard library and Google’s UUID package, using components that are widely used and well-tested.
Suitable for testing, ID generation, cryptographic workflows, and data seeding.

## Installation

Expand Down Expand Up @@ -34,38 +33,39 @@ rm /usr/local/bin/puff && tar -C /usr/local/bin xvzf puff-1.2.3.linux-amd64.tar.

## Quickstart

### Print Hexadecimal Values (Default: 16 Bytes)
Running `puff` without any subcommand will generate a single hexadecimal string by default.

Use `puff hex --help` to view available command options.
### Hexadecimal (default): `puff hex --help` for options

By default, Puff generates 16 random bytes and encodes them as a 32-character hexadecimal string.

```bash
# Print a single hex-encoded value
puff hex
puff
2cc84ba90e5277f6733aa71386a4de3b

# Print two hex-encoded values
puff hex -n 2
puff -n 2
f906e2fa87fbf6e9f0b0b44e2fc81993
5d7347c2fe7fda44097604c06ae4f25f

# Print a hex-encoded value with custom byte length (32 bytes)
puff hex --bytes 32
puff --bytes 32
8c5955a659c59d4414072b45bac872964a8a8077ffbd0f0083ffad47e5b33c66

# Print hex-encoded values separated by a comma
puff hex -n 2 --delimiter ","
puff -n 2 --delimiter ","
d4bc48da024a728fee985a6257e88611,63100951b7ff67de3f7e9c1d0b98101d

# Print hex-encoded values with a custom suffix
puff hex -n 2 --suffix ".png"
puff -n 2 --suffix ".png"
2259c58f9a774fe171720349cd715bed.png
314fb96973ccf36ef579fcaa9303ddcc.png
```

### Print UUIDs as Hexadecimal Values
### UUID: `puff uuid --help` for options

By default, Puff generates version 4 UUIDs, but version 7 is also supported.
Use `puff uuid --help` to view available command options.

```bash
# Print two version 4 UUIDs (default)
Expand All @@ -88,9 +88,7 @@ puff uuid -n 2 --compact --suffix ".png"
805fc8e5b2aa4de0a7f37deecbf9a606.png
```

### Print Base64 Values (Default: 16 Bytes)

Use `puff base64 --help` to view available command options.
### Base64: `puff base64 --help` for options

```bash
# Print a single base64-encoded value
Expand All @@ -110,9 +108,9 @@ puff base64 --url-safe --suffix ".png"
BvOqihvrdg2kmtPQaxKx6A.png
```

### Create a Binary File with Random Bytes
### Binary: `puff binary --help` for options

Similar to using `dd` for generating test data, you can use `puff` to create a binary file with random bytes:
Similar to using `dd` for generating test data, Puff can create a binary file with random bytes (default: 1MB).

```bash
# Create a 10MB binary file with random bytes
Expand Down
39 changes: 23 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,31 +270,38 @@ func main() {
Usage: "optional value to append to the values",
}

hexCommandFlags := []cli.Flag{
&cli.IntFlag{
Name: "bytes",
Aliases: []string{"b"},
Usage: "length of the source data in bytes",
Value: defaultDataBytes,
},
&cli.IntFlag{
Name: "num",
Aliases: []string{"n"},
Usage: "number of hex strings to generate",
Value: 1,
},
delimiterFlag,
suffixFlag,
}

app := &cli.App{
Name: "puff",
Usage: "Generate random values in different formats",
Version: version,

// default to the hex command if no subcommand is provided
Action: generateHex,
Flags: hexCommandFlags,

Commands: []*cli.Command{
{
Name: "hex",
Usage: "Generate random hexadecimal strings",
Action: generateHex,
Flags: []cli.Flag{
&cli.IntFlag{
Name: "bytes",
Aliases: []string{"b"},
Usage: "length of the source data in bytes",
Value: defaultDataBytes,
},
&cli.IntFlag{
Name: "num",
Aliases: []string{"n"},
Usage: "number of hex strings to generate",
Value: 1,
},
delimiterFlag,
suffixFlag,
},
Flags: hexCommandFlags,
},
{
Name: "uuid",
Expand Down