Skip to content

Commit

Permalink
feat: include metadata when export json (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored May 16, 2024
1 parent b645ab7 commit 36d6d9d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<IndexMap<String, Option<String>>>()),
);
}
extra.insert("command_fn".into(), self.command_fn.clone().into());
let flag_options = self.all_flag_options().iter().map(|v| v.export()).collect();
CommandValue {
Expand Down
3 changes: 3 additions & 0 deletions tests/snapshots/integration__cli__export.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2959,5 +2959,8 @@ expression: stdout
}
],
"combine_shorts": true,
"metadata": {
"combine-shorts": null
},
"command_fn": null
}

0 comments on commit 36d6d9d

Please sign in to comment.