Skip to main content

command_to_ndjson

Function command_to_ndjson 

Source
pub fn command_to_ndjson(cmd: &Command) -> Result<String, QueryError>
Expand description

Serialize a single Command to a compact (single-line) JSON string.

The output contains no trailing newline. Handler closures are excluded. This is the single-command companion to Registry::to_ndjson.

§Errors

Returns QueryError::Serialization if serialization fails.

§Examples

let cmd = Command::builder("deploy").summary("Deploy").build().unwrap();
let line = command_to_ndjson(&cmd).unwrap();
// No trailing newline.
assert!(!line.ends_with('\n'));
// Must be valid compact JSON on one line.
assert!(!line.contains('\n'));
let val: serde_json::Value = serde_json::from_str(&line).unwrap();
assert_eq!(val["canonical"], "deploy");