Skip to content

Commit d5ee7be

Browse files
authored
feat: unify dirctl cli output (#289)
* add new dirctl cli --output flag description * update cli command --output examples Signed-off-by: Tibor Kircsi <tkircsi@cisco.com>
1 parent cd574f6 commit d5ee7be

4 files changed

Lines changed: 108 additions & 17 deletions

File tree

docs/dir/directory-cli.md

Lines changed: 88 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,62 @@ The following example demonstrates how to store, publish, search, and retrieve a
6767
dirctl pull baeareihdr6t7s6sr2q4zo456sza66eewqc7huzatyfgvoupaqyjw23ilvi
6868
```
6969

70+
## Output Formats
71+
72+
All `dirctl` commands support multiple output formats via the `--output` (or `-o`) flag, making it easy to switch between human-readable output and machine-processable formats.
73+
74+
### Available Formats
75+
76+
| Format | Description | Use Case |
77+
|--------|-------------|----------|
78+
| `human` | Human-readable, formatted output with colors and tables (default) | Interactive terminal use |
79+
| `json` | Pretty-printed JSON with indentation | Debugging, single-record processing |
80+
| `jsonl` | Newline-delimited JSON (compact, one object per line) | Streaming, batch processing, logging |
81+
| `raw` | Raw values only (e.g., CIDs, IDs) | Shell scripting, piping to other commands |
82+
83+
### Usage
84+
85+
```bash
86+
# Human-readable output (default)
87+
dirctl routing list
88+
89+
# JSON output (pretty-printed)
90+
dirctl routing list --output json
91+
dirctl routing list -o json
92+
93+
# JSONL output (streaming-friendly)
94+
dirctl events listen --output jsonl
95+
96+
# Raw output (just values)
97+
dirctl push my-agent.json --output raw
98+
```
99+
100+
### Piping and Processing
101+
102+
Structured formats (`json`, `jsonl`, `raw`) automatically route data to **stdout** and metadata messages to **stderr**, enabling clean piping to tools like `jq`:
103+
104+
```bash
105+
# Process JSON output with jq
106+
dirctl routing search --skill "AI" -o json | jq '.[] | .cid'
107+
108+
# Stream events and filter by type
109+
dirctl events listen -o jsonl | jq -c 'select(.type == "EVENT_TYPE_RECORD_PUSHED")'
110+
111+
# Capture CID for scripting
112+
CID=$(dirctl push my-agent.json -o raw)
113+
echo "Stored with CID: $CID"
114+
115+
# Chain commands
116+
dirctl routing list -o json | jq -r '.[].cid' | xargs -I {} dirctl pull {}
117+
```
118+
119+
### Format Selection Guidelines
120+
121+
- **`human`**: Default for terminal interaction, provides context and formatting
122+
- **`json`**: Best for debugging or when you need readable structured data
123+
- **`jsonl`**: Ideal for streaming events, logs, or processing large result sets line-by-line
124+
- **`raw`**: Perfect for shell scripts and command chaining where you only need the value
125+
70126
## Command Reference
71127

72128
### Storage Operations
@@ -398,7 +454,9 @@ The following workflow demonstrates how to publish a record to the network:
398454
1. Store your record
399455

400456
```bash
401-
CID=$(dirctl push my-agent.json)
457+
# Using --output raw for clean scripting
458+
CID=$(dirctl push my-agent.json --output raw)
459+
echo "Stored with CID: $CID"
402460
```
403461

404462
1. Publish for discovery
@@ -410,7 +468,8 @@ The following workflow demonstrates how to publish a record to the network:
410468
1. Verify the record is published
411469

412470
```bash
413-
dirctl routing list --cid $CID
471+
# Use JSON output for programmatic verification
472+
dirctl routing list --cid $CID --output json
414473
```
415474

416475
1. Check routing statistics
@@ -426,18 +485,22 @@ The following workflow demonstrates how to discover records from the network:
426485
1. Search for records by skill
427486

428487
```bash
429-
dirctl routing search --skill "AI" --limit 10
488+
# Use JSON output to process results
489+
dirctl routing search --skill "AI" --limit 10 --output json
430490
```
431491

432492
1. Search with multiple criteria
433493

434494
```bash
435-
dirctl routing search --skill "AI" --locator "docker-image" --min-score 2
495+
dirctl routing search --skill "AI" --locator "docker-image" --min-score 2 --output json
436496
```
437497

438-
1. Pull interesting records
498+
1. Pull discovered records
439499
```bash
440-
dirctl pull <discovered-cid>
500+
# Extract CIDs and pull records
501+
dirctl routing search --skill "AI" --output json | \
502+
jq -r '.[].record_ref.cid' | \
503+
xargs -I {} dirctl pull {}
441504
```
442505

443506
### Synchronization Workflow
@@ -447,19 +510,23 @@ The following workflow demonstrates how to synchronize records between remote di
447510
1. Create sync with remote peer
448511

449512
```bash
450-
SYNC_ID=$(dirctl sync create https://peer.example.com)
513+
# Using --output raw for clean variable capture
514+
SYNC_ID=$(dirctl sync create https://peer.example.com --output raw)
515+
echo "Sync created with ID: $SYNC_ID"
451516
```
452517

453518
1. Monitor sync progress
454519

455520
```bash
456-
dirctl sync status $SYNC_ID
521+
# Use JSON output for programmatic monitoring
522+
dirctl sync status $SYNC_ID --output json
457523
```
458524

459525
1. List all syncs
460526

461527
```bash
462-
dirctl sync list
528+
# Use JSONL output for streaming results
529+
dirctl sync list --output jsonl
463530
```
464531

465532
1. Clean up when done
@@ -468,6 +535,18 @@ The following workflow demonstrates how to synchronize records between remote di
468535
dirctl sync delete $SYNC_ID
469536
```
470537

538+
### Advanced Synchronization: Search-to-Sync Pipeline
539+
540+
Automatically sync records that match specific criteria from the network:
541+
542+
```bash
543+
# Search for AI-related records and create sync operations
544+
dirctl routing search --skill "AI" --output json | dirctl sync create --stdin
545+
546+
# This creates separate sync operations for each remote peer found,
547+
# syncing only the specific CIDs that matched your search criteria
548+
```
549+
471550
## Command Organization
472551

473552
The CLI follows a clear service-based organization:

docs/dir/events.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,20 @@ dirctl events listen --cids bafybe...,bafkyb...
9797
For programmatic processing:
9898

9999
```bash
100-
# JSON format output
101-
dirctl events listen --json
100+
# JSONL format output (streaming-friendly, one event per line)
101+
dirctl events listen --output jsonl
102+
103+
# JSON format output (pretty-printed)
104+
dirctl events listen --output json
102105
```
103106

107+
**JSONL format** (recommended for streaming - compact, one event per line):
108+
```json
109+
{"id":"550e8400-...","type":"EVENT_TYPE_RECORD_PUSHED","timestamp":"2025-10-18T14:23:15.123456Z","resource_id":"bafybeig...","labels":["/skills/AI"]}
110+
{"id":"550e8401-...","type":"EVENT_TYPE_RECORD_PUBLISHED","timestamp":"2025-10-18T14:23:16.456789Z","resource_id":"bafybeig...","labels":["/skills/AI"]}
111+
```
112+
113+
**JSON format** (pretty-printed):
104114
```json
105115
{
106116
"id": "550e8400-e29b-41d4-a716-446655440000",
@@ -111,6 +121,8 @@ dirctl events listen --json
111121
}
112122
```
113123

124+
> **Note:** For streaming events, use `--output jsonl` format as it outputs one compact JSON object per line, making it ideal for real-time processing with tools like `jq`.
125+
114126
### Combine Filters
115127

116128
All filter types can be combined for precise event monitoring:
@@ -120,7 +132,7 @@ All filter types can be combined for precise event monitoring:
120132
dirctl events listen \
121133
--types RECORD_PUSHED,RECORD_PULLED \
122134
--labels /skills/AI \
123-
--json
135+
--output jsonl
124136
```
125137

126138
## Using the Go SDK
@@ -251,7 +263,7 @@ Track system activity for operational awareness:
251263

252264
```bash
253265
# Monitor all operations in production
254-
dirctl events listen --json | tee events.log
266+
dirctl events listen --output jsonl | tee events.log
255267

256268
# Alert on failed syncs
257269
dirctl events listen --types SYNC_FAILED | \
@@ -294,7 +306,7 @@ Maintain audit trails for critical operations:
294306

295307
```bash
296308
# Record all signature events
297-
dirctl events listen --types RECORD_SIGNED --json >> audit.jsonl
309+
dirctl events listen --types RECORD_SIGNED --output jsonl >> audit.jsonl
298310
```
299311

300312
### Development and Debugging
@@ -303,7 +315,7 @@ Monitor system behavior during development:
303315

304316
```bash
305317
# Watch all events during testing
306-
dirctl events listen --json | jq .
318+
dirctl events listen --output jsonl | jq -c .
307319

308320
# Track specific record through the system
309321
dirctl events listen --cids $RECORD_CID

docs/dir/hosted-agent-directory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ The `dirctl` command line tools supports two methods to authenticate to a Outshi
177177
```
178178

179179
```bash
180-
$ dirctl hub apikey create --org-name your-user --role ROLE_ADMIN --json > api-key-creds.json
180+
$ dirctl hub apikey create --org-name your-user --role ROLE_ADMIN --output json > api-key-creds.json
181181
```
182182

183183
* Set the environment variable and use the dirctl commands as usual or provide the JSON file with the credentials:

docs/dir/scenarios.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ match specific criteria:
384384
```bash
385385
# Search for agents with a given skill across
386386
# the network and sync them automatically
387-
dirctl routing search --skill "Audio" --json | dirctl sync create --stdin
387+
dirctl routing search --skill "Audio" --output json | dirctl sync create --stdin
388388
```
389389

390390
This creates separate sync operations for each remote peer found in the search results,

0 commit comments

Comments
 (0)