coding-tools 0.6.1

Declarative, agent-friendly CLI tools behind one 'ct' command: search, view, verifiable edits, and framed command tests.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 Jonathan Shook

//! Shared JSON result output for the `--json` / `--json-pretty` tools: one
//! place that decides compact (the default, one line for piping into `jq`) vs.
//! pretty-printed (indented, for reading). `--json-pretty` implies `--json`.

use serde_json::Value;

/// Print a JSON value to stdout — pretty-printed (indented) when `pretty`, else
/// compact on a single line.
pub fn print(value: &Value, pretty: bool) {
    if pretty {
        println!("{}", serde_json::to_string_pretty(value).expect("a JSON value serializes"));
    } else {
        println!("{value}");
    }
}