aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/clear_cache_command.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/command/clear_cache_command.rs')
-rw-r--r--crates/shirabe/src/command/clear_cache_command.rs64
1 files changed, 43 insertions, 21 deletions
diff --git a/crates/shirabe/src/command/clear_cache_command.rs b/crates/shirabe/src/command/clear_cache_command.rs
index fe2c4dd..06026a4 100644
--- a/crates/shirabe/src/command/clear_cache_command.rs
+++ b/crates/shirabe/src/command/clear_cache_command.rs
@@ -1,12 +1,12 @@
//! ref: composer/src/Composer/Command/ClearCacheCommand.php
-use indexmap::IndexMap;
-use shirabe_external_packages::symfony::console::input::input_interface::InputInterface;
-use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface;
use crate::cache::Cache;
use crate::command::base_command::BaseCommand;
use crate::console::input::input_option::InputOption;
use crate::factory::Factory;
+use indexmap::IndexMap;
+use shirabe_external_packages::symfony::console::input::input_interface::InputInterface;
+use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface;
#[derive(Debug)]
pub struct ClearCacheCommand {
@@ -19,22 +19,24 @@ impl ClearCacheCommand {
.set_name("clear-cache")
.set_aliases(vec!["clearcache".to_string(), "cc".to_string()])
.set_description("Clears composer's internal package cache")
- .set_definition(vec![
- InputOption::new(
- "gc",
- None,
- InputOption::VALUE_NONE,
- "Only run garbage collection, not a full cache clear",
- ),
- ])
+ .set_definition(vec![InputOption::new(
+ "gc",
+ None,
+ InputOption::VALUE_NONE,
+ "Only run garbage collection, not a full cache clear",
+ )])
.set_help(
"The <info>clear-cache</info> deletes all cached packages from composer's\n\
cache directory.\n\n\
- Read more at https://getcomposer.org/doc/03-cli.md#clear-cache-clearcache-cc"
+ Read more at https://getcomposer.org/doc/03-cli.md#clear-cache-clearcache-cc",
);
}
- pub fn execute(&self, input: &dyn InputInterface, _output: &dyn OutputInterface) -> anyhow::Result<i64> {
+ pub fn execute(
+ &self,
+ input: &dyn InputInterface,
+ _output: &dyn OutputInterface,
+ ) -> anyhow::Result<i64> {
let composer = self.inner.try_composer();
let config = if let Some(composer) = composer {
composer.get_config()
@@ -45,9 +47,18 @@ impl ClearCacheCommand {
let io = self.inner.get_io();
let mut cache_paths: IndexMap<String, String> = IndexMap::new();
- cache_paths.insert("cache-vcs-dir".to_string(), config.get("cache-vcs-dir").to_string());
- cache_paths.insert("cache-repo-dir".to_string(), config.get("cache-repo-dir").to_string());
- cache_paths.insert("cache-files-dir".to_string(), config.get("cache-files-dir").to_string());
+ cache_paths.insert(
+ "cache-vcs-dir".to_string(),
+ config.get("cache-vcs-dir").to_string(),
+ );
+ cache_paths.insert(
+ "cache-repo-dir".to_string(),
+ config.get("cache-repo-dir").to_string(),
+ );
+ cache_paths.insert(
+ "cache-files-dir".to_string(),
+ config.get("cache-files-dir").to_string(),
+ );
cache_paths.insert("cache-dir".to_string(), config.get("cache-dir").to_string());
for (key, cache_path) in &cache_paths {
@@ -59,28 +70,39 @@ impl ClearCacheCommand {
let cache_path = shirabe_php_shim::realpath(cache_path);
if !cache_path.as_ref().map(|s| !s.is_empty()).unwrap_or(false) {
let cache_path_display = cache_path.as_deref().unwrap_or("");
- io.write_error(&format!("<info>Cache directory does not exist ({key}): {cache_path_display}</info>"));
+ io.write_error(&format!(
+ "<info>Cache directory does not exist ({key}): {cache_path_display}</info>"
+ ));
continue;
}
let cache_path = cache_path.unwrap();
let mut cache = Cache::new(io, &cache_path);
cache.set_read_only(config.get("cache-read-only").as_bool().unwrap_or(false));
if !cache.is_enabled() {
- io.write_error(&format!("<info>Cache is not enabled ({key}): {cache_path}</info>"));
+ io.write_error(&format!(
+ "<info>Cache is not enabled ({key}): {cache_path}</info>"
+ ));
continue;
}
if input.get_option("gc").as_bool() {
- io.write_error(&format!("<info>Garbage-collecting cache ({key}): {cache_path}</info>"));
+ io.write_error(&format!(
+ "<info>Garbage-collecting cache ({key}): {cache_path}</info>"
+ ));
if key == "cache-files-dir" {
- cache.gc(config.get("cache-files-ttl"), config.get("cache-files-maxsize"))?;
+ cache.gc(
+ config.get("cache-files-ttl"),
+ config.get("cache-files-maxsize"),
+ )?;
} else if key == "cache-repo-dir" {
cache.gc(config.get("cache-ttl"), 1024 * 1024 * 1024)?;
} else if key == "cache-vcs-dir" {
cache.gc_vcs_cache(config.get("cache-ttl"))?;
}
} else {
- io.write_error(&format!("<info>Clearing cache ({key}): {cache_path}</info>"));
+ io.write_error(&format!(
+ "<info>Clearing cache ({key}): {cache_path}</info>"
+ ));
cache.clear()?;
}
}