From 2f018e89c8584bc2bbca91054d0d5e96ed57e42d Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 9 Jan 2026 23:19:55 +0800 Subject: Add JSON output support for share list and see commands --- src/bin/jv.rs | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'src/bin') 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 = 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!( -- cgit