diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-01-09 23:19:55 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-01-09 23:19:55 +0800 |
| commit | 2f018e89c8584bc2bbca91054d0d5e96ed57e42d (patch) | |
| tree | 4cbacfab1a4d7a5db5ae1e87ef7719bc3f9e5737 | |
| parent | ab2c87b785036a872e17eac771c65a4af88790e5 (diff) | |
Add JSON output support for share list and see commands
| -rw-r--r-- | src/bin/jv.rs | 39 | ||||
| -rw-r--r-- | src/output.rs | 1 | ||||
| -rw-r--r-- | src/output/share.rs | 32 |
3 files changed, 70 insertions, 2 deletions
diff --git a/src/bin/jv.rs b/src/bin/jv.rs index de40b23..21ec126 100644 --- a/src/bin/jv.rs +++ b/src/bin/jv.rs @@ -92,6 +92,7 @@ use just_enough_vcs_cli::{ analyzer_result::{AnalyzerJsonResult, ModifiedType}, here::{HereJsonResult, HereJsonResultItem}, info::{InfoHistory, InfoJsonResult}, + share::{SeeShareResult, ShareItem, ShareListResult}, sheets::{SheetItem, SheetListJsonResult}, }, utils::{ @@ -730,6 +731,14 @@ struct ShareMappingArgs { /// Show raw output #[arg(short = 'r', long)] raw: bool, + + /// Show json output + #[arg(long = "json")] + json_output: bool, + + /// Show json output pretty + #[arg(long = "pretty")] + pretty: bool, } #[derive(Parser, Debug)] @@ -4751,7 +4760,7 @@ async fn jv_share(args: ShareMappingArgs) { if let (Some(args1), Some(args2), None) = (&args.args1, &args.args2, &args.args3) { // See mode if args1.trim() == "see" { - share_see(args2.to_string()).await; + share_see(args2.to_string(), args).await; return; } @@ -4814,6 +4823,21 @@ async fn share_list(args: ShareMappingArgs) { sorted_shares.insert(id.clone(), share); } + if args.json_output { + let share_list: Vec<ShareItem> = sorted_shares + .iter() + .map(|(share_id, share)| ShareItem { + share_id: share_id.clone(), + sharer: share.sharer.clone(), + description: share.description.clone(), + file_count: share.mappings.len(), + }) + .collect(); + let result = ShareListResult { share_list }; + print_json(result, args.pretty); + return; + } + if !args.raw { // Create table and insert information let mut table = SimpleTable::new(vec![ @@ -4845,7 +4869,7 @@ async fn share_list(args: ShareMappingArgs) { } } -async fn share_see(share_id: String) { +async fn share_see(share_id: String, args: ShareMappingArgs) { let _ = correct_current_dir(); let Some(local_dir) = current_local_path() else { @@ -4878,6 +4902,17 @@ async fn share_see(share_id: String) { if let Some(shares) = latest_info.shares_in_my_sheets.get(&sheet_name) { if let Some(share) = shares.get(&share_id) { + if args.json_output { + let result = SeeShareResult { + share_id: share_id.clone(), + sharer: share.sharer.clone(), + description: share.description.clone(), + mappings: share.mappings.clone(), + }; + print_json(result, args.pretty); + return; + } + println!( "{}", md(t!( diff --git a/src/output.rs b/src/output.rs index c121b82..88802a4 100644 --- a/src/output.rs +++ b/src/output.rs @@ -3,4 +3,5 @@ pub mod align; pub mod analyzer_result; pub mod here; pub mod info; +pub mod share; pub mod sheets; diff --git a/src/output/share.rs b/src/output/share.rs new file mode 100644 index 0000000..6fbfc3f --- /dev/null +++ b/src/output/share.rs @@ -0,0 +1,32 @@ +use std::collections::HashMap; + +use just_enough_vcs::vcs::data::{ + member::MemberId, + sheet::{SheetMappingMetadata, SheetPathBuf}, + vault::sheet_share::SheetShareId, +}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Default, Serialize, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct ShareListResult { + pub share_list: Vec<ShareItem>, +} + +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct ShareItem { + pub share_id: SheetShareId, + pub sharer: MemberId, + pub description: String, + pub file_count: usize, +} + +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct SeeShareResult { + pub share_id: SheetShareId, + pub sharer: MemberId, + pub description: String, + pub mappings: HashMap<SheetPathBuf, SheetMappingMetadata>, +} |
