aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/base_dependency_command.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-17 11:52:08 +0900
committernsfisis <nsfisis@gmail.com>2026-05-17 11:52:20 +0900
commit93a7671c98a9f022d757781f8fe583a2d55df07b (patch)
tree66ad0cef7ac58823262280a6bf94961c1d73f92a /crates/shirabe/src/command/base_dependency_command.rs
parent35690acf83fa4473311a18e970ecd8156e1e6ac0 (diff)
downloadphp-shirabe-93a7671c98a9f022d757781f8fe583a2d55df07b.tar.gz
php-shirabe-93a7671c98a9f022d757781f8fe583a2d55df07b.tar.zst
php-shirabe-93a7671c98a9f022d757781f8fe583a2d55df07b.zip
refactor(shirabe): convert PHP abstract classes to Rust traits
PHP abstract classes are represented as traits to better align with Rust's type system.
Diffstat (limited to 'crates/shirabe/src/command/base_dependency_command.rs')
-rw-r--r--crates/shirabe/src/command/base_dependency_command.rs45
1 files changed, 21 insertions, 24 deletions
diff --git a/crates/shirabe/src/command/base_dependency_command.rs b/crates/shirabe/src/command/base_dependency_command.rs
index 4ea779a..62b97ea 100644
--- a/crates/shirabe/src/command/base_dependency_command.rs
+++ b/crates/shirabe/src/command/base_dependency_command.rs
@@ -24,44 +24,41 @@ use crate::repository::repository_interface::{FindPackageConstraint, RepositoryI
use crate::repository::root_package_repository::RootPackageRepository;
use crate::util::package_info::PackageInfo;
-#[derive(Debug)]
-pub struct BaseDependencyCommand {
- inner: BaseCommand,
- pub(crate) colors: Vec<String>,
-}
+pub trait BaseDependencyCommand: BaseCommand {
+ const ARGUMENT_PACKAGE: &'static str = "package";
+ const ARGUMENT_CONSTRAINT: &'static str = "version";
+ const OPTION_RECURSIVE: &'static str = "recursive";
+ const OPTION_TREE: &'static str = "tree";
-impl BaseDependencyCommand {
- pub const ARGUMENT_PACKAGE: &'static str = "package";
- pub const ARGUMENT_CONSTRAINT: &'static str = "version";
- pub const OPTION_RECURSIVE: &'static str = "recursive";
- pub const OPTION_TREE: &'static str = "tree";
+ fn colors(&self) -> &[String];
+ fn colors_mut(&mut self) -> &mut [String];
- pub fn set_name(&mut self, name: &str) -> &mut Self {
+ fn set_name(&mut self, name: &str) -> &mut Self {
self.inner.set_name(name);
self
}
- pub fn set_aliases(&mut self, aliases: Vec<String>) -> &mut Self {
+ fn set_aliases(&mut self, aliases: Vec<String>) -> &mut Self {
self.inner.set_aliases(aliases);
self
}
- pub fn set_description(&mut self, description: &str) -> &mut Self {
+ fn set_description(&mut self, description: &str) -> &mut Self {
self.inner.set_description(description);
self
}
- pub fn set_definition(&mut self, definition: Vec<shirabe_php_shim::PhpMixed>) -> &mut Self {
+ fn set_definition(&mut self, definition: Vec<shirabe_php_shim::PhpMixed>) -> &mut Self {
self.inner.set_definition(definition);
self
}
- pub fn set_help(&mut self, help: &str) -> &mut Self {
+ fn set_help(&mut self, help: &str) -> &mut Self {
self.inner.set_help(help);
self
}
- pub(crate) fn do_execute(
+ fn do_execute(
&mut self,
input: &dyn InputInterface,
output: &dyn OutputInterface,
@@ -309,7 +306,7 @@ impl BaseDependencyCommand {
Ok(r#return)
}
- pub(crate) fn print_table(&self, output: &dyn OutputInterface, results: Vec<DependentsEntry>) {
+ fn print_table(&self, output: &dyn OutputInterface, results: Vec<DependentsEntry>) {
let mut table: Vec<Vec<String>> = vec![];
let mut doubles: IndexMap<String, bool> = IndexMap::new();
let mut results = results;
@@ -362,28 +359,28 @@ impl BaseDependencyCommand {
self.inner.render_table(table, output);
}
- pub(crate) fn init_styles(&mut self, output: &dyn OutputInterface) {
- self.colors = vec![
+ fn init_styles(&mut self, output: &dyn OutputInterface) {
+ *self.colors_mut() = vec![
"green".to_string(),
"yellow".to_string(),
"cyan".to_string(),
"magenta".to_string(),
"blue".to_string(),
];
- for color in &self.colors {
+ for color in &self.colors() {
let style = OutputFormatterStyle::new(color.clone());
output.get_formatter().set_style(color, style);
}
}
- pub(crate) fn print_tree(&self, results: &[DependentsEntry], prefix: &str, level: i64) {
+ fn print_tree(&self, results: &[DependentsEntry], prefix: &str, level: i64) {
let count = results.len() as i64;
let mut idx: i64 = 0;
- let colors_len = self.colors.len() as i64;
+ let colors_len = self.colors().len() as i64;
for result in results {
let DependentsEntry(package, link, children) = result;
- let color = &self.colors[(level % colors_len) as usize];
- let prev_color = &self.colors[((level - 1) % colors_len) as usize];
+ let color = &self.colors()[(level % colors_len) as usize];
+ let prev_color = &self.colors()[((level - 1) % colors_len) as usize];
idx += 1;
let is_last = idx == count;
let version_text =