Support --json output for status command
#11
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Allows to easily use the output in scripts if needed (e.g. pipe that status output through
jq, etc)How
struct RepositoryStatusobject to represent the status reported bygit-conceal statusstruct FileStatusListandstruct FileStatusobjects to represent the status of files list reported bygit-conceal status file1 file2 …Serializetrait from theserdecrate—to handle JSON serialization (using#[derive(Serialize)]for implicit implementation of it)—and thefmt::Displaytrait—to handle plain text rendering.cmd_statusto build those objects representations regardless of the output format requested, and only at the end decide toprintln!those results either as JSON (serde_json::to_string_pretty(&status)) or as plain text (print!("{}", status)). (Making the code nicer than if I did giantif / elsebranches for all the cases)Testing Instructions
cargo build --releasefrom this PR's head branchgit-conceal, like of [AINFRA-1533] Adoptgit-concealin this repo woocommerce/woocommerce-android#14979 or [AINFRA-1539] [Internal] Migrate fromconfigure_applytogit-concealpocket-casts-android#4841, so you have a repo on which to test that command on