diff --git a/src/command/mod.rs b/src/command/mod.rs index 1dc7351..80230e2 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -123,6 +123,23 @@ impl Command { } else if let Some((idx, _)) = &self.default_subcommand { extra.insert("default_subcommand".into(), (*idx).into()); } + if !self.metadata.is_empty() { + extra.insert( + "metadata".into(), + serde_json::json!(self + .metadata + .iter() + .map(|(k, v, _)| ( + k.to_string(), + if v.is_empty() { + None + } else { + Some(v.to_string()) + } + )) + .collect::>>()), + ); + } extra.insert("command_fn".into(), self.command_fn.clone().into()); let flag_options = self.all_flag_options().iter().map(|v| v.export()).collect(); CommandValue { diff --git a/tests/snapshots/integration__cli__export.snap b/tests/snapshots/integration__cli__export.snap index 3977738..a4f7684 100644 --- a/tests/snapshots/integration__cli__export.snap +++ b/tests/snapshots/integration__cli__export.snap @@ -2959,5 +2959,8 @@ expression: stdout } ], "combine_shorts": true, + "metadata": { + "combine-shorts": null + }, "command_fn": null }