giv 0.2.3

A CLI for generating useful values.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# JSON Output Format

This document describes the JSON output format for all commands in the `giv` CLI tool. JSON output is enabled using the `--json` or `-j` flag.

## Overview

All commands return structured JSON objects with descriptive property names and relevant metadata. This provides:

- **Consistency**: Predictable structure across all commands
- **Metadata**: Additional context (version, precision, rounding flags, source data)
- **Parseability**: Easy integration with other tools and scripts
- **Type information**: Clear distinction between formatted values and raw data

### Common Patterns

- **Descriptive properties**: Use command-specific names (e.g., `"key"`, `"pi"`, `"uuid"`)
- **Metadata fields**: Include contextual information where relevant
- **Source data**: Raw or unformatted values stored in `source` arrays
- **Formatted values**: Display-ready values in `value` fields

---

## Commands

### `key` - Generate Random Key

**Output Structure**:

```json
{
  "key": "key_<alphanumeric>"
}
```

**Properties**:

- `key` (string): The generated key with `key_` prefix

**Examples**:

```bash
# Default size (36 characters)
giv --json key
```

```json
{
  "key": "key_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8"
}
```

```bash
# Custom size (10 characters)
giv --json key 10
```

```json
{
  "key": "key_a1b2c3d4e5"
}
```

---

### `uuid` - Generate UUID v7

**Output Structure**:

```json
{
  "uuid": "<uuid-string>",
  "version": "v7"
}
```

**Properties**:

- `uuid` (string): The generated UUID in standard format
- `version` (string): The UUID version (always `"v7"`)

**Examples**:

```bash
giv --json uuid
```

```json
{
  "uuid": "01234567-89ab-cdef-0123-456789abcdef",
  "version": "v7"
}
```

---

### `pi` - Calculate Pi

**Output Structure**:

```json
{
  "pi": "<value>",
  "rounded": true|false
}
```

**Properties**:

- `pi` (string): Pi value formatted to the specified decimal places
- `rounded` (boolean): Whether rounding was applied to the last digit

**Examples**:

```bash
# Default precision (15 decimal places, rounded)
giv --json pi
```

```json
{
  "pi": "3.141592653589793",
  "rounded": true
}
```

```bash
# Custom precision (10 decimal places, rounded)
giv --json pi 10
```

```json
{
  "pi": "3.1415926536",
  "rounded": true
}
```

```bash
# No rounding
giv --json pi 10 --no-round
```

```json
{
  "pi": "3.1415926535",
  "rounded": false
}
```

---

### `date` - Generate Date

**Output Structure**:

```json
{
  "date": "<formatted-date>"
}
```

**Properties**:

- `date` (string): The formatted date/time string

**Examples**:

```bash
# Current date and time (RFC 3339)
giv --json date now
```

```json
{
  "date": "2025-09-02T14:30:15.123Z"
}
```

```bash
# Current timestamp
giv --json date timestamp
```

```json
{
  "date": "1725283815"
}
```

```bash
# Today's date
giv --json date today
```

```json
{
  "date": "2025-09-02"
}
```

```bash
# Custom format
giv --json date now --format timestamp-ms
```

```json
{
  "date": "1725283815123"
}
```

---

### `now` - Current Time Alias

**Output Structure**:

```json
{
  "date": "<formatted-date>"
}
```

**Properties**:

- `date` (string): The current UTC time in the specified format

**Examples**:

```bash
# Current time (default RFC 3339)
giv --json now
```

```json
{
  "date": "2025-09-02T14:30:15.123Z"
}
```

```bash
# Current time as timestamp
giv --json now --format timestamp
```

```json
{
  "date": "1725283815"
}
```

---

### `rng` - Random Number Generation

**Output Structure**:

```json
{
  "rng": [
    {
      "type": "dice|range_int|range_float",
      "notation": "<spec>",
      "value": <formatted-value>,
      "precision": <number>,
      "source": [<raw-values>]
    }
  ]
}
```

**Properties**:

- `rng` (array): Array of results, one per specification
  - `type` (string): The type of random generation
    - `"dice"`: Dice roll (e.g., `3d6`)
    - `"range_int"`: Integer range (e.g., `1..100`)
    - `"range_float"`: Float range (e.g., `1.0..10.0`)
  - `notation` (string): The parsed specification notation
  - `value` (number|string): The final result
    - For `dice`: Sum of all rolls plus modifier (number, can be negative)
    - For `range_int`: The generated integer (number)
    - For `range_float`: Formatted string with precision
  - `modifier` (number): The modifier applied to dice rolls (dice only, can be negative)
  - `precision` (number): Decimal places (float ranges only)
  - `source` (array): Raw data
    - For `dice`: Individual roll results (before modifier)
    - For `range_float`: Full-precision floating point value(s)
    - Not present for `range_int`

**Examples**:

```bash
# Dice roll without modifier
giv --json rng 3d6
```

```json
{
  "rng": [
    {
      "type": "dice",
      "notation": "3d6",
      "value": 13,
      "modifier": 0,
      "source": [6, 4, 3]
    }
  ]
}
```

```bash
# Dice roll with positive modifier
giv --json rng 3d6+2
```

```json
{
  "rng": [
    {
      "type": "dice",
      "notation": "3d6+2",
      "value": 15,
      "modifier": 2,
      "source": [5, 6, 2]
    }
  ]
}
```

```bash
# Dice roll with negative modifier
giv --json rng 1d20-1
```

```json
{
  "rng": [
    {
      "type": "dice",
      "notation": "d20-1",
      "value": 14,
      "modifier": -1,
      "source": [15]
    }
  ]
}
```

```bash
# Integer range
giv --json rng 1..100
```

```json
{
  "rng": [
    {
      "type": "range_int",
      "notation": "1..100",
      "value": 42
    }
  ]
}
```

```bash
# Float range
giv --json rng 1.0..10.0
```

```json
{
  "rng": [
    {
      "type": "range_float",
      "notation": "1.0..10.0",
      "value": "2.5",
      "precision": 1,
      "source": [2.510738494148031]
    }
  ]
}
```

```bash
# Multiple specifications
giv --json rng 2d6 1..100 0.0..1.0
```

```json
{
  "rng": [
    {
      "type": "dice",
      "notation": "2d6",
      "value": 8,
      "modifier": 0,
      "source": [5, 3]
    },
    {
      "type": "range_int",
      "notation": "1..100",
      "value": 67
    },
    {
      "type": "range_float",
      "notation": "0.0..1.0",
      "value": "0.7",
      "precision": 1,
      "source": [0.7234567890123456]
    }
  ]
}
```

---

## Usage Tips

### Parsing JSON Output

Use `jq` or similar tools to parse and extract values:

```bash
# Extract just the UUID value
giv --json uuid | jq -r '.uuid'
# Output: 01234567-89ab-cdef-0123-456789abcdef

# Extract pi value
giv --json pi 10 | jq -r '.pi'
# Output: 3.1415926536

# Check if rounding was applied
giv --json pi 10 | jq '.rounded'
# Output: true

# Extract all dice roll results
giv --json rng 3d6 | jq '.rng[0].source'
# Output: [6, 4, 3]

# Get float source value for higher precision
giv --json rng 1.0..10.0 | jq '.rng[0].source[0]'
# Output: 2.510738494148031
```

### Scripting Integration

JSON output is designed for integration with scripts and automation:

```bash
# Generate multiple keys and process with jq
for i in {1..5}; do
  giv --json key 8 | jq -r '.key'
done

# Get current timestamp for logging
timestamp=$(giv --json now --format timestamp | jq -r '.date')
echo "Event at: $timestamp"

# Generate random number for scripting
random_value=$(giv --json rng 1..100 | jq '.rng[0].value')
if [ "$random_value" -gt 50 ]; then
  echo "High roll: $random_value"
fi
```

### Type Safety

JSON output provides type information making it easier to handle values correctly:

- Strings are always quoted: `"3.14"`, `"key_abc"`
- Numbers are unquoted: `42`, `3.14159`
- Booleans are lowercase: `true`, `false`
- Arrays provide access to multiple values: `[6, 4, 3]`

---

## Availability

JSON output is only available when `giv` is compiled with the `json` feature enabled. This is the default configuration.

To check if JSON support is available:

```bash
giv --help | grep -q "\-\-json" && echo "JSON supported" || echo "JSON not available"
```