From d0edb5b7ac3456f99c2f2576e8992cc12d60574a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 5 Jun 2026 04:45:11 +0900 Subject: refactor(json): model JsonFile encode/write options as a typed struct Replace the i64 bitmask + encode_with_indent split with a JsonEncodeOptions struct (Default = JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE, default indent). encode/write each get a default form plus an explicit encode_with_options/write_with_options variant, mirroring PHP's optional $options argument. write_with_options always encodes with self.indent, matching PHP write(). Also reconcile call sites with the PHP sources: most ported sites passed 0 where Composer omits the argument (= default flags), so JsonManipulator/ShowCommand and JsonConfigSource now use the default options; only ComposerRepository and Locker genuinely pass 0. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/command/show_command.rs | 38 ++++++++++++------------------ 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'crates/shirabe/src/command/show_command.rs') diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index f992798..bb7b909 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -575,12 +575,9 @@ impl ShowCommand { .collect(), ))]), ); - self.get_io().write(&JsonFile::encode( - &PhpMixed::Array( - wrapper.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), - ), - 0, - )); + self.get_io().write(&JsonFile::encode(&PhpMixed::Array( + wrapper.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), + ))); } else { self.display_package_tree(vec![array_tree]); } @@ -700,10 +697,9 @@ impl ShowCommand { .collect(), ), ); - self.get_io().write(&JsonFile::encode( - &PhpMixed::Array(wrapper.into_iter().map(|(k, v)| (k, Box::new(v))).collect()), - 0, - )); + self.get_io().write(&JsonFile::encode(&PhpMixed::Array( + wrapper.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), + ))); } else { self.display_package_tree(array_tree); } @@ -1152,15 +1148,12 @@ impl ShowCommand { ); } let io = self.get_io(); - io.write(&JsonFile::encode( - &PhpMixed::Array( - json_map - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ), - 0, - )); + io.write(&JsonFile::encode(&PhpMixed::Array( + json_map + .into_iter() + .map(|(k, v)| (k, Box::new(v))) + .collect(), + ))); } else { if input.get_option("latest").as_bool() == Some(true) && view_data.values().any(|v| !v.is_empty()) @@ -2025,10 +2018,9 @@ impl ShowCommand { json = Self::append_links(json, package); - self.get_io().write(&JsonFile::encode( - &PhpMixed::Array(json.into_iter().map(|(k, v)| (k, Box::new(v))).collect()), - 0, - )); + self.get_io().write(&JsonFile::encode(&PhpMixed::Array( + json.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), + ))); Ok(()) } -- cgit v1.3.1