aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe/src/advisory/auditor.rs20
-rw-r--r--crates/shirabe/src/advisory/partial_security_advisory.rs5
-rw-r--r--crates/shirabe/src/cache.rs5
-rw-r--r--crates/shirabe/src/command/about_command.rs1
-rw-r--r--crates/shirabe/src/command/archive_command.rs5
-rw-r--r--crates/shirabe/src/command/audit_command.rs3
-rw-r--r--crates/shirabe/src/command/base_command.rs45
-rw-r--r--crates/shirabe/src/command/bump_command.rs5
-rw-r--r--crates/shirabe/src/command/check_platform_reqs_command.rs1
-rw-r--r--crates/shirabe/src/command/clear_cache_command.rs1
-rw-r--r--crates/shirabe/src/command/config_command.rs1
-rw-r--r--crates/shirabe/src/command/create_project_command.rs5
-rw-r--r--crates/shirabe/src/command/depends_command.rs1
-rw-r--r--crates/shirabe/src/command/diagnose_command.rs3
-rw-r--r--crates/shirabe/src/command/dump_autoload_command.rs1
-rw-r--r--crates/shirabe/src/command/exec_command.rs3
-rw-r--r--crates/shirabe/src/command/fund_command.rs3
-rw-r--r--crates/shirabe/src/command/global_command.rs5
-rw-r--r--crates/shirabe/src/command/home_command.rs5
-rw-r--r--crates/shirabe/src/command/init_command.rs21
-rw-r--r--crates/shirabe/src/command/install_command.rs1
-rw-r--r--crates/shirabe/src/command/licenses_command.rs1
-rw-r--r--crates/shirabe/src/command/outdated_command.rs1
-rw-r--r--crates/shirabe/src/command/package_discovery_trait.rs11
-rw-r--r--crates/shirabe/src/command/prohibits_command.rs1
-rw-r--r--crates/shirabe/src/command/reinstall_command.rs1
-rw-r--r--crates/shirabe/src/command/remove_command.rs1
-rw-r--r--crates/shirabe/src/command/repository_command.rs1
-rw-r--r--crates/shirabe/src/command/require_command.rs7
-rw-r--r--crates/shirabe/src/command/run_script_command.rs5
-rw-r--r--crates/shirabe/src/command/script_alias_command.rs7
-rw-r--r--crates/shirabe/src/command/search_command.rs1
-rw-r--r--crates/shirabe/src/command/self_update_command.rs1
-rw-r--r--crates/shirabe/src/command/show_command.rs1
-rw-r--r--crates/shirabe/src/command/status_command.rs3
-rw-r--r--crates/shirabe/src/command/suggests_command.rs3
-rw-r--r--crates/shirabe/src/command/update_command.rs8
-rw-r--r--crates/shirabe/src/command/validate_command.rs1
-rw-r--r--crates/shirabe/src/config.rs11
-rw-r--r--crates/shirabe/src/config/json_config_source.rs27
-rw-r--r--crates/shirabe/src/console/input/input_argument.rs3
-rw-r--r--crates/shirabe/src/console/input/input_option.rs3
-rw-r--r--crates/shirabe/src/dependency_resolver/generic_rule.rs3
-rw-r--r--crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs9
-rw-r--r--crates/shirabe/src/dependency_resolver/rule.rs7
-rw-r--r--crates/shirabe/src/downloader/archive_downloader.rs13
-rw-r--r--crates/shirabe/src/downloader/change_report_interface.rs3
-rw-r--r--crates/shirabe/src/downloader/download_manager.rs49
-rw-r--r--crates/shirabe/src/downloader/dvcs_downloader_interface.rs3
-rw-r--r--crates/shirabe/src/downloader/file_downloader.rs29
-rw-r--r--crates/shirabe/src/downloader/fossil_downloader.rs25
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs33
-rw-r--r--crates/shirabe/src/downloader/gzip_downloader.rs17
-rw-r--r--crates/shirabe/src/downloader/hg_downloader.rs23
-rw-r--r--crates/shirabe/src/downloader/path_downloader.rs19
-rw-r--r--crates/shirabe/src/downloader/perforce_downloader.rs23
-rw-r--r--crates/shirabe/src/downloader/phar_downloader.rs17
-rw-r--r--crates/shirabe/src/downloader/rar_downloader.rs17
-rw-r--r--crates/shirabe/src/downloader/tar_downloader.rs17
-rw-r--r--crates/shirabe/src/downloader/vcs_downloader.rs31
-rw-r--r--crates/shirabe/src/downloader/xz_downloader.rs18
-rw-r--r--crates/shirabe/src/downloader/zip_downloader.rs25
-rw-r--r--crates/shirabe/src/filter/platform_requirement_filter/platform_requirement_filter_factory.rs3
-rw-r--r--crates/shirabe/src/installed_versions.rs13
-rw-r--r--crates/shirabe/src/installer/installation_manager.rs61
-rw-r--r--crates/shirabe/src/installer/library_installer.rs19
-rw-r--r--crates/shirabe/src/installer/metapackage_installer.rs13
-rw-r--r--crates/shirabe/src/installer/plugin_installer.rs15
-rw-r--r--crates/shirabe/src/io/buffer_io.rs7
-rw-r--r--crates/shirabe/src/json/json_file.rs33
-rw-r--r--crates/shirabe/src/package/loader/array_loader.rs20
-rw-r--r--crates/shirabe/src/package/loader/json_loader.rs3
-rw-r--r--crates/shirabe/src/package/locker.rs108
-rw-r--r--crates/shirabe/src/package/version/version_bumper.rs3
-rw-r--r--crates/shirabe/src/package/version/version_guesser.rs27
-rw-r--r--crates/shirabe/src/platform/runtime.rs9
-rw-r--r--crates/shirabe/src/repository/array_repository.rs5
-rw-r--r--crates/shirabe/src/repository/filesystem_repository.rs38
-rw-r--r--crates/shirabe/src/repository/filter_repository.rs3
-rw-r--r--crates/shirabe/src/repository/installed_filesystem_repository.rs5
-rw-r--r--crates/shirabe/src/repository/repository_set.rs19
-rw-r--r--crates/shirabe/src/repository/vcs/forgejo_driver.rs23
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs32
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs32
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs37
-rw-r--r--crates/shirabe/src/repository/vcs/svn_driver.rs24
-rw-r--r--crates/shirabe/src/repository/vcs_repository.rs13
-rw-r--r--crates/shirabe/src/repository/writable_array_repository.rs29
-rw-r--r--crates/shirabe/src/repository/writable_repository_interface.rs11
-rw-r--r--crates/shirabe/src/self_update/keys.rs3
-rw-r--r--crates/shirabe/src/util/auth_helper.rs7
-rw-r--r--crates/shirabe/src/util/forgejo_url.rs3
-rw-r--r--crates/shirabe/src/util/git.rs21
-rw-r--r--crates/shirabe/src/util/hg.rs5
-rw-r--r--crates/shirabe/src/util/http_downloader.rs29
-rw-r--r--crates/shirabe/src/util/loop.rs7
-rw-r--r--crates/shirabe/src/util/no_proxy_pattern.rs22
-rw-r--r--crates/shirabe/src/util/perforce.rs35
-rw-r--r--crates/shirabe/src/util/platform.rs7
-rw-r--r--crates/shirabe/src/util/process_executor.rs46
-rw-r--r--crates/shirabe/src/util/silencer.rs5
-rw-r--r--crates/shirabe/src/util/svn.rs13
-rw-r--r--crates/shirabe/src/util/sync_helper.rs21
-rw-r--r--crates/shirabe/src/util/tar.rs5
-rw-r--r--crates/shirabe/src/util/zip.rs5
-rwxr-xr-xscripts/lint1
-rw-r--r--scripts/linters/no_banned_use.rb112
107 files changed, 859 insertions, 712 deletions
diff --git a/crates/shirabe/src/advisory/auditor.rs b/crates/shirabe/src/advisory/auditor.rs
index be78f4b..662a940 100644
--- a/crates/shirabe/src/advisory/auditor.rs
+++ b/crates/shirabe/src/advisory/auditor.rs
@@ -10,7 +10,6 @@ use crate::package::PackageInterfaceHandle;
use crate::package::base_package;
use crate::repository::RepositorySet;
use crate::util::PackageInfo;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::console::formatter::OutputFormatter;
@@ -37,7 +36,10 @@ struct AuditJsonReport<'a> {
/// PHP `json_encode` emits an empty associative array as `[]`, not `{}`. Mirror that so an empty
/// map serializes as an empty JSON array.
-fn serialize_php_array<S, V>(map: &IndexMap<String, V>, serializer: S) -> Result<S::Ok, S::Error>
+fn serialize_php_array<S, V>(
+ map: &IndexMap<String, V>,
+ serializer: S,
+) -> anyhow::Result<S::Ok, S::Error>
where
S: serde::Serializer,
V: serde::Serialize,
@@ -54,7 +56,7 @@ where
fn serialize_advisories_field<S>(
map: &&IndexMap<String, Vec<AnySecurityAdvisory>>,
serializer: S,
-) -> Result<S::Ok, S::Error>
+) -> anyhow::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
@@ -64,7 +66,7 @@ where
fn serialize_abandoned_field<S>(
map: &IndexMap<String, Option<String>>,
serializer: S,
-) -> Result<S::Ok, S::Error>
+) -> anyhow::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
@@ -120,7 +122,7 @@ impl Auditor {
ignored_severities: IndexMap<String, Option<String>>,
ignore_unreachable: bool,
ignore_abandoned: IndexMap<String, Option<String>>,
- ) -> Result<i64> {
+ ) -> anyhow::Result<i64> {
let result = repo_set.get_matching_security_advisories(
packages.clone(),
format == Self::FORMAT_SUMMARY,
@@ -426,7 +428,7 @@ impl Auditor {
io: &mut dyn IOInterface,
advisories: &IndexMap<String, Vec<AnySecurityAdvisory>>,
format: &str,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
match format {
Self::FORMAT_TABLE => {
let io_as_console = io.as_any().downcast_ref::<ConsoleIO>();
@@ -463,7 +465,7 @@ impl Auditor {
&self,
io: &ConsoleIO,
advisories: &IndexMap<String, Vec<AnySecurityAdvisory>>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
for package_advisories in advisories.values() {
for advisory in package_advisories {
let mut headers: Vec<String> = vec![
@@ -524,7 +526,7 @@ impl Auditor {
&self,
io: &mut dyn IOInterface,
advisories: &IndexMap<String, Vec<AnySecurityAdvisory>>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let mut error: Vec<String> = vec![];
let mut first_advisory = true;
for package_advisories in advisories.values() {
@@ -572,7 +574,7 @@ impl Auditor {
io: &mut dyn IOInterface,
packages: &[CompletePackageInterfaceHandle],
format: &str,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
io.write_error(&format!(
"<error>Found {} abandoned package{}:</error>",
packages.len() as i64,
diff --git a/crates/shirabe/src/advisory/partial_security_advisory.rs b/crates/shirabe/src/advisory/partial_security_advisory.rs
index 11b95bd..148bef4 100644
--- a/crates/shirabe/src/advisory/partial_security_advisory.rs
+++ b/crates/shirabe/src/advisory/partial_security_advisory.rs
@@ -3,7 +3,6 @@
use crate::advisory::AnySecurityAdvisory;
use crate::advisory::SecurityAdvisory;
use crate::package::version::VersionParser;
-use anyhow::Result;
use chrono::{DateTime, Utc};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
@@ -14,7 +13,7 @@ use shirabe_semver::constraint::SimpleConstraint;
fn serialize_constraint<S: serde::Serializer>(
c: &AnyConstraint,
serializer: S,
-) -> Result<S::Ok, S::Error> {
+) -> anyhow::Result<S::Ok, S::Error> {
serializer.serialize_str(&c.get_pretty_string())
}
@@ -32,7 +31,7 @@ impl PartialSecurityAdvisory {
package_name: &str,
data: &IndexMap<String, PhpMixed>,
parser: &VersionParser,
- ) -> Result<AnySecurityAdvisory> {
+ ) -> anyhow::Result<AnySecurityAdvisory> {
let affected_versions_str = data["affectedVersions"].as_string().unwrap_or("");
let constraint: AnyConstraint = match parser.parse_constraints(affected_versions_str) {
diff --git a/crates/shirabe/src/cache.rs b/crates/shirabe/src/cache.rs
index b2e2f3f..87f6ea4 100644
--- a/crates/shirabe/src/cache.rs
+++ b/crates/shirabe/src/cache.rs
@@ -5,7 +5,6 @@ use crate::io::IOInterfaceImmutable;
use crate::util::Filesystem;
use crate::util::Platform;
use crate::util::Silencer;
-use anyhow::Result;
use chrono::Utc;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::finder::Finder;
@@ -138,7 +137,7 @@ impl Cache {
None
}
- pub fn write(&mut self, file: &str, contents: &str) -> Result<bool> {
+ pub fn write(&mut self, file: &str, contents: &str) -> anyhow::Result<bool> {
let was_enabled = self.enabled == Some(true);
if self.is_enabled() && !self.read_only {
@@ -241,7 +240,7 @@ impl Cache {
}
/// Copy a file out of the cache
- pub fn copy_to(&mut self, file: &str, target: &str) -> Result<bool> {
+ pub fn copy_to(&mut self, file: &str, target: &str) -> anyhow::Result<bool> {
if self.is_enabled() {
let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file);
let full_path = format!("{}{}", self.root, file);
diff --git a/crates/shirabe/src/command/about_command.rs b/crates/shirabe/src/command/about_command.rs
index 94c877a..7983a58 100644
--- a/crates/shirabe/src/command/about_command.rs
+++ b/crates/shirabe/src/command/about_command.rs
@@ -4,7 +4,6 @@ use crate::command::BaseCommand;
use crate::command::BaseCommandData;
use crate::command::base_command::base_command_initialize;
use crate::composer;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
diff --git a/crates/shirabe/src/command/archive_command.rs b/crates/shirabe/src/command/archive_command.rs
index ce1d496..741847a 100644
--- a/crates/shirabe/src/command/archive_command.rs
+++ b/crates/shirabe/src/command/archive_command.rs
@@ -22,7 +22,6 @@ use crate::util::Filesystem;
use crate::util::Platform;
use crate::util::ProcessExecutor;
use crate::util::r#loop::Loop;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::console::command::command::Command;
@@ -260,7 +259,7 @@ impl ArchiveCommand {
file_name: Option<String>,
ignore_filters: bool,
composer: Option<&PartialComposerHandle>,
- ) -> Result<i64> {
+ ) -> anyhow::Result<i64> {
let archive_stub_return = self.test_hooks.borrow().archive_stub_return;
if let Some(return_value) = archive_stub_return {
self.test_hooks
@@ -352,7 +351,7 @@ impl ArchiveCommand {
io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
package_name: &str,
version: Option<&str>,
- ) -> Result<Option<crate::package::CompletePackageInterfaceHandle>> {
+ ) -> anyhow::Result<Option<crate::package::CompletePackageInterfaceHandle>> {
io.write_error("<info>Searching for the specified package.</info>");
let mut version = version.map(|v| v.to_string());
diff --git a/crates/shirabe/src/command/audit_command.rs b/crates/shirabe/src/command/audit_command.rs
index 59d11a6..24af44c 100644
--- a/crates/shirabe/src/command/audit_command.rs
+++ b/crates/shirabe/src/command/audit_command.rs
@@ -11,7 +11,6 @@ use crate::io::IOInterfaceImmutable;
use crate::repository::CanonicalPackagesTrait;
use crate::repository::RepositorySet;
use crate::repository::RepositoryUtils;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
@@ -243,7 +242,7 @@ impl AuditCommand {
&self,
composer: &PartialComposerHandle,
input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
- ) -> Result<Vec<crate::package::PackageInterfaceHandle>> {
+ ) -> anyhow::Result<Vec<crate::package::PackageInterfaceHandle>> {
let composer = crate::composer::composer_full(composer);
if input
.borrow()
diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs
index 46ee5f7..25618c5 100644
--- a/crates/shirabe/src/command/base_command.rs
+++ b/crates/shirabe/src/command/base_command.rs
@@ -17,7 +17,6 @@ use crate::package::version::VersionParser;
use crate::plugin::PluginEvents;
use crate::plugin::PreCommandRunEvent;
use crate::util::Platform;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::console::Terminal;
use shirabe_external_packages::symfony::console::command::command::{
@@ -139,7 +138,7 @@ pub trait BaseCommand: Command {
&self,
disable_plugins: Option<bool>,
disable_scripts: Option<bool>,
- ) -> Result<PartialComposerHandle>;
+ ) -> anyhow::Result<PartialComposerHandle>;
/// Retrieves the default Composer\Composer instance or null
fn try_composer(
@@ -151,7 +150,7 @@ pub trait BaseCommand: Command {
fn set_composer(&self, composer: PartialComposerHandle);
/// Removes the cached composer instance
- fn reset_composer(&self) -> Result<()>;
+ fn reset_composer(&self) -> anyhow::Result<()>;
fn get_io(&self) -> Rc<RefCell<dyn IOInterface>>;
@@ -165,7 +164,7 @@ pub trait BaseCommand: Command {
config: Option<IndexMap<String, PhpMixed>>,
disable_plugins: bool,
disable_scripts: Option<bool>,
- ) -> Result<PartialComposerHandle>;
+ ) -> anyhow::Result<PartialComposerHandle>;
/// Returns preferSource and preferDist values based on the configuration.
fn get_preferred_install_options(
@@ -173,17 +172,20 @@ pub trait BaseCommand: Command {
config: &Config,
input: Rc<RefCell<dyn InputInterface>>,
keep_vcs_requires_prefer_source: bool,
- ) -> Result<(bool, bool)>;
+ ) -> anyhow::Result<(bool, bool)>;
fn get_platform_requirement_filter(
&self,
input: Rc<RefCell<dyn InputInterface>>,
- ) -> Result<Rc<dyn PlatformRequirementFilterInterface>>;
+ ) -> anyhow::Result<Rc<dyn PlatformRequirementFilterInterface>>;
/// @param array<string> $requirements
///
/// @return array<string, string>
- fn format_requirements(&self, requirements: Vec<String>) -> Result<IndexMap<String, String>>;
+ fn format_requirements(
+ &self,
+ requirements: Vec<String>,
+ ) -> anyhow::Result<IndexMap<String, String>>;
/// @param array<string> $requirements
///
@@ -191,7 +193,7 @@ pub trait BaseCommand: Command {
fn normalize_requirements(
&self,
requirements: Vec<String>,
- ) -> Result<Vec<IndexMap<String, String>>>;
+ ) -> anyhow::Result<Vec<IndexMap<String, String>>>;
/// @param array<TableSeparator|mixed[]> $table
fn render_table(&self, table: Vec<PhpMixed>, output: Rc<RefCell<dyn OutputInterface>>);
@@ -205,14 +207,14 @@ pub trait BaseCommand: Command {
&self,
input: Rc<RefCell<dyn InputInterface>>,
opt_name: &str,
- ) -> Result<String>;
+ ) -> anyhow::Result<String>;
/// Creates an AuditConfig from the Config object, optionally overriding security blocking based on input options
fn create_audit_config(
&self,
config: &mut Config,
input: Rc<RefCell<dyn InputInterface>>,
- ) -> Result<AuditConfig>;
+ ) -> anyhow::Result<AuditConfig>;
}
/// Forwards every Composer-specific `BaseCommand` method that no command overrides to an
@@ -253,7 +255,7 @@ impl BaseCommand for BaseCommandData {
&self,
disable_plugins: Option<bool>,
disable_scripts: Option<bool>,
- ) -> Result<PartialComposerHandle> {
+ ) -> anyhow::Result<PartialComposerHandle> {
if self.composer.borrow().is_none() {
let application = self.get_application();
let Some(application) = application else {
@@ -311,7 +313,7 @@ impl BaseCommand for BaseCommandData {
*self.composer.borrow_mut() = Some(composer);
}
- fn reset_composer(&self) -> Result<()> {
+ fn reset_composer(&self) -> anyhow::Result<()> {
*self.composer.borrow_mut() = None;
if let Some(application) = self.get_application() {
let mut app_ref = application.borrow_mut();
@@ -360,7 +362,7 @@ impl BaseCommand for BaseCommandData {
config: Option<IndexMap<String, PhpMixed>>,
disable_plugins: bool,
disable_scripts: Option<bool>,
- ) -> Result<PartialComposerHandle> {
+ ) -> anyhow::Result<PartialComposerHandle> {
let disable_plugins = disable_plugins
|| input
.borrow()
@@ -388,7 +390,7 @@ impl BaseCommand for BaseCommandData {
config: &Config,
input: Rc<RefCell<dyn InputInterface>>,
keep_vcs_requires_prefer_source: bool,
- ) -> Result<(bool, bool)> {
+ ) -> anyhow::Result<(bool, bool)> {
let mut prefer_source = false;
let mut prefer_dist = false;
@@ -510,7 +512,7 @@ impl BaseCommand for BaseCommandData {
fn get_platform_requirement_filter(
&self,
input: Rc<RefCell<dyn InputInterface>>,
- ) -> Result<Rc<dyn PlatformRequirementFilterInterface>> {
+ ) -> anyhow::Result<Rc<dyn PlatformRequirementFilterInterface>> {
if !input.borrow().has_option("ignore-platform-reqs")
|| !input.borrow().has_option("ignore-platform-req")
{
@@ -540,7 +542,10 @@ impl BaseCommand for BaseCommandData {
Ok(PlatformRequirementFilterFactory::ignore_nothing())
}
- fn format_requirements(&self, requirements: Vec<String>) -> Result<IndexMap<String, String>> {
+ fn format_requirements(
+ &self,
+ requirements: Vec<String>,
+ ) -> anyhow::Result<IndexMap<String, String>> {
let mut requires: IndexMap<String, String> = IndexMap::new();
let requirements = self.normalize_requirements(requirements)?;
for requirement in requirements {
@@ -567,7 +572,7 @@ impl BaseCommand for BaseCommandData {
fn normalize_requirements(
&self,
requirements: Vec<String>,
- ) -> Result<Vec<IndexMap<String, String>>> {
+ ) -> anyhow::Result<Vec<IndexMap<String, String>>> {
let parser: VersionParser = VersionParser::new();
parser.parse_name_version_pairs(requirements)
@@ -602,7 +607,7 @@ impl BaseCommand for BaseCommandData {
&self,
input: Rc<RefCell<dyn InputInterface>>,
opt_name: &str,
- ) -> Result<String> {
+ ) -> anyhow::Result<String> {
if !input.borrow().has_option(opt_name) {
return Err(LogicException {
message: format!(
@@ -638,7 +643,7 @@ impl BaseCommand for BaseCommandData {
&self,
config: &mut Config,
input: Rc<RefCell<dyn InputInterface>>,
- ) -> Result<AuditConfig> {
+ ) -> anyhow::Result<AuditConfig> {
// Handle both --audit and --no-audit flags
let audit = if input.borrow().has_option("audit") {
input
@@ -700,7 +705,7 @@ pub fn base_command_initialize(
cmd: &dyn BaseCommand,
input: Rc<RefCell<dyn InputInterface>>,
_output: Rc<RefCell<dyn OutputInterface>>,
-) -> Result<()> {
+) -> anyhow::Result<()> {
// initialize a plugin-enabled Composer instance, either local or global
// PHP also ORs in $this->getApplication()->getDisablePluginsByDefault() /
// getDisableScriptsByDefault().
diff --git a/crates/shirabe/src/command/bump_command.rs b/crates/shirabe/src/command/bump_command.rs
index 79fedfb..e3dac8a 100644
--- a/crates/shirabe/src/command/bump_command.rs
+++ b/crates/shirabe/src/command/bump_command.rs
@@ -15,7 +15,6 @@ use crate::package::version::VersionBumper;
use crate::repository::PlatformRepository;
use crate::util::Filesystem;
use crate::util::Silencer;
-use anyhow::Result;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
@@ -57,7 +56,7 @@ impl BumpCommand {
dry_run: bool,
packages_filter: Vec<String>,
dev_only_flag_hint: String,
- ) -> Result<i64> {
+ ) -> anyhow::Result<i64> {
let composer_json_path = Factory::get_composer_file()?;
if !Filesystem::is_readable(&composer_json_path) {
@@ -298,7 +297,7 @@ impl BumpCommand {
&self,
json: &JsonFile,
updates: &indexmap::IndexMap<&str, indexmap::IndexMap<String, String>>,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
let contents = match file_get_contents(json.get_path()) {
Some(c) => c,
None => {
diff --git a/crates/shirabe/src/command/check_platform_reqs_command.rs b/crates/shirabe/src/command/check_platform_reqs_command.rs
index 4b4e043..4f53e79 100644
--- a/crates/shirabe/src/command/check_platform_reqs_command.rs
+++ b/crates/shirabe/src/command/check_platform_reqs_command.rs
@@ -10,7 +10,6 @@ use crate::repository::InstalledRepository;
use crate::repository::PlatformRepository;
use crate::repository::RepositoryInterface;
use crate::repository::RootPackageRepository;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
diff --git a/crates/shirabe/src/command/clear_cache_command.rs b/crates/shirabe/src/command/clear_cache_command.rs
index 696b1dc..2e41412 100644
--- a/crates/shirabe/src/command/clear_cache_command.rs
+++ b/crates/shirabe/src/command/clear_cache_command.rs
@@ -8,7 +8,6 @@ use crate::config::Config;
use crate::console::input::InputOption;
use crate::factory::Factory;
use crate::io::IOInterfaceImmutable;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index e1ebf1a..6c2e777 100644
--- a/crates/shirabe/src/command/config_command.rs
+++ b/crates/shirabe/src/command/config_command.rs
@@ -16,7 +16,6 @@ use crate::package::base_package::{self};
use crate::util::Filesystem;
use crate::util::Platform;
use crate::util::Silencer;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::console::command::command::Command;
diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs
index 8f01f98..e63502a 100644
--- a/crates/shirabe/src/command/create_project_command.rs
+++ b/crates/shirabe/src/command/create_project_command.rs
@@ -32,7 +32,6 @@ use crate::script::ScriptEvents;
use crate::util::Filesystem;
use crate::util::Platform;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::seld::signal::SignalHandler;
@@ -302,7 +301,7 @@ impl CreateProjectCommand {
platform_requirement_filter: Option<std::rc::Rc<dyn PlatformRequirementFilterInterface>>,
secure_http: bool,
add_repository: bool,
- ) -> Result<i64> {
+ ) -> anyhow::Result<i64> {
let old_cwd = Platform::get_cwd(false)?;
let repositories: Option<Vec<String>> = match repositories {
@@ -648,7 +647,7 @@ impl CreateProjectCommand {
disable_scripts: bool,
no_progress: bool,
secure_http: bool,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
let parser: VersionParser = VersionParser::new();
let requirements = parser.parse_name_version_pairs(vec![package_name.to_string()])?;
let name = strtolower(
diff --git a/crates/shirabe/src/command/depends_command.rs b/crates/shirabe/src/command/depends_command.rs
index 39e916a..00b5abc 100644
--- a/crates/shirabe/src/command/depends_command.rs
+++ b/crates/shirabe/src/command/depends_command.rs
@@ -6,7 +6,6 @@ use crate::command::BaseDependencyCommand;
use crate::command::base_command::base_command_initialize;
use crate::console::input::InputArgument;
use crate::console::input::InputOption;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs
index 656f730..a465182 100644
--- a/crates/shirabe/src/command/diagnose_command.rs
+++ b/crates/shirabe/src/command/diagnose_command.rs
@@ -32,7 +32,6 @@ use crate::util::Platform;
use crate::util::ProcessExecutor;
use crate::util::http::ProxyManager;
use crate::util::http::RequestProxy;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::composer::xdebug_handler::XdebugHandler;
@@ -347,7 +346,7 @@ impl Command for DiagnoseCommand {
} else {
vec!["http", "https"]
};
- let proxy_check_result: Result<(), anyhow::Error> = (|| -> anyhow::Result<()> {
+ let proxy_check_result: anyhow::Result<(), anyhow::Error> = (|| -> anyhow::Result<()> {
for proto in &protos {
let proxy = proxy_manager
.lock()
diff --git a/crates/shirabe/src/command/dump_autoload_command.rs b/crates/shirabe/src/command/dump_autoload_command.rs
index baae79d..de917b5 100644
--- a/crates/shirabe/src/command/dump_autoload_command.rs
+++ b/crates/shirabe/src/command/dump_autoload_command.rs
@@ -7,7 +7,6 @@ use crate::console::input::InputOption;
use crate::io::IOInterfaceImmutable;
use crate::plugin::CommandEvent;
use crate::plugin::PluginEvents;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
diff --git a/crates/shirabe/src/command/exec_command.rs b/crates/shirabe/src/command/exec_command.rs
index 8b7d5f7..a394ac4 100644
--- a/crates/shirabe/src/command/exec_command.rs
+++ b/crates/shirabe/src/command/exec_command.rs
@@ -6,7 +6,6 @@ use crate::command::base_command::base_command_initialize;
use crate::console::input::InputArgument;
use crate::console::input::InputOption;
use crate::io::IOInterfaceImmutable;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
@@ -36,7 +35,7 @@ impl ExecCommand {
command
}
- fn get_binaries(&self, for_display: bool) -> Result<Vec<String>> {
+ fn get_binaries(&self, for_display: bool) -> anyhow::Result<Vec<String>> {
let composer = self.require_composer(None, None)?;
let composer_ref = crate::composer::composer_full(&composer);
let bin_dir = composer_ref
diff --git a/crates/shirabe/src/command/fund_command.rs b/crates/shirabe/src/command/fund_command.rs
index ad4f94f..5d1dfea 100644
--- a/crates/shirabe/src/command/fund_command.rs
+++ b/crates/shirabe/src/command/fund_command.rs
@@ -8,7 +8,6 @@ use crate::json::JsonFile;
use crate::package::base_package::{self};
use crate::repository::CompositeRepository;
use crate::repository::RepositoryInterface;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::console::command::command::Command;
@@ -46,7 +45,7 @@ impl FundCommand {
fn insert_funding_data(
fundings: &mut IndexMap<String, IndexMap<String, Vec<String>>>,
package: &crate::package::CompletePackageInterfaceHandle,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let pretty_name = package.get_pretty_name();
let (vendor, package_name) = pretty_name
.split_once('/')
diff --git a/crates/shirabe/src/command/global_command.rs b/crates/shirabe/src/command/global_command.rs
index 04c2409..5769ebb 100644
--- a/crates/shirabe/src/command/global_command.rs
+++ b/crates/shirabe/src/command/global_command.rs
@@ -7,7 +7,6 @@ use crate::console::input::InputArgument;
use crate::factory::Factory;
use crate::util::Filesystem;
use crate::util::Platform;
-use anyhow::Result;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::ArgvInput;
@@ -48,7 +47,7 @@ impl GlobalCommand {
// Mirrors PHP's `method_exists($input, '__toString')` guard followed by
// `$input->__toString()`. `InputInterface` does not declare `__toString`, so the
// concrete stringable input types are matched explicitly.
- fn input_to_string(input: &dyn InputInterface) -> Result<String> {
+ fn input_to_string(input: &dyn InputInterface) -> anyhow::Result<String> {
let input_any = input.as_any();
if let Some(argv_input) = input_any.downcast_ref::<ArgvInput>() {
Ok(argv_input.to_string())
@@ -71,7 +70,7 @@ impl GlobalCommand {
&self,
input: Rc<RefCell<dyn InputInterface>>,
quiet: bool,
- ) -> Result<StringInput> {
+ ) -> anyhow::Result<StringInput> {
if Platform::get_env("COMPOSER").is_some() {
Platform::clear_env("COMPOSER");
}
diff --git a/crates/shirabe/src/command/home_command.rs b/crates/shirabe/src/command/home_command.rs
index 682cb6a..8ff43f3 100644
--- a/crates/shirabe/src/command/home_command.rs
+++ b/crates/shirabe/src/command/home_command.rs
@@ -11,7 +11,6 @@ use crate::repository::RepositoryFactory;
use crate::repository::RootPackageRepository;
use crate::util::Platform;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
@@ -106,7 +105,9 @@ impl HomeCommand {
}
}
- fn initialize_repos(&self) -> Result<Vec<crate::repository::RepositoryInterfaceHandle>> {
+ fn initialize_repos(
+ &self,
+ ) -> anyhow::Result<Vec<crate::repository::RepositoryInterfaceHandle>> {
let composer = self.try_composer(None, None);
if let Some(composer) = composer {
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index dc91069..856cc78 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -17,7 +17,6 @@ use crate::repository::RepositoryFactory;
use crate::util::Filesystem;
use crate::util::ProcessExecutor;
use crate::util::Silencer;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::console::command::command::Command;
@@ -918,7 +917,10 @@ impl BaseCommand for InitCommand {
impl InitCommand {
/// @return array{name: string, email: string|null}
- fn parse_author_string(&self, author: &str) -> Result<IndexMap<String, Option<String>>> {
+ fn parse_author_string(
+ &self,
+ author: &str,
+ ) -> anyhow::Result<IndexMap<String, Option<String>>> {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
r#"/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’\"()]+)(?:\s+<(?P<email>.+?)>)?$/u"#,
@@ -960,7 +962,10 @@ impl InitCommand {
}
/// @return array<int, array{name: string, email?: string}>
- pub(crate) fn format_authors(&self, author: &str) -> Result<Vec<IndexMap<String, PhpMixed>>> {
+ pub(crate) fn format_authors(
+ &self,
+ author: &str,
+ ) -> anyhow::Result<Vec<IndexMap<String, PhpMixed>>> {
let parsed = self.parse_author_string(author)?;
let mut author_map: IndexMap<String, PhpMixed> = IndexMap::new();
let name = parsed.get("name").cloned().unwrap_or(None);
@@ -1072,12 +1077,18 @@ impl InitCommand {
}
/// For testing only: invoke the private `parse_author_string`.
- pub fn __parse_author_string(&self, author: &str) -> Result<IndexMap<String, Option<String>>> {
+ pub fn __parse_author_string(
+ &self,
+ author: &str,
+ ) -> anyhow::Result<IndexMap<String, Option<String>>> {
self.parse_author_string(author)
}
/// For testing only: invoke the crate-private `format_authors`.
- pub fn __format_authors(&self, author: &str) -> Result<Vec<IndexMap<String, PhpMixed>>> {
+ pub fn __format_authors(
+ &self,
+ author: &str,
+ ) -> anyhow::Result<Vec<IndexMap<String, PhpMixed>>> {
self.format_authors(author)
}
diff --git a/crates/shirabe/src/command/install_command.rs b/crates/shirabe/src/command/install_command.rs
index 2f782cc..1192968 100644
--- a/crates/shirabe/src/command/install_command.rs
+++ b/crates/shirabe/src/command/install_command.rs
@@ -11,7 +11,6 @@ use crate::io::IOInterfaceImmutable;
use crate::plugin::CommandEvent;
use crate::plugin::PluginEvents;
use crate::util::HttpDownloader;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
diff --git a/crates/shirabe/src/command/licenses_command.rs b/crates/shirabe/src/command/licenses_command.rs
index c5cdf2a..52f7d2f 100644
--- a/crates/shirabe/src/command/licenses_command.rs
+++ b/crates/shirabe/src/command/licenses_command.rs
@@ -11,7 +11,6 @@ use crate::repository::RepositoryInterface;
use crate::repository::RepositoryUtils;
use crate::util::PackageInfo;
use crate::util::PackageSorter;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::formatter::OutputFormatter;
diff --git a/crates/shirabe/src/command/outdated_command.rs b/crates/shirabe/src/command/outdated_command.rs
index be921e1..73f191d 100644
--- a/crates/shirabe/src/command/outdated_command.rs
+++ b/crates/shirabe/src/command/outdated_command.rs
@@ -5,7 +5,6 @@ use crate::command::BaseCommandData;
use crate::command::base_command::base_command_initialize;
use crate::console::input::InputArgument;
use crate::console::input::InputOption;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::ArrayInput;
diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs
index c3f744c..475b67d 100644
--- a/crates/shirabe/src/command/package_discovery_trait.rs
+++ b/crates/shirabe/src/command/package_discovery_trait.rs
@@ -17,7 +17,6 @@ use crate::repository::RepositoryFactory;
use crate::repository::RepositorySet;
use crate::repository::{RepositoryInterface, SearchResult};
use crate::util::Filesystem;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::console::input::InputInterface;
@@ -104,7 +103,7 @@ pub trait PackageDiscoveryTrait: BaseCommand {
&input
.borrow()
.get_option("stability")
- .expect("get_minimum_stability returns String, not Result; stability option is guaranteed present by the has_option guard above")
+ .expect("get_minimum_stability returns String, not anyhow::Result; stability option is guaranteed present by the has_option guard above")
.as_string()
.map(|s| s.to_string())
.unwrap_or_else(|| "stable".to_string()),
@@ -139,7 +138,7 @@ pub trait PackageDiscoveryTrait: BaseCommand {
preferred_stability: &str,
use_best_version_constraint: bool,
fixed: bool,
- ) -> Result<Vec<String>> {
+ ) -> anyhow::Result<Vec<String>> {
if !requires.is_empty() {
let requires_norm = self.normalize_requirements(requires.clone())?;
let mut result: Vec<String> = vec![];
@@ -462,7 +461,7 @@ pub trait PackageDiscoveryTrait: BaseCommand {
platform_repo: Option<&PlatformRepositoryHandle>,
preferred_stability: &str,
fixed: bool,
- ) -> Result<(String, String)> {
+ ) -> anyhow::Result<(String, String)> {
// handle ignore-platform-reqs flag if present
let platform_requirement_filter = if input.borrow().has_option("ignore-platform-reqs")
&& input.borrow().has_option("ignore-platform-req")
@@ -751,8 +750,8 @@ pub trait PackageDiscoveryTrait: BaseCommand {
}
/// @return array<string>
- fn find_similar(&self, package: &str) -> Result<Vec<String>> {
- let results: Vec<SearchResult> = match (|| -> Result<Vec<SearchResult>> {
+ fn find_similar(&self, package: &str) -> anyhow::Result<Vec<String>> {
+ let results: Vec<SearchResult> = match (|| -> anyhow::Result<Vec<SearchResult>> {
if self.get_repos_mut().is_none() {
return Err(LogicException {
message: "findSimilar was called before $this->repos was initialized"
diff --git a/crates/shirabe/src/command/prohibits_command.rs b/crates/shirabe/src/command/prohibits_command.rs
index 2423dc7..9f9b0ee 100644
--- a/crates/shirabe/src/command/prohibits_command.rs
+++ b/crates/shirabe/src/command/prohibits_command.rs
@@ -5,7 +5,6 @@ use crate::command::base_command::base_command_initialize;
use crate::command::{BaseCommand, BaseCommandData};
use crate::console::input::InputArgument;
use crate::console::input::InputOption;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
diff --git a/crates/shirabe/src/command/reinstall_command.rs b/crates/shirabe/src/command/reinstall_command.rs
index 2cafbc3..3fddf1f 100644
--- a/crates/shirabe/src/command/reinstall_command.rs
+++ b/crates/shirabe/src/command/reinstall_command.rs
@@ -14,7 +14,6 @@ use crate::plugin::CommandEvent;
use crate::plugin::PluginEvents;
use crate::script::ScriptEvents;
use crate::util::Platform;
-use anyhow::Result;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
diff --git a/crates/shirabe/src/command/remove_command.rs b/crates/shirabe/src/command/remove_command.rs
index 7422151..aa8f772 100644
--- a/crates/shirabe/src/command/remove_command.rs
+++ b/crates/shirabe/src/command/remove_command.rs
@@ -14,7 +14,6 @@ use crate::io::IOInterfaceImmutable;
use crate::json::JsonFile;
use crate::package::base_package;
use crate::repository::RepositoryInterface;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::console::command::command::Command;
diff --git a/crates/shirabe/src/command/repository_command.rs b/crates/shirabe/src/command/repository_command.rs
index ba0778c..89fb84b 100644
--- a/crates/shirabe/src/command/repository_command.rs
+++ b/crates/shirabe/src/command/repository_command.rs
@@ -9,7 +9,6 @@ use crate::console::input::InputArgument;
use crate::console::input::InputOption;
use crate::io::IOInterfaceImmutable;
use crate::json::JsonFile;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::console::command::command::Command;
diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs
index ebd090a..6a3ff5e 100644
--- a/crates/shirabe/src/command/require_command.rs
+++ b/crates/shirabe/src/command/require_command.rs
@@ -29,7 +29,6 @@ use crate::repository::RepositorySet;
use crate::util::Filesystem;
use crate::util::PackageSorter;
use crate::util::Silencer;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::seld::signal::SignalHandler;
@@ -163,7 +162,7 @@ impl Command for RequireCommand {
&self,
input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
- ) -> Result<i64> {
+ ) -> anyhow::Result<i64> {
*self.file.borrow_mut() = Factory::get_composer_file()?;
if input
@@ -748,7 +747,7 @@ impl RequireCommand {
requirements: &IndexMap<String, String>,
require_key: &str,
_remove_key: &str,
- ) -> Result<i64> {
+ ) -> anyhow::Result<i64> {
// Update packages
self.reset_composer()?;
let composer_handle = self.require_composer(None, None)?;
@@ -1053,7 +1052,7 @@ impl RequireCommand {
sort_packages: bool,
dry_run: bool,
fixed: bool,
- ) -> Result<i64> {
+ ) -> anyhow::Result<i64> {
let composer = self.require_composer(None, None)?;
let composer = crate::composer::composer_full(&composer);
let locker_is_locked = composer.get_locker().borrow_mut().is_locked();
diff --git a/crates/shirabe/src/command/run_script_command.rs b/crates/shirabe/src/command/run_script_command.rs
index 869d97b..fdfc4c0 100644
--- a/crates/shirabe/src/command/run_script_command.rs
+++ b/crates/shirabe/src/command/run_script_command.rs
@@ -10,7 +10,6 @@ use crate::script::Event as ScriptEvent;
use crate::script::ScriptEvents;
use crate::util::Platform;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
@@ -58,7 +57,7 @@ impl RunScriptCommand {
command
}
- fn list_scripts(&self, output: Rc<RefCell<dyn OutputInterface>>) -> Result<i64> {
+ fn list_scripts(&self, output: Rc<RefCell<dyn OutputInterface>>) -> anyhow::Result<i64> {
let scripts = self.get_scripts()?;
if scripts.is_empty() {
return Ok(0);
@@ -81,7 +80,7 @@ impl RunScriptCommand {
Ok(0)
}
- fn get_scripts(&self) -> Result<Vec<(String, String)>> {
+ fn get_scripts(&self) -> anyhow::Result<Vec<(String, String)>> {
let composer = self.require_composer(None, None)?;
let scripts = crate::composer::composer_full(&composer)
.get_package()
diff --git a/crates/shirabe/src/command/script_alias_command.rs b/crates/shirabe/src/command/script_alias_command.rs
index 20e2901..ff1fd3d 100644
--- a/crates/shirabe/src/command/script_alias_command.rs
+++ b/crates/shirabe/src/command/script_alias_command.rs
@@ -6,7 +6,6 @@ use crate::command::base_command::base_command_initialize;
use crate::console::input::InputArgument;
use crate::console::input::InputOption;
use crate::util::Platform;
-use anyhow::Result;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
@@ -25,7 +24,11 @@ pub struct ScriptAliasCommand {
}
impl ScriptAliasCommand {
- pub fn new(script: String, description: Option<String>, aliases: Vec<String>) -> Result<Self> {
+ pub fn new(
+ script: String,
+ description: Option<String>,
+ aliases: Vec<String>,
+ ) -> anyhow::Result<Self> {
let description = description
.unwrap_or_else(|| format!("Runs the {} script as defined in composer.json", script));
diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs
index 6f3f4ce..3e85d78 100644
--- a/crates/shirabe/src/command/search_command.rs
+++ b/crates/shirabe/src/command/search_command.rs
@@ -12,7 +12,6 @@ use crate::repository::CompositeRepository;
use crate::repository::PlatformRepository;
use crate::repository::RepositoryInterfaceHandle;
use crate::repository::repository_interface::{self, RepositoryInterface};
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::formatter::OutputFormatter;
diff --git a/crates/shirabe/src/command/self_update_command.rs b/crates/shirabe/src/command/self_update_command.rs
index ca567ce..35a1374 100644
--- a/crates/shirabe/src/command/self_update_command.rs
+++ b/crates/shirabe/src/command/self_update_command.rs
@@ -7,7 +7,6 @@ use crate::console::input::InputArgument;
use crate::console::input::InputOption;
use crate::io::IOInterfaceImmutable;
use crate::io::io_interface;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs
index 4f7403d..68b42e6 100644
--- a/crates/shirabe/src/command/show_command.rs
+++ b/crates/shirabe/src/command/show_command.rs
@@ -32,7 +32,6 @@ use crate::repository::RepositorySet;
use crate::repository::RepositoryUtils;
use crate::repository::RootPackageRepository;
use crate::util::PackageInfo;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::console::command::command::Command;
diff --git a/crates/shirabe/src/command/status_command.rs b/crates/shirabe/src/command/status_command.rs
index bec6868..3b3445b 100644
--- a/crates/shirabe/src/command/status_command.rs
+++ b/crates/shirabe/src/command/status_command.rs
@@ -12,7 +12,6 @@ use crate::plugin::CommandEvent;
use crate::plugin::PluginEvents;
use crate::script::ScriptEvents;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
@@ -49,7 +48,7 @@ impl StatusCommand {
fn do_execute(
&self,
input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
- ) -> Result<i64> {
+ ) -> anyhow::Result<i64> {
let composer = self.require_composer(None, None)?;
let composer = crate::composer::composer_full(&composer);
let io = self.get_io().clone();
diff --git a/crates/shirabe/src/command/suggests_command.rs b/crates/shirabe/src/command/suggests_command.rs
index 25b2e92..f7b0414 100644
--- a/crates/shirabe/src/command/suggests_command.rs
+++ b/crates/shirabe/src/command/suggests_command.rs
@@ -10,7 +10,6 @@ use crate::repository::PlatformRepository;
use crate::repository::RepositoryInterface;
use crate::repository::RepositoryInterfaceHandle;
use crate::repository::RootPackageRepository;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
@@ -112,7 +111,7 @@ impl Command for SuggestsCommand {
&self,
input: Rc<RefCell<dyn InputInterface>>,
_output: Rc<RefCell<dyn OutputInterface>>,
- ) -> Result<i64> {
+ ) -> anyhow::Result<i64> {
let composer = self.require_composer(None, None)?;
let composer = crate::composer::composer_full(&composer);
diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs
index cce4829..366cf8b 100644
--- a/crates/shirabe/src/command/update_command.rs
+++ b/crates/shirabe/src/command/update_command.rs
@@ -23,7 +23,6 @@ use crate::repository::CompositeRepository;
use crate::repository::PlatformRepository;
use crate::repository::RepositorySet;
use crate::util::HttpDownloader;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::console::command::command::Command;
@@ -602,7 +601,7 @@ impl UpdateCommand {
output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
composer: &PartialComposerHandle,
packages: Vec<String>,
- ) -> Result<Vec<String>> {
+ ) -> anyhow::Result<Vec<String>> {
if !input.borrow().is_interactive() {
return Err(InvalidArgumentException {
message: "--interactive cannot be used in non-interactive terminals.".to_string(),
@@ -747,7 +746,10 @@ impl UpdateCommand {
.into())
}
- fn create_version_selector(&self, composer: &PartialComposerHandle) -> Result<VersionSelector> {
+ fn create_version_selector(
+ &self,
+ composer: &PartialComposerHandle,
+ ) -> anyhow::Result<VersionSelector> {
let composer = crate::composer::composer_full(composer);
let root_aliases: Vec<crate::repository::RootAliasInput> = composer
.get_package()
diff --git a/crates/shirabe/src/command/validate_command.rs b/crates/shirabe/src/command/validate_command.rs
index ab88398..bceaa99 100644
--- a/crates/shirabe/src/command/validate_command.rs
+++ b/crates/shirabe/src/command/validate_command.rs
@@ -13,7 +13,6 @@ use crate::plugin::CommandEvent;
use crate::plugin::PluginEvents;
use crate::util::ConfigValidator;
use crate::util::Filesystem;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs
index 7b4ce89..cac6181 100644
--- a/crates/shirabe/src/config.rs
+++ b/crates/shirabe/src/config.rs
@@ -7,7 +7,6 @@ pub use config_source_interface::*;
pub use json_config_source::*;
use crate::io::io_interface;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
@@ -573,7 +572,7 @@ impl Config {
}
/// Typed convenience accessor for keys whose `get()` value is always a string.
- pub fn get_str(&self, key: &str) -> Result<String> {
+ pub fn get_str(&self, key: &str) -> anyhow::Result<String> {
Ok(self
.get_with_flags(key, 0)?
.as_string()
@@ -581,7 +580,7 @@ impl Config {
.to_string())
}
- pub fn get_with_flags(&self, key: &str, flags: i64) -> Result<PhpMixed> {
+ pub fn get_with_flags(&self, key: &str, flags: i64) -> anyhow::Result<PhpMixed> {
match key {
// strings/paths with env var and {$refs} support
"vendor-dir" | "bin-dir" | "process-timeout" | "data-dir" | "cache-dir"
@@ -972,7 +971,7 @@ impl Config {
}
/// @return array<string, mixed[]>
- pub fn all(&mut self, flags: i64) -> Result<IndexMap<String, PhpMixed>> {
+ pub fn all(&mut self, flags: i64) -> anyhow::Result<IndexMap<String, PhpMixed>> {
let mut all: IndexMap<String, PhpMixed> = IndexMap::new();
all.insert(
"repositories".to_string(),
@@ -1040,7 +1039,7 @@ impl Config {
/// @param int $flags Options (see class constants)
///
/// @return string|mixed
- fn process(&self, value: PhpMixed, flags: i64) -> Result<PhpMixed> {
+ fn process(&self, value: PhpMixed, flags: i64) -> anyhow::Result<PhpMixed> {
if !is_string(&value) {
return Ok(value);
}
@@ -1115,7 +1114,7 @@ impl Config {
url: &str,
io: Option<std::rc::Rc<std::cell::RefCell<dyn IOInterface>>>,
repo_options: &IndexMap<String, PhpMixed>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
// Return right away if the URL is malformed or custom (see issue #5173), but only for non-HTTP(S) URLs
if !filter_var_url(url) && !Preg::is_match(r"{^https?://}", url) {
return Ok(());
diff --git a/crates/shirabe/src/config/json_config_source.rs b/crates/shirabe/src/config/json_config_source.rs
index 1b09e54..53e3722 100644
--- a/crates/shirabe/src/config/json_config_source.rs
+++ b/crates/shirabe/src/config/json_config_source.rs
@@ -6,7 +6,6 @@ use crate::json::JsonManipulator;
use crate::json::JsonValidationException;
use crate::util::Filesystem;
use crate::util::Silencer;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{
PHP_EOL, PhpMixed, RuntimeException, chmod, explode, file_get_contents, file_put_contents,
@@ -27,9 +26,9 @@ impl JsonConfigSource {
fn manipulate_json(
&mut self,
- clean: impl FnOnce(&mut JsonManipulator) -> Result<bool>,
- fallback: impl FnOnce(&mut PhpMixed) -> Result<()>,
- ) -> Result<()> {
+ clean: impl FnOnce(&mut JsonManipulator) -> anyhow::Result<bool>,
+ fallback: impl FnOnce(&mut PhpMixed) -> anyhow::Result<()>,
+ ) -> anyhow::Result<()> {
let contents;
if self.file.borrow().exists() {
if !is_writable(self.file.borrow().get_path()) {
@@ -295,7 +294,7 @@ impl ConfigSourceInterface for JsonConfigSource {
self.file.borrow().get_path().to_string()
}
- fn add_repository(&mut self, name: &str, config: PhpMixed, append: bool) -> Result<()> {
+ fn add_repository(&mut self, name: &str, config: PhpMixed, append: bool) -> anyhow::Result<()> {
let config_cloned = config.clone();
self.manipulate_json(
move |m| m.add_repository(name, config_cloned, append),
@@ -368,7 +367,7 @@ impl ConfigSourceInterface for JsonConfigSource {
config: PhpMixed,
reference_name: &str,
offset: i64,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let config_cloned = config.clone();
self.manipulate_json(
move |m| m.insert_repository(name, config_cloned, reference_name, offset),
@@ -435,7 +434,7 @@ impl ConfigSourceInterface for JsonConfigSource {
)
}
- fn set_repository_url(&mut self, name: &str, url: &str) -> Result<()> {
+ fn set_repository_url(&mut self, name: &str, url: &str) -> anyhow::Result<()> {
self.manipulate_json(
move |m| m.set_repository_url(name, url),
move |cfg| {
@@ -476,7 +475,7 @@ impl ConfigSourceInterface for JsonConfigSource {
)
}
- fn remove_repository(&mut self, name: &str) -> Result<()> {
+ fn remove_repository(&mut self, name: &str) -> anyhow::Result<()> {
self.manipulate_json(
move |m| m.remove_repository(name),
move |cfg| {
@@ -507,7 +506,7 @@ impl ConfigSourceInterface for JsonConfigSource {
)
}
- fn add_config_setting(&mut self, name: &str, value: PhpMixed) -> Result<()> {
+ fn add_config_setting(&mut self, name: &str, value: PhpMixed) -> anyhow::Result<()> {
let auth_config = self.auth_config;
let value_cloned = value.clone();
self.manipulate_json(
@@ -546,7 +545,7 @@ impl ConfigSourceInterface for JsonConfigSource {
)
}
- fn remove_config_setting(&mut self, name: &str) -> Result<()> {
+ fn remove_config_setting(&mut self, name: &str) -> anyhow::Result<()> {
let auth_config = self.auth_config;
self.manipulate_json(
// override manipulator method for auth config files
@@ -582,7 +581,7 @@ impl ConfigSourceInterface for JsonConfigSource {
)
}
- fn add_property(&mut self, name: &str, value: PhpMixed) -> Result<()> {
+ fn add_property(&mut self, name: &str, value: PhpMixed) -> anyhow::Result<()> {
let value_cloned = value.clone();
self.manipulate_json(
move |m| m.add_property(name, value_cloned),
@@ -625,7 +624,7 @@ impl ConfigSourceInterface for JsonConfigSource {
)
}
- fn remove_property(&mut self, name: &str) -> Result<()> {
+ fn remove_property(&mut self, name: &str) -> anyhow::Result<()> {
self.manipulate_json(
move |m| m.remove_property(name),
move |cfg| {
@@ -662,7 +661,7 @@ impl ConfigSourceInterface for JsonConfigSource {
)
}
- fn add_link(&mut self, r#type: &str, name: &str, value: &str) -> Result<()> {
+ fn add_link(&mut self, r#type: &str, name: &str, value: &str) -> anyhow::Result<()> {
self.manipulate_json(
move |m| m.add_link(r#type, name, value, false),
move |cfg| {
@@ -675,7 +674,7 @@ impl ConfigSourceInterface for JsonConfigSource {
)
}
- fn remove_link(&mut self, r#type: &str, name: &str) -> Result<()> {
+ fn remove_link(&mut self, r#type: &str, name: &str) -> anyhow::Result<()> {
self.manipulate_json(
move |m| m.remove_sub_node(r#type, name),
move |cfg| {
diff --git a/crates/shirabe/src/console/input/input_argument.rs b/crates/shirabe/src/console/input/input_argument.rs
index 53576dd..5fd9cec 100644
--- a/crates/shirabe/src/console/input/input_argument.rs
+++ b/crates/shirabe/src/console/input/input_argument.rs
@@ -1,6 +1,5 @@
//! ref: composer/src/Composer/Console/Input/InputArgument.php
-use anyhow::Result;
use shirabe_external_packages::symfony::console::input::InputArgument as BaseInputArgument;
use shirabe_php_shim::PhpMixed;
@@ -20,7 +19,7 @@ impl InputArgument {
description: &str,
default: Option<PhpMixed>,
// TODO(cli-completion): suggested_values closure / list dropped along with completion support
- ) -> Result<Self> {
+ ) -> anyhow::Result<Self> {
let inner = BaseInputArgument::new(
name.to_string(),
mode,
diff --git a/crates/shirabe/src/console/input/input_option.rs b/crates/shirabe/src/console/input/input_option.rs
index c7b2af5..938f5a3 100644
--- a/crates/shirabe/src/console/input/input_option.rs
+++ b/crates/shirabe/src/console/input/input_option.rs
@@ -1,6 +1,5 @@
//! ref: composer/src/Composer/Console/Input/InputOption.php
-use anyhow::Result;
use shirabe_external_packages::symfony::console::input::InputOption as BaseInputOption;
use shirabe_php_shim::PhpMixed;
@@ -23,7 +22,7 @@ impl InputOption {
description: &str,
default: Option<PhpMixed>,
// TODO(cli-completion): suggested_values closure / list dropped along with completion support
- ) -> Result<Self> {
+ ) -> anyhow::Result<Self> {
let shortcut = shortcut.unwrap_or(PhpMixed::Null);
let default_mixed = default.unwrap_or(PhpMixed::Null);
let inner =
diff --git a/crates/shirabe/src/dependency_resolver/generic_rule.rs b/crates/shirabe/src/dependency_resolver/generic_rule.rs
index afab376..328a770 100644
--- a/crates/shirabe/src/dependency_resolver/generic_rule.rs
+++ b/crates/shirabe/src/dependency_resolver/generic_rule.rs
@@ -2,7 +2,6 @@
use super::rule::ReasonData;
use crate::dependency_resolver::{Rule, RuleBase};
-use anyhow::Result;
use shirabe_php_shim::{PHP_VERSION_ID, RuntimeException, hash_raw, unpack};
#[derive(Debug)]
@@ -30,7 +29,7 @@ impl GenericRule {
&self.literals
}
- pub fn get_hash(&self) -> Result<i64> {
+ pub fn get_hash(&self) -> anyhow::Result<i64> {
let joined = self
.literals
.iter()
diff --git a/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs b/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs
index 8db0f7f..bfbfc82 100644
--- a/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs
+++ b/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs
@@ -1,7 +1,6 @@
//! ref: composer/src/Composer/DependencyResolver/MultiConflictRule.php
use crate::dependency_resolver::{ReasonData, Rule, RuleBase};
-use anyhow::Result;
use shirabe_php_shim::{PHP_VERSION_ID, RuntimeException, hash_raw};
#[derive(Debug)]
@@ -11,7 +10,11 @@ pub struct MultiConflictRule {
}
impl MultiConflictRule {
- pub fn new(mut literals: Vec<i64>, reason: i64, reason_data: ReasonData) -> Result<Self> {
+ pub fn new(
+ mut literals: Vec<i64>,
+ reason: i64,
+ reason_data: ReasonData,
+ ) -> anyhow::Result<Self> {
if literals.len() < 3 {
return Err(RuntimeException {
message: "multi conflict rule requires at least 3 literals".to_string(),
@@ -41,7 +44,7 @@ impl MultiConflictRule {
&self.literals
}
- pub fn get_hash(&self) -> Result<i64> {
+ pub fn get_hash(&self) -> anyhow::Result<i64> {
let joined = self
.literals
.iter()
diff --git a/crates/shirabe/src/dependency_resolver/rule.rs b/crates/shirabe/src/dependency_resolver/rule.rs
index 958af5a..ab4eeb0 100644
--- a/crates/shirabe/src/dependency_resolver/rule.rs
+++ b/crates/shirabe/src/dependency_resolver/rule.rs
@@ -12,7 +12,6 @@ use crate::package::version::VersionParser;
use crate::repository::PlatformRepository;
use crate::repository::RepositoryInterface;
use crate::repository::RepositorySet;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{
LogicException, PhpMixed, RuntimeException, array_keys, array_shift, implode,
@@ -97,7 +96,7 @@ impl Rule {
}
}
- pub fn get_hash(&self) -> Result<PhpMixed> {
+ pub fn get_hash(&self) -> anyhow::Result<PhpMixed> {
match self {
Rule::Generic(r) => Ok(PhpMixed::Int(r.get_hash()?)),
Rule::MultiConflict(r) => Ok(PhpMixed::Int(r.get_hash()?)),
@@ -170,7 +169,7 @@ impl Rule {
(self.bitfield() & (255 << BITFIELD_TYPE)) >> BITFIELD_TYPE
}
- pub fn disable(&mut self) -> Result<()> {
+ pub fn disable(&mut self) -> anyhow::Result<()> {
if let Rule::MultiConflict(_) = self {
return Err(RuntimeException {
message: "Disabling multi conflict rules is not possible. Please contact composer at https://github.com/composer/composer to let us debug what lead to this situation.".to_string(),
@@ -278,7 +277,7 @@ impl Rule {
}
/// @internal
- pub fn get_source_package(&self, pool: &Pool) -> Result<BasePackageHandle> {
+ pub fn get_source_package(&self, pool: &Pool) -> anyhow::Result<BasePackageHandle> {
let literals = self.get_literals();
match self.get_reason() {
diff --git a/crates/shirabe/src/downloader/archive_downloader.rs b/crates/shirabe/src/downloader/archive_downloader.rs
index 4744bc2..eaa985d 100644
--- a/crates/shirabe/src/downloader/archive_downloader.rs
+++ b/crates/shirabe/src/downloader/archive_downloader.rs
@@ -7,7 +7,6 @@ use crate::io::IOInterfaceImmutable;
use crate::package::PackageInterfaceHandle;
use crate::util::Filesystem;
use crate::util::Platform;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::finder::Finder;
use shirabe_php_shim::{
@@ -27,7 +26,7 @@ pub trait ArchiveDownloader {
package: PackageInterfaceHandle,
file: &str,
path: &str,
- ) -> Result<Option<PhpMixed>>;
+ ) -> anyhow::Result<Option<PhpMixed>>;
async fn prepare(
&mut self,
@@ -35,7 +34,7 @@ pub trait ArchiveDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.cleanup_executed_mut()
.shift_remove(&package.get_name());
self.inner_mut()
@@ -49,7 +48,7 @@ pub trait ArchiveDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.cleanup_executed_mut().insert(package.get_name(), true);
self.inner_mut()
.cleanup(r#type, package, path, prev_package)
@@ -65,7 +64,7 @@ pub trait ArchiveDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if output {
self.inner().io.write_error(&format!(
" - {}{}",
@@ -221,7 +220,7 @@ fn install_cleanup(
package: PackageInterfaceHandle,
path: &str,
temporary_dir: &str,
-) -> Result<()> {
+) -> anyhow::Result<()> {
// remove cache if the file was corrupted
inner.clear_last_cache_write(package.clone());
@@ -265,7 +264,7 @@ fn rename_recursively(
package: PackageInterfaceHandle,
from: &Path,
to: &Path,
-) -> Result<()> {
+) -> anyhow::Result<()> {
let content_dir = get_folder_content(from);
// move files back out of the temp dir
diff --git a/crates/shirabe/src/downloader/change_report_interface.rs b/crates/shirabe/src/downloader/change_report_interface.rs
index ca2a113..ccbea49 100644
--- a/crates/shirabe/src/downloader/change_report_interface.rs
+++ b/crates/shirabe/src/downloader/change_report_interface.rs
@@ -1,12 +1,11 @@
//! ref: composer/src/Composer/Downloader/ChangeReportInterface.php
use crate::package::PackageInterfaceHandle;
-use anyhow::Result;
pub trait ChangeReportInterface {
fn get_local_changes(
&mut self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>>;
+ ) -> anyhow::Result<Option<String>>;
}
diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs
index 82bf4bb..466570e 100644
--- a/crates/shirabe/src/downloader/download_manager.rs
+++ b/crates/shirabe/src/downloader/download_manager.rs
@@ -7,7 +7,6 @@ use crate::io::IOInterfaceImmutable;
use crate::io::io_interface;
use crate::package::PackageInterfaceHandle;
use crate::util::Filesystem;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
@@ -97,7 +96,7 @@ impl DownloadManager {
pub fn get_downloader(
&self,
r#type: &str,
- ) -> Result<std::rc::Rc<std::cell::RefCell<dyn DownloaderInterface>>> {
+ ) -> anyhow::Result<std::rc::Rc<std::cell::RefCell<dyn DownloaderInterface>>> {
let r#type = strtolower(r#type);
if !self.downloaders.contains_key(&r#type) {
return Err(InvalidArgumentException {
@@ -123,7 +122,7 @@ impl DownloadManager {
pub fn get_downloader_for_package(
&self,
package: PackageInterfaceHandle,
- ) -> Result<Option<std::rc::Rc<std::cell::RefCell<dyn DownloaderInterface>>>> {
+ ) -> anyhow::Result<Option<std::rc::Rc<std::cell::RefCell<dyn DownloaderInterface>>>> {
let installation_source = package.get_installation_source();
if "metapackage" == package.get_type() {
@@ -190,7 +189,7 @@ impl DownloadManager {
package: PackageInterfaceHandle,
target_dir: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let target_dir = self.normalize_target_dir(target_dir);
self.filesystem
.borrow_mut()
@@ -278,7 +277,7 @@ impl DownloadManager {
package: PackageInterfaceHandle,
target_dir: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let target_dir = self.normalize_target_dir(target_dir);
if let Some(downloader) = self.get_downloader_for_package(package.clone())? {
return downloader
@@ -302,7 +301,7 @@ impl DownloadManager {
&self,
package: PackageInterfaceHandle,
target_dir: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let target_dir = self.normalize_target_dir(target_dir);
if let Some(downloader) = self.get_downloader_for_package(package.clone())? {
return downloader.borrow_mut().install2(package, &target_dir).await;
@@ -324,7 +323,7 @@ impl DownloadManager {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
target_dir: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let target_dir = self.normalize_target_dir(target_dir);
let downloader = self.get_downloader_for_package(target.clone())?;
let initial_downloader = self.get_downloader_for_package(initial.clone())?;
@@ -404,7 +403,7 @@ impl DownloadManager {
&self,
package: PackageInterfaceHandle,
target_dir: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let target_dir = self.normalize_target_dir(target_dir);
if let Some(downloader) = self.get_downloader_for_package(package.clone())? {
return downloader.borrow_mut().remove2(package, &target_dir).await;
@@ -426,7 +425,7 @@ impl DownloadManager {
package: PackageInterfaceHandle,
target_dir: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let target_dir = self.normalize_target_dir(target_dir);
if let Some(downloader) = self.get_downloader_for_package(package.clone())? {
return downloader
@@ -472,7 +471,7 @@ impl DownloadManager {
&self,
package: PackageInterfaceHandle,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Vec<String>> {
+ ) -> anyhow::Result<Vec<String>> {
let source_type = package.get_source_type();
let dist_type = package.get_dist_type();
@@ -538,7 +537,7 @@ impl DownloadManager {
&self,
package: PackageInterfaceHandle,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Vec<String>> {
+ ) -> anyhow::Result<Vec<String>> {
self.get_available_sources(package, prev_package)
}
@@ -564,43 +563,43 @@ pub trait DownloadManagerInterface: std::fmt::Debug {
fn get_downloader_for_package(
&self,
package: PackageInterfaceHandle,
- ) -> Result<Option<std::rc::Rc<std::cell::RefCell<dyn DownloaderInterface>>>>;
+ ) -> anyhow::Result<Option<std::rc::Rc<std::cell::RefCell<dyn DownloaderInterface>>>>;
async fn download(
&self,
package: PackageInterfaceHandle,
target_dir: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>>;
+ ) -> anyhow::Result<Option<PhpMixed>>;
async fn prepare(
&self,
r#type: &str,
package: PackageInterfaceHandle,
target_dir: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>>;
+ ) -> anyhow::Result<Option<PhpMixed>>;
async fn install(
&self,
package: PackageInterfaceHandle,
target_dir: &str,
- ) -> Result<Option<PhpMixed>>;
+ ) -> anyhow::Result<Option<PhpMixed>>;
async fn update(
&self,
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
target_dir: &str,
- ) -> Result<Option<PhpMixed>>;
+ ) -> anyhow::Result<Option<PhpMixed>>;
async fn remove(
&self,
package: PackageInterfaceHandle,
target_dir: &str,
- ) -> Result<Option<PhpMixed>>;
+ ) -> anyhow::Result<Option<PhpMixed>>;
async fn cleanup(
&self,
r#type: &str,
package: PackageInterfaceHandle,
target_dir: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>>;
+ ) -> anyhow::Result<Option<PhpMixed>>;
}
#[async_trait::async_trait(?Send)]
@@ -616,7 +615,7 @@ impl DownloadManagerInterface for DownloadManager {
fn get_downloader_for_package(
&self,
package: PackageInterfaceHandle,
- ) -> Result<Option<std::rc::Rc<std::cell::RefCell<dyn DownloaderInterface>>>> {
+ ) -> anyhow::Result<Option<std::rc::Rc<std::cell::RefCell<dyn DownloaderInterface>>>> {
self.get_downloader_for_package(package)
}
@@ -625,7 +624,7 @@ impl DownloadManagerInterface for DownloadManager {
package: PackageInterfaceHandle,
target_dir: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.download(package, target_dir, prev_package).await
}
@@ -635,7 +634,7 @@ impl DownloadManagerInterface for DownloadManager {
package: PackageInterfaceHandle,
target_dir: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.prepare(r#type, package, target_dir, prev_package)
.await
}
@@ -644,7 +643,7 @@ impl DownloadManagerInterface for DownloadManager {
&self,
package: PackageInterfaceHandle,
target_dir: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.install(package, target_dir).await
}
@@ -653,7 +652,7 @@ impl DownloadManagerInterface for DownloadManager {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
target_dir: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.update(initial, target, target_dir).await
}
@@ -661,7 +660,7 @@ impl DownloadManagerInterface for DownloadManager {
&self,
package: PackageInterfaceHandle,
target_dir: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.remove(package, target_dir).await
}
@@ -671,7 +670,7 @@ impl DownloadManagerInterface for DownloadManager {
package: PackageInterfaceHandle,
target_dir: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.cleanup(r#type, package, target_dir, prev_package)
.await
}
diff --git a/crates/shirabe/src/downloader/dvcs_downloader_interface.rs b/crates/shirabe/src/downloader/dvcs_downloader_interface.rs
index e33aa46..69756ba 100644
--- a/crates/shirabe/src/downloader/dvcs_downloader_interface.rs
+++ b/crates/shirabe/src/downloader/dvcs_downloader_interface.rs
@@ -1,12 +1,11 @@
//! ref: composer/src/Composer/Downloader/DvcsDownloaderInterface.php
use crate::package::PackageInterfaceHandle;
-use anyhow::Result;
pub trait DvcsDownloaderInterface {
fn get_unpushed_changes(
&self,
package: PackageInterfaceHandle,
path: String,
- ) -> Result<Option<String>>;
+ ) -> anyhow::Result<Option<String>>;
}
diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs
index a6334fb..6286918 100644
--- a/crates/shirabe/src/downloader/file_downloader.rs
+++ b/crates/shirabe/src/downloader/file_downloader.rs
@@ -24,7 +24,6 @@ use crate::util::ProcessExecutor;
use crate::util::Silencer;
use crate::util::Url as UrlUtil;
use crate::util::sync_executor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{
DIRECTORY_SEPARATOR, InvalidArgumentException, PATHINFO_BASENAME, PATHINFO_EXTENSION,
@@ -162,7 +161,7 @@ impl DownloaderInterface for FileDownloader {
path: &str,
_prev_package: Option<PackageInterfaceHandle>,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if package.get_dist_url().is_none() {
return Err(InvalidArgumentException {
message: "The given package is missing url information".to_string(),
@@ -439,7 +438,7 @@ impl DownloaderInterface for FileDownloader {
_package: PackageInterfaceHandle,
_path: &str,
_prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
Ok(Some(PhpMixed::Null))
}
@@ -450,7 +449,7 @@ impl DownloaderInterface for FileDownloader {
package: PackageInterfaceHandle,
path: &str,
_prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let file_name = self.get_file_name(package.clone(), path);
if file_exists(&file_name) {
self.filesystem.borrow_mut().unlink(&file_name)?;
@@ -504,7 +503,7 @@ impl DownloaderInterface for FileDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if output {
self.io.write_error(&format!(
" - {}",
@@ -561,7 +560,7 @@ impl DownloaderInterface for FileDownloader {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.io.write_error(&format!(
" - {}{}",
UpdateOperation::format(initial.clone(), target.clone(), false),
@@ -579,7 +578,7 @@ impl DownloaderInterface for FileDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if output {
self.io.write_error(&format!(
" - {}",
@@ -610,7 +609,7 @@ impl ChangeReportInterface for FileDownloader {
&mut self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
let prev_io = std::mem::replace(
&mut self.io,
std::rc::Rc::new(std::cell::RefCell::new(NullIO::new())),
@@ -623,7 +622,7 @@ impl ChangeReportInterface for FileDownloader {
// PHP attaches an onRejected handler to capture the error and drives the promise via
// httpDownloader->wait() / process->wait(); the single-threaded sync bridge block_on's the
// download/install futures, so a rejection surfaces directly as the Err captured below.
- let result: Result<String> = (|| -> Result<String> {
+ let result: anyhow::Result<String> = (|| -> anyhow::Result<String> {
if is_dir(format!("{}_compare", target_dir)) {
self.filesystem
.borrow_mut()
@@ -773,12 +772,20 @@ impl FileDownloader {
}
/// For testing only: invoke the crate-private `process_url`.
- pub fn __process_url(&self, package: PackageInterfaceHandle, url: &str) -> Result<String> {
+ pub fn __process_url(
+ &self,
+ package: PackageInterfaceHandle,
+ url: &str,
+ ) -> anyhow::Result<String> {
self.process_url(package, url)
}
/// Process the download url
- pub(crate) fn process_url(&self, package: PackageInterfaceHandle, url: &str) -> Result<String> {
+ pub(crate) fn process_url(
+ &self,
+ package: PackageInterfaceHandle,
+ url: &str,
+ ) -> anyhow::Result<String> {
if !shirabe_php_shim::extension_loaded("openssl") && Some(0) == strpos(url, "https:") {
return Err(RuntimeException {
message: "You must enable the openssl extension to download files via https"
diff --git a/crates/shirabe/src/downloader/fossil_downloader.rs b/crates/shirabe/src/downloader/fossil_downloader.rs
index 26a0987..7663c01 100644
--- a/crates/shirabe/src/downloader/fossil_downloader.rs
+++ b/crates/shirabe/src/downloader/fossil_downloader.rs
@@ -11,7 +11,6 @@ use crate::io::IOInterfaceImmutable;
use crate::package::PackageInterfaceHandle;
use crate::util::Filesystem;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{PhpMixed, RuntimeException};
@@ -38,7 +37,7 @@ impl FossilDownloader {
command: Vec<String>,
cwd: Option<String>,
output: &mut String,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
if self
.inner
.process
@@ -91,7 +90,7 @@ impl VcsDownloader for FossilDownloader {
_path: &str,
_url: &str,
_prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
Ok(None)
}
@@ -100,7 +99,7 @@ impl VcsDownloader for FossilDownloader {
package: PackageInterfaceHandle,
path: &str,
url: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.config.borrow_mut().prohibit_url_by_config(
url,
Some(self.inner.io.clone()),
@@ -161,7 +160,7 @@ impl VcsDownloader for FossilDownloader {
target: PackageInterfaceHandle,
path: &str,
url: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.config.borrow_mut().prohibit_url_by_config(
url,
Some(self.inner.io.clone()),
@@ -212,7 +211,7 @@ impl VcsDownloader for FossilDownloader {
_from_reference: &str,
to_reference: &str,
path: &str,
- ) -> Result<String> {
+ ) -> anyhow::Result<String> {
let mut output = String::new();
self.execute(
vec![
@@ -262,7 +261,7 @@ impl ChangeReportInterface for FossilDownloader {
&mut self,
_package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
if !self.has_metadata_repository(path) {
return Ok(None);
}
@@ -314,7 +313,7 @@ impl DownloaderInterface for FossilDownloader {
path: &str,
prev_package: Option<PackageInterfaceHandle>,
_output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::download(self, package, path, prev_package).await
}
@@ -324,7 +323,7 @@ impl DownloaderInterface for FossilDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::prepare(self, r#type, package, path, prev_package).await
}
@@ -333,7 +332,7 @@ impl DownloaderInterface for FossilDownloader {
package: PackageInterfaceHandle,
path: &str,
_output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::install(self, package, path).await
}
@@ -342,7 +341,7 @@ impl DownloaderInterface for FossilDownloader {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::update(self, initial, target, path).await
}
@@ -351,7 +350,7 @@ impl DownloaderInterface for FossilDownloader {
package: PackageInterfaceHandle,
path: &str,
_output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::remove(self, package, path).await
}
@@ -361,7 +360,7 @@ impl DownloaderInterface for FossilDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::cleanup(self, r#type, package, path, prev_package).await
}
}
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index dc27e0c..55cf161 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -16,7 +16,6 @@ use crate::util::Git as GitUtil;
use crate::util::Platform;
use crate::util::ProcessExecutor;
use crate::util::Url;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
@@ -63,7 +62,7 @@ impl GitDownloader {
&self,
_package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
GitUtil::clean_env(&self.inner.process);
let path = self.normalize_path(path);
if !self.has_metadata_repository(&path) {
@@ -258,7 +257,7 @@ impl GitDownloader {
path: &str,
reference: &str,
pretty_version: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
let force: Vec<String> = if self
.has_discarded_changes
.get(path)
@@ -546,7 +545,7 @@ impl GitDownloader {
/// @phpstan-return PromiseInterface<void|null>
/// @throws \RuntimeException
- pub(crate) async fn discard_changes(&mut self, path: &str) -> Result<Option<PhpMixed>> {
+ pub(crate) async fn discard_changes(&mut self, path: &str) -> anyhow::Result<Option<PhpMixed>> {
let path = self.normalize_path(path);
let mut output = String::new();
if self.inner.process.borrow_mut().execute_args(
@@ -582,7 +581,7 @@ impl GitDownloader {
/// @phpstan-return PromiseInterface<void|null>
/// @throws \RuntimeException
- pub(crate) async fn stash_changes(&mut self, path: &str) -> Result<Option<PhpMixed>> {
+ pub(crate) async fn stash_changes(&mut self, path: &str) -> anyhow::Result<Option<PhpMixed>> {
let path = self.normalize_path(path);
let mut output = String::new();
if self.inner.process.borrow_mut().execute_args(
@@ -608,7 +607,7 @@ impl GitDownloader {
}
/// @throws \RuntimeException
- pub(crate) fn view_diff(&mut self, path: &str) -> Result<()> {
+ pub(crate) fn view_diff(&mut self, path: &str) -> anyhow::Result<()> {
let path = self.normalize_path(path);
let mut output = String::new();
if self.inner.process.borrow_mut().execute_args(
@@ -671,7 +670,11 @@ impl GitDownloader {
/// The default `VcsDownloader::clean_changes()` behavior: fail if the working copy has
/// local changes.
- fn fail_on_local_changes(&mut self, package: PackageInterfaceHandle, path: &str) -> Result<()> {
+ fn fail_on_local_changes(
+ &mut self,
+ package: PackageInterfaceHandle,
+ path: &str,
+ ) -> anyhow::Result<()> {
if self.get_local_changes(package, path)?.is_some() {
return Err(RuntimeException {
message: format!("Source directory {} has uncommitted changes.", path),
@@ -689,7 +692,7 @@ impl DvcsDownloaderInterface for GitDownloader {
&self,
package: PackageInterfaceHandle,
path: String,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
GitDownloader::get_unpushed_changes(self, package, &path)
}
}
@@ -699,7 +702,7 @@ impl ChangeReportInterface for GitDownloader {
&mut self,
_package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
GitUtil::clean_env(&self.inner.process);
if !self.has_metadata_repository(path) {
return Ok(None);
@@ -777,7 +780,7 @@ impl VcsDownloader for GitDownloader {
path: &str,
url: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
// Do not create an extra local cache when repository is already local
if Filesystem::is_local_path(url) {
return Ok(None);
@@ -847,7 +850,7 @@ impl VcsDownloader for GitDownloader {
package: PackageInterfaceHandle,
path: &str,
url: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
GitUtil::clean_env(&self.inner.process);
let path = self.normalize_path(path);
let cache_path = format!(
@@ -999,7 +1002,7 @@ impl VcsDownloader for GitDownloader {
target: PackageInterfaceHandle,
path: &str,
url: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
GitUtil::clean_env(&self.inner.process);
let path = self.normalize_path(path);
if !self.has_metadata_repository(&path) {
@@ -1159,7 +1162,7 @@ impl VcsDownloader for GitDownloader {
package: PackageInterfaceHandle,
path: &str,
update: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
GitUtil::clean_env(&self.inner.process);
let path = self.normalize_path(path);
@@ -1318,7 +1321,7 @@ impl VcsDownloader for GitDownloader {
Ok(None)
}
- fn reapply_changes(&mut self, path: &str) -> Result<()> {
+ fn reapply_changes(&mut self, path: &str) -> anyhow::Result<()> {
let path = self.normalize_path(path);
if self
.has_stashed_changes
@@ -1359,7 +1362,7 @@ impl VcsDownloader for GitDownloader {
from_reference: &str,
to_reference: &str,
path: &str,
- ) -> Result<String> {
+ ) -> anyhow::Result<String> {
let path = self.normalize_path(path);
let mut args = vec![
"--format=%h - %an: %s".to_string(),
diff --git a/crates/shirabe/src/downloader/gzip_downloader.rs b/crates/shirabe/src/downloader/gzip_downloader.rs
index b7b92c6..4ea2a32 100644
--- a/crates/shirabe/src/downloader/gzip_downloader.rs
+++ b/crates/shirabe/src/downloader/gzip_downloader.rs
@@ -12,7 +12,6 @@ use crate::util::Filesystem;
use crate::util::HttpDownloader;
use crate::util::Platform;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{
DIRECTORY_SEPARATOR, PATHINFO_FILENAME, PHP_URL_PATH, PhpMixed, RuntimeException,
@@ -87,7 +86,7 @@ impl ArchiveDownloader for GzipDownloader {
package: PackageInterfaceHandle,
file: &str,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let filename = pathinfo(
parse_url(
&strtr(&package.get_dist_url().unwrap_or_default(), "\\", "/"),
@@ -153,7 +152,7 @@ impl ChangeReportInterface for GzipDownloader {
&mut self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
self.inner.get_local_changes(package, path)
}
}
@@ -176,7 +175,7 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
path: &str,
prev_package: Option<PackageInterfaceHandle>,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner
.download(package, path, prev_package, output)
.await
@@ -188,7 +187,7 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::prepare(self, r#type, package, path, prev_package).await
}
@@ -197,7 +196,7 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::install(self, package, path, output).await
}
@@ -206,7 +205,7 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.update(initial, target, path).await
}
@@ -215,7 +214,7 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.remove(package, path, output).await
}
@@ -225,7 +224,7 @@ impl crate::downloader::DownloaderInterface for GzipDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::cleanup(self, r#type, package, path, prev_package).await
}
}
diff --git a/crates/shirabe/src/downloader/hg_downloader.rs b/crates/shirabe/src/downloader/hg_downloader.rs
index 650746b..5cc6f34 100644
--- a/crates/shirabe/src/downloader/hg_downloader.rs
+++ b/crates/shirabe/src/downloader/hg_downloader.rs
@@ -12,7 +12,6 @@ use crate::package::PackageInterfaceHandle;
use crate::util::Filesystem;
use crate::util::Hg as HgUtils;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{PhpMixed, RuntimeException};
@@ -65,7 +64,7 @@ impl VcsDownloader for HgDownloader {
_path: &str,
_url: &str,
_prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if HgUtils::get_version(&self.inner.process).is_none() {
return Err(RuntimeException {
message: "hg was not found in your PATH, skipping source download".to_string(),
@@ -82,7 +81,7 @@ impl VcsDownloader for HgDownloader {
package: PackageInterfaceHandle,
path: &str,
url: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let hg_utils = HgUtils::new(
self.inner.io.clone(),
self.inner.config.clone(),
@@ -137,7 +136,7 @@ impl VcsDownloader for HgDownloader {
target: PackageInterfaceHandle,
path: &str,
url: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let hg_utils = HgUtils::new(
self.inner.io.clone(),
self.inner.config.clone(),
@@ -187,7 +186,7 @@ impl VcsDownloader for HgDownloader {
from_reference: &str,
to_reference: &str,
path: &str,
- ) -> Result<String> {
+ ) -> anyhow::Result<String> {
let command = vec![
"hg".to_string(),
"log".to_string(),
@@ -228,7 +227,7 @@ impl ChangeReportInterface for HgDownloader {
&mut self,
_package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
if !std::path::Path::new(&format!("{}/.hg", path)).is_dir() {
return Ok(None);
}
@@ -280,7 +279,7 @@ impl DownloaderInterface for HgDownloader {
path: &str,
prev_package: Option<PackageInterfaceHandle>,
_output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::download(self, package, path, prev_package).await
}
@@ -290,7 +289,7 @@ impl DownloaderInterface for HgDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::prepare(self, r#type, package, path, prev_package).await
}
@@ -299,7 +298,7 @@ impl DownloaderInterface for HgDownloader {
package: PackageInterfaceHandle,
path: &str,
_output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::install(self, package, path).await
}
@@ -308,7 +307,7 @@ impl DownloaderInterface for HgDownloader {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::update(self, initial, target, path).await
}
@@ -317,7 +316,7 @@ impl DownloaderInterface for HgDownloader {
package: PackageInterfaceHandle,
path: &str,
_output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::remove(self, package, path).await
}
@@ -327,7 +326,7 @@ impl DownloaderInterface for HgDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::cleanup(self, r#type, package, path, prev_package).await
}
}
diff --git a/crates/shirabe/src/downloader/path_downloader.rs b/crates/shirabe/src/downloader/path_downloader.rs
index cfd4889..5dc51b3 100644
--- a/crates/shirabe/src/downloader/path_downloader.rs
+++ b/crates/shirabe/src/downloader/path_downloader.rs
@@ -20,7 +20,6 @@ use crate::util::Filesystem;
use crate::util::HttpDownloader;
use crate::util::Platform;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::filesystem::Filesystem as SymfonyFilesystem;
use shirabe_php_shim::{
@@ -83,7 +82,7 @@ impl PathDownloader {
&self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<String> {
+ ) -> anyhow::Result<String> {
let url = package.get_dist_url().ok_or_else(|| RuntimeException {
message: format!(
"The package {} has no dist url configured, cannot install.",
@@ -126,7 +125,7 @@ impl PathDownloader {
fn compute_allowed_strategies(
&self,
transport_options: &IndexMap<String, PhpMixed>,
- ) -> Result<(i64, Vec<i64>)> {
+ ) -> anyhow::Result<(i64, Vec<i64>)> {
// When symlink transport option is null, both symlink and mirror are allowed
let mut current_strategy = Self::STRATEGY_SYMLINK;
let mut allowed_strategies = vec![Self::STRATEGY_SYMLINK, Self::STRATEGY_MIRROR];
@@ -242,7 +241,7 @@ impl DownloaderInterface for PathDownloader {
path: &str,
prev_package: Option<PackageInterfaceHandle>,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let path = Filesystem::trim_trailing_slash(path);
let url = package.get_dist_url().ok_or_else(|| RuntimeException {
message: format!(
@@ -304,7 +303,7 @@ impl DownloaderInterface for PathDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner
.prepare(r#type, package, path, prev_package)
.await
@@ -315,7 +314,7 @@ impl DownloaderInterface for PathDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let path = Filesystem::trim_trailing_slash(path);
let url = package.get_dist_url().ok_or_else(|| RuntimeException {
message: format!(
@@ -368,7 +367,7 @@ impl DownloaderInterface for PathDownloader {
let mut is_fallback = false;
if Self::STRATEGY_SYMLINK == current_strategy {
- let symlink_result: Result<anyhow::Result<()>> =
+ let symlink_result: anyhow::Result<anyhow::Result<()>> =
(|| {
if Platform::is_windows() {
// Implement symlinks as NTFS junctions on Windows
@@ -489,7 +488,7 @@ impl DownloaderInterface for PathDownloader {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.update(initial, target, path).await
}
@@ -498,7 +497,7 @@ impl DownloaderInterface for PathDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let path = Filesystem::trim_trailing_slash(path);
// realpath() may resolve Windows junctions to the source path, so we'll check for a junction
// first to prevent a false positive when checking if the dist and install paths are the same.
@@ -590,7 +589,7 @@ impl DownloaderInterface for PathDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner
.cleanup(r#type, package, path, prev_package)
.await
diff --git a/crates/shirabe/src/downloader/perforce_downloader.rs b/crates/shirabe/src/downloader/perforce_downloader.rs
index 56d6957..4ca9b64 100644
--- a/crates/shirabe/src/downloader/perforce_downloader.rs
+++ b/crates/shirabe/src/downloader/perforce_downloader.rs
@@ -14,7 +14,6 @@ use crate::util::Filesystem;
use crate::util::Perforce;
use crate::util::PerforceInterface;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;
@@ -111,7 +110,7 @@ impl VcsDownloader for PerforceDownloader {
_path: &str,
_url: &str,
_prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
Ok(None)
}
@@ -120,7 +119,7 @@ impl VcsDownloader for PerforceDownloader {
package: PackageInterfaceHandle,
path: &str,
url: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let source_ref = package.get_source_reference().map(|s| s.to_string());
let label = self.get_label_from_source_reference(source_ref.clone().unwrap_or_default());
@@ -148,7 +147,7 @@ impl VcsDownloader for PerforceDownloader {
target: PackageInterfaceHandle,
path: &str,
url: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.do_install(target, path, url).await
}
@@ -157,7 +156,7 @@ impl VcsDownloader for PerforceDownloader {
from_reference: &str,
to_reference: &str,
_path: &str,
- ) -> Result<String> {
+ ) -> anyhow::Result<String> {
Ok(self
.perforce
.as_mut()
@@ -176,7 +175,7 @@ impl ChangeReportInterface for PerforceDownloader {
&mut self,
_package: PackageInterfaceHandle,
_path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
self.inner
.io
.write_error("Perforce driver does not check for local changes before overriding");
@@ -215,7 +214,7 @@ impl DownloaderInterface for PerforceDownloader {
path: &str,
prev_package: Option<PackageInterfaceHandle>,
_output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::download(self, package, path, prev_package).await
}
@@ -225,7 +224,7 @@ impl DownloaderInterface for PerforceDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::prepare(self, r#type, package, path, prev_package).await
}
@@ -234,7 +233,7 @@ impl DownloaderInterface for PerforceDownloader {
package: PackageInterfaceHandle,
path: &str,
_output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::install(self, package, path).await
}
@@ -243,7 +242,7 @@ impl DownloaderInterface for PerforceDownloader {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::update(self, initial, target, path).await
}
@@ -252,7 +251,7 @@ impl DownloaderInterface for PerforceDownloader {
package: PackageInterfaceHandle,
path: &str,
_output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::remove(self, package, path).await
}
@@ -262,7 +261,7 @@ impl DownloaderInterface for PerforceDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as VcsDownloader>::cleanup(self, r#type, package, path, prev_package).await
}
}
diff --git a/crates/shirabe/src/downloader/phar_downloader.rs b/crates/shirabe/src/downloader/phar_downloader.rs
index 4b3fc51..491f07e 100644
--- a/crates/shirabe/src/downloader/phar_downloader.rs
+++ b/crates/shirabe/src/downloader/phar_downloader.rs
@@ -12,7 +12,6 @@ use crate::package::PackageInterfaceHandle;
use crate::util::Filesystem;
use crate::util::HttpDownloader;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{Phar, PhpMixed};
@@ -69,7 +68,7 @@ impl ArchiveDownloader for PharDownloader {
_package: PackageInterfaceHandle,
file: &str,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
// Can throw an UnexpectedValueException
let archive = Phar::new(file.to_string());
archive.extract_to(path, None, true);
@@ -87,7 +86,7 @@ impl ChangeReportInterface for PharDownloader {
&mut self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
self.inner.get_local_changes(package, path)
}
}
@@ -110,7 +109,7 @@ impl DownloaderInterface for PharDownloader {
path: &str,
prev_package: Option<PackageInterfaceHandle>,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner
.download(package, path, prev_package, output)
.await
@@ -122,7 +121,7 @@ impl DownloaderInterface for PharDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::prepare(self, r#type, package, path, prev_package).await
}
@@ -131,7 +130,7 @@ impl DownloaderInterface for PharDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::install(self, package, path, output).await
}
@@ -140,7 +139,7 @@ impl DownloaderInterface for PharDownloader {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.update(initial, target, path).await
}
@@ -149,7 +148,7 @@ impl DownloaderInterface for PharDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.remove(package, path, output).await
}
@@ -159,7 +158,7 @@ impl DownloaderInterface for PharDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::cleanup(self, r#type, package, path, prev_package).await
}
}
diff --git a/crates/shirabe/src/downloader/rar_downloader.rs b/crates/shirabe/src/downloader/rar_downloader.rs
index 88183f9..bf69d14 100644
--- a/crates/shirabe/src/downloader/rar_downloader.rs
+++ b/crates/shirabe/src/downloader/rar_downloader.rs
@@ -13,7 +13,6 @@ use crate::util::HttpDownloader;
use crate::util::IniHelper;
use crate::util::Platform;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{
PhpMixed, RarArchive, RuntimeException, UnexpectedValueException, class_exists, implode,
@@ -72,7 +71,7 @@ impl ArchiveDownloader for RarDownloader {
_package: PackageInterfaceHandle,
file: &str,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let mut process_error: Option<String> = None;
if !Platform::is_windows() {
@@ -167,7 +166,7 @@ impl ChangeReportInterface for RarDownloader {
&mut self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
self.inner.get_local_changes(package, path)
}
}
@@ -190,7 +189,7 @@ impl crate::downloader::DownloaderInterface for RarDownloader {
path: &str,
prev_package: Option<PackageInterfaceHandle>,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner
.download(package, path, prev_package, output)
.await
@@ -202,7 +201,7 @@ impl crate::downloader::DownloaderInterface for RarDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::prepare(self, r#type, package, path, prev_package).await
}
@@ -211,7 +210,7 @@ impl crate::downloader::DownloaderInterface for RarDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::install(self, package, path, output).await
}
@@ -220,7 +219,7 @@ impl crate::downloader::DownloaderInterface for RarDownloader {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.update(initial, target, path).await
}
@@ -229,7 +228,7 @@ impl crate::downloader::DownloaderInterface for RarDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.remove(package, path, output).await
}
@@ -239,7 +238,7 @@ impl crate::downloader::DownloaderInterface for RarDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::cleanup(self, r#type, package, path, prev_package).await
}
}
diff --git a/crates/shirabe/src/downloader/tar_downloader.rs b/crates/shirabe/src/downloader/tar_downloader.rs
index 833a958..6de38c9 100644
--- a/crates/shirabe/src/downloader/tar_downloader.rs
+++ b/crates/shirabe/src/downloader/tar_downloader.rs
@@ -12,7 +12,6 @@ use crate::package::PackageInterfaceHandle;
use crate::util::Filesystem;
use crate::util::HttpDownloader;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{PharData, PhpMixed};
@@ -69,7 +68,7 @@ impl ArchiveDownloader for TarDownloader {
_package: PackageInterfaceHandle,
file: &str,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let archive = PharData::new(file.to_string());
archive.extract_to(path, None, true);
@@ -82,7 +81,7 @@ impl ChangeReportInterface for TarDownloader {
&mut self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
self.inner.get_local_changes(package, path)
}
}
@@ -105,7 +104,7 @@ impl DownloaderInterface for TarDownloader {
path: &str,
prev_package: Option<PackageInterfaceHandle>,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner
.download(package, path, prev_package, output)
.await
@@ -117,7 +116,7 @@ impl DownloaderInterface for TarDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::prepare(self, r#type, package, path, prev_package).await
}
@@ -126,7 +125,7 @@ impl DownloaderInterface for TarDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::install(self, package, path, output).await
}
@@ -135,7 +134,7 @@ impl DownloaderInterface for TarDownloader {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.update(initial, target, path).await
}
@@ -144,7 +143,7 @@ impl DownloaderInterface for TarDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.remove(package, path, output).await
}
@@ -154,7 +153,7 @@ impl DownloaderInterface for TarDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::cleanup(self, r#type, package, path, prev_package).await
}
}
diff --git a/crates/shirabe/src/downloader/vcs_downloader.rs b/crates/shirabe/src/downloader/vcs_downloader.rs
index 1c89571..7c5dfb8 100644
--- a/crates/shirabe/src/downloader/vcs_downloader.rs
+++ b/crates/shirabe/src/downloader/vcs_downloader.rs
@@ -16,7 +16,6 @@ use crate::package::version::VersionGuesser;
use crate::package::version::VersionParser;
use crate::util::Filesystem;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, RuntimeException, array_map, array_shift, explode,
@@ -89,7 +88,7 @@ pub trait VcsDownloader:
path: &str,
url: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>>;
+ ) -> anyhow::Result<Option<PhpMixed>>;
/// Downloads specific package into specific folder.
async fn do_install(
@@ -97,7 +96,7 @@ pub trait VcsDownloader:
package: PackageInterfaceHandle,
path: &str,
url: &str,
- ) -> Result<Option<PhpMixed>>;
+ ) -> anyhow::Result<Option<PhpMixed>>;
/// Updates specific package in specific folder from initial to target version.
async fn do_update(
@@ -106,7 +105,7 @@ pub trait VcsDownloader:
target: PackageInterfaceHandle,
path: &str,
url: &str,
- ) -> Result<Option<PhpMixed>>;
+ ) -> anyhow::Result<Option<PhpMixed>>;
/// Fetches the commit logs between two commits
fn get_commit_logs(
@@ -114,7 +113,7 @@ pub trait VcsDownloader:
from_reference: &str,
to_reference: &str,
path: &str,
- ) -> Result<String>;
+ ) -> anyhow::Result<String>;
/// Checks if VCS metadata repository has been initialized
/// repository example: .git|.svn|.hg
@@ -129,7 +128,7 @@ pub trait VcsDownloader:
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if package.get_source_reference().is_none() {
return Err(InvalidArgumentException {
message: format!(
@@ -144,7 +143,7 @@ pub trait VcsDownloader:
let mut urls = self.prepare_urls(package.get_source_urls());
while let Some(url) = array_shift(&mut urls) {
- let attempt: Result<Option<PhpMixed>> = self
+ let attempt: anyhow::Result<Option<PhpMixed>> = self
.do_download(package.clone(), path, &url, prev_package.clone())
.await;
match attempt {
@@ -186,7 +185,7 @@ pub trait VcsDownloader:
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if r#type == "update" {
self.clean_changes(prev_package.clone().unwrap(), path, true)
.await?;
@@ -207,7 +206,7 @@ pub trait VcsDownloader:
_package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if r#type == "update"
&& prev_package
.clone()
@@ -229,7 +228,7 @@ pub trait VcsDownloader:
&mut self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if package.get_source_reference().is_none() {
return Err(InvalidArgumentException {
message: format!(
@@ -249,7 +248,7 @@ pub trait VcsDownloader:
let mut urls = self.prepare_urls(package.get_source_urls());
while let Some(url) = array_shift(&mut urls) {
- let attempt: Result<Option<PhpMixed>> =
+ let attempt: anyhow::Result<Option<PhpMixed>> =
self.do_install(package.clone(), path, &url).await;
match attempt {
Ok(_) => break,
@@ -289,7 +288,7 @@ pub trait VcsDownloader:
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if target.get_source_reference().is_none() {
return Err(InvalidArgumentException {
message: format!(
@@ -314,7 +313,7 @@ pub trait VcsDownloader:
let mut exception: Option<anyhow::Error> = None;
while let Some(url) = array_shift(&mut urls) {
- let attempt: Result<Option<PhpMixed>> = self
+ let attempt: anyhow::Result<Option<PhpMixed>> = self
.do_update(initial.clone(), target.clone(), path, &url)
.await;
match attempt {
@@ -390,7 +389,7 @@ pub trait VcsDownloader:
&mut self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.io().write_error3(
&format!(" - {}", UninstallOperation::format(package, false)),
true,
@@ -441,7 +440,7 @@ pub trait VcsDownloader:
package: PackageInterfaceHandle,
path: &str,
_update: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
// the default implementation just fails if there are any changes, override in child classes to provide stash-ability
if self.get_local_changes(package, path)?.is_some() {
return Err(RuntimeException {
@@ -455,7 +454,7 @@ pub trait VcsDownloader:
}
/// Reapply previously stashed changes if applicable, only called after an update (regardless if successful or not)
- fn reapply_changes(&mut self, _path: &str) -> Result<()> {
+ fn reapply_changes(&mut self, _path: &str) -> anyhow::Result<()> {
Ok(())
}
diff --git a/crates/shirabe/src/downloader/xz_downloader.rs b/crates/shirabe/src/downloader/xz_downloader.rs
index 3e61ba5..fe35c92 100644
--- a/crates/shirabe/src/downloader/xz_downloader.rs
+++ b/crates/shirabe/src/downloader/xz_downloader.rs
@@ -11,7 +11,7 @@ use crate::package::PackageInterfaceHandle;
use crate::util::Filesystem;
use crate::util::HttpDownloader;
use crate::util::ProcessExecutor;
-use anyhow::{Result, bail};
+use anyhow::bail;
use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;
@@ -68,7 +68,7 @@ impl ArchiveDownloader for XzDownloader {
_package: PackageInterfaceHandle,
file: &str,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let command = ["tar", "-xJf", file, "-C", path];
let mut ignored_output = PhpMixed::Null;
@@ -101,7 +101,7 @@ impl ChangeReportInterface for XzDownloader {
&mut self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
self.inner.get_local_changes(package, path)
}
}
@@ -124,7 +124,7 @@ impl crate::downloader::DownloaderInterface for XzDownloader {
path: &str,
prev_package: Option<PackageInterfaceHandle>,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner
.download(package, path, prev_package, output)
.await
@@ -136,7 +136,7 @@ impl crate::downloader::DownloaderInterface for XzDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::prepare(self, r#type, package, path, prev_package).await
}
@@ -145,7 +145,7 @@ impl crate::downloader::DownloaderInterface for XzDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::install(self, package, path, output).await
}
@@ -154,7 +154,7 @@ impl crate::downloader::DownloaderInterface for XzDownloader {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.update(initial, target, path).await
}
@@ -163,7 +163,7 @@ impl crate::downloader::DownloaderInterface for XzDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.remove(package, path, output).await
}
@@ -173,7 +173,7 @@ impl crate::downloader::DownloaderInterface for XzDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::cleanup(self, r#type, package, path, prev_package).await
}
}
diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs
index 6f3c6e5..428ca2a 100644
--- a/crates/shirabe/src/downloader/zip_downloader.rs
+++ b/crates/shirabe/src/downloader/zip_downloader.rs
@@ -7,7 +7,6 @@ use crate::io::IOInterfaceImmutable;
use crate::package::PackageInterfaceHandle;
use crate::util::IniHelper;
use crate::util::Platform;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::process::ExecutableFinder;
@@ -63,7 +62,7 @@ impl ZipDownloader {
package: PackageInterfaceHandle,
file: &str,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
static WARNED_7ZIP_LINUX: Mutex<bool> = Mutex::new(false);
let is_last_chance = !HAS_ZIP_ARCHIVE.lock().unwrap().unwrap_or(false);
@@ -191,7 +190,7 @@ impl ZipDownloader {
path: &str,
package: PackageInterfaceHandle,
executable: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if is_last_chance {
return Err(process_error);
}
@@ -277,10 +276,10 @@ impl ZipDownloader {
package: PackageInterfaceHandle,
file: &str,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let mut zip_archive = self.zip_archive_object.take().unwrap_or_default();
- let result: Result<Option<PhpMixed>> = (|| {
+ let result: anyhow::Result<Option<PhpMixed>> = (|| {
let retval = if !file_exists(file) || filesize(file).is_none_or(|s| s == 0) {
Err(-1i64)
} else {
@@ -436,7 +435,7 @@ impl ArchiveDownloader for ZipDownloader {
package: PackageInterfaceHandle,
file: &str,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.extract_with_system_unzip(package, file, path).await
}
}
@@ -446,7 +445,7 @@ impl ChangeReportInterface for ZipDownloader {
&mut self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
self.inner.get_local_changes(package, path)
}
}
@@ -469,7 +468,7 @@ impl crate::downloader::DownloaderInterface for ZipDownloader {
path: &str,
prev_package: Option<PackageInterfaceHandle>,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
{
let mut unzip_commands = UNZIP_COMMANDS.lock().unwrap();
if unzip_commands.is_none() {
@@ -608,7 +607,7 @@ impl crate::downloader::DownloaderInterface for ZipDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::prepare(self, r#type, package, path, prev_package).await
}
@@ -617,7 +616,7 @@ impl crate::downloader::DownloaderInterface for ZipDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::install(self, package, path, output).await
}
@@ -626,7 +625,7 @@ impl crate::downloader::DownloaderInterface for ZipDownloader {
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.update(initial, target, path).await
}
@@ -635,7 +634,7 @@ impl crate::downloader::DownloaderInterface for ZipDownloader {
package: PackageInterfaceHandle,
path: &str,
output: bool,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.remove(package, path, output).await
}
@@ -645,7 +644,7 @@ impl crate::downloader::DownloaderInterface for ZipDownloader {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
<Self as ArchiveDownloader>::cleanup(self, r#type, package, path, prev_package).await
}
}
diff --git a/crates/shirabe/src/filter/platform_requirement_filter/platform_requirement_filter_factory.rs b/crates/shirabe/src/filter/platform_requirement_filter/platform_requirement_filter_factory.rs
index a260c29..dcfd519 100644
--- a/crates/shirabe/src/filter/platform_requirement_filter/platform_requirement_filter_factory.rs
+++ b/crates/shirabe/src/filter/platform_requirement_filter/platform_requirement_filter_factory.rs
@@ -6,7 +6,6 @@ use crate::filter::platform_requirement_filter::{
ignore_nothing_platform_requirement_filter::IgnoreNothingPlatformRequirementFilter,
platform_requirement_filter_interface::PlatformRequirementFilterInterface,
};
-use anyhow::Result;
use shirabe_php_shim::{InvalidArgumentException, PhpMixed};
use std::rc::Rc;
@@ -15,7 +14,7 @@ pub struct PlatformRequirementFilterFactory;
impl PlatformRequirementFilterFactory {
pub fn from_bool_or_list(
bool_or_list: PhpMixed,
- ) -> Result<Rc<dyn PlatformRequirementFilterInterface>> {
+ ) -> anyhow::Result<Rc<dyn PlatformRequirementFilterInterface>> {
match bool_or_list {
PhpMixed::Bool(b) => {
if b {
diff --git a/crates/shirabe/src/installed_versions.rs b/crates/shirabe/src/installed_versions.rs
index 8b287f1..3cda1c4 100644
--- a/crates/shirabe/src/installed_versions.rs
+++ b/crates/shirabe/src/installed_versions.rs
@@ -1,7 +1,6 @@
//! ref: composer/src/Composer/InstalledVersions.php
use crate::autoload::ClassLoader;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{
OutOfBoundsException, PhpMixed, array_flip, array_keys, array_merge, call_user_func_array,
@@ -143,7 +142,7 @@ impl InstalledVersions {
parser: &VersionParser,
package_name: &str,
constraint: Option<&str>,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
let constraint = parser.parse_constraints(constraint.unwrap_or(""))?;
let provided = parser.parse_constraints(&Self::get_version_ranges(package_name)?)?;
@@ -157,7 +156,7 @@ impl InstalledVersions {
///
/// @param string $packageName
/// @return string Version constraint usable with composer/semver
- pub fn get_version_ranges(package_name: &str) -> Result<String> {
+ pub fn get_version_ranges(package_name: &str) -> anyhow::Result<String> {
for installed in Self::get_installed() {
let Some(versions) = installed.get("versions").and_then(|v| v.as_array()) else {
continue;
@@ -226,7 +225,7 @@ impl InstalledVersions {
/// @param string $packageName
/// @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
- pub fn get_version(package_name: &str) -> Result<Option<String>> {
+ pub fn get_version(package_name: &str) -> anyhow::Result<Option<String>> {
for installed in Self::get_installed() {
let Some(versions) = installed.get("versions").and_then(|v| v.as_array()) else {
continue;
@@ -254,7 +253,7 @@ impl InstalledVersions {
/// @param string $packageName
/// @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
- pub fn get_pretty_version(package_name: &str) -> Result<Option<String>> {
+ pub fn get_pretty_version(package_name: &str) -> anyhow::Result<Option<String>> {
for installed in Self::get_installed() {
let Some(versions) = installed.get("versions").and_then(|v| v.as_array()) else {
continue;
@@ -282,7 +281,7 @@ impl InstalledVersions {
/// @param string $packageName
/// @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
- pub fn get_reference(package_name: &str) -> Result<Option<String>> {
+ pub fn get_reference(package_name: &str) -> anyhow::Result<Option<String>> {
for installed in Self::get_installed() {
let Some(versions) = installed.get("versions").and_then(|v| v.as_array()) else {
continue;
@@ -310,7 +309,7 @@ impl InstalledVersions {
/// @param string $packageName
/// @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
- pub fn get_install_path(package_name: &str) -> Result<Option<String>> {
+ pub fn get_install_path(package_name: &str) -> anyhow::Result<Option<String>> {
for installed in Self::get_installed() {
let Some(versions) = installed.get("versions").and_then(|v| v.as_array()) else {
continue;
diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs
index c1e65a8..97e1985 100644
--- a/crates/shirabe/src/installer/installation_manager.rs
+++ b/crates/shirabe/src/installer/installation_manager.rs
@@ -18,7 +18,6 @@ use crate::repository::InstalledRepositoryInterface;
use crate::util::Platform;
use crate::util::r#loop::Loop;
use crate::util::sync_executor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::seld::signal::SignalHandler;
use shirabe_php_shim::{
@@ -156,7 +155,7 @@ impl InstallationManager {
}
/// Returns installer for a specific package type.
- pub fn get_installer(&mut self, r#type: &str) -> Result<&mut dyn InstallerInterface> {
+ pub fn get_installer(&mut self, r#type: &str) -> anyhow::Result<&mut dyn InstallerInterface> {
let r#type = strtolower(r#type);
if let Some(&index) = self.cache.get(&r#type) {
@@ -184,7 +183,7 @@ impl InstallationManager {
&mut self,
repo: &dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
// For testing only (ref InstallationManagerMock::isPackageInstalled).
if self.mock.is_some() {
return Ok(repo.has_package(package));
@@ -228,7 +227,7 @@ impl InstallationManager {
dev_mode: bool,
run_scripts: bool,
download_only: bool,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
// For testing only: the mock records each operation and mutates the repo directly,
// skipping the download step (ref InstallationManagerMock::execute). The alias operations'
// repo mutation is inlined (rather than calling mark_alias_*) so `self.mock` can stay
@@ -297,8 +296,9 @@ impl InstallationManager {
let mut cleanup_promises: IndexMap<
i64,
Box<
- dyn Fn()
- -> Option<std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>>>>>,
+ dyn Fn() -> Option<
+ std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>>>>,
+ >,
>,
> = IndexMap::new();
@@ -318,7 +318,7 @@ impl InstallationManager {
let all_operations: Vec<std::rc::Rc<dyn OperationInterface>> = operations.clone();
- let result: Result<()> = (|| -> Result<()> {
+ let result: anyhow::Result<()> = (|| -> anyhow::Result<()> {
// execute operations in batches to make sure download-modifying-plugins are installed
// before the other packages get downloaded
let mut batches: Vec<IndexMap<i64, std::rc::Rc<dyn OperationInterface>>> = vec![];
@@ -405,15 +405,16 @@ impl InstallationManager {
cleanup_promises: &mut IndexMap<
i64,
Box<
- dyn Fn()
- -> Option<std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>>>>>,
+ dyn Fn() -> Option<
+ std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>>>>,
+ >,
>,
>,
dev_mode: bool,
run_scripts: bool,
download_only: bool,
all_operations: Vec<std::rc::Rc<dyn OperationInterface>>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
for (index, operation) in &operations {
let op_type = operation.get_operation_type();
@@ -449,8 +450,9 @@ impl InstallationManager {
let _ = installer;
let op_type_clone = op_type.clone();
let cleanup: Box<
- dyn Fn()
- -> Option<std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>>>>>,
+ dyn Fn() -> Option<
+ std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>>>>,
+ >,
> = Box::new(move || {
// avoid calling cleanup if the download was not even initialized for a package
// as without installation source configured nothing will work
@@ -458,7 +460,7 @@ impl InstallationManager {
let _ = &op_type_clone;
// TODO(phase-c-promise): build the real installer.cleanup() future once the installer
// can be shared into a 'static cleanup closure (Stage 2 Rc/Arc).
- let fut: std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>>>> =
+ let fut: std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>>>> =
Box::pin(async { Ok(()) });
Some(fut)
});
@@ -533,14 +535,15 @@ impl InstallationManager {
cleanup_promises: &IndexMap<
i64,
Box<
- dyn Fn()
- -> Option<std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>>>>>,
+ dyn Fn() -> Option<
+ std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>>>>,
+ >,
>,
>,
dev_mode: bool,
run_scripts: bool,
all_operations: &[std::rc::Rc<dyn OperationInterface>],
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let mut post_exec_callbacks: Vec<Box<dyn Fn()>> = vec![];
for (index, operation) in operations {
@@ -711,7 +714,7 @@ impl InstallationManager {
&mut self,
repo: &mut dyn InstalledRepositoryInterface,
operation: &InstallOperation,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let package = operation.get_package();
let package_type = package.get_type();
let installer = self.get_installer(&package_type)?;
@@ -726,7 +729,7 @@ impl InstallationManager {
&mut self,
repo: &mut dyn InstalledRepositoryInterface,
operation: &UpdateOperation,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let initial = operation.get_initial_package().clone();
let target = operation.get_target_package().clone();
@@ -754,7 +757,7 @@ impl InstallationManager {
&mut self,
repo: &mut dyn InstalledRepositoryInterface,
operation: &UninstallOperation,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let package = operation.get_package();
let package_type = package.get_type();
let installer = self.get_installer(&package_type)?;
@@ -810,7 +813,7 @@ impl InstallationManager {
// TODO(phase-c-promise): PHP collects every http_downloader.add() promise and runs them via
// Loop::wait; the single-threaded sync bridge block_on's each notification serially instead.
- let result: Result<()> = (|| -> Result<()> {
+ let result: anyhow::Result<()> = (|| -> anyhow::Result<()> {
for (repo_url, packages) in &self.notifiable_packages {
// non-batch API, deprecated
if str_contains(repo_url, "%package%") {
@@ -937,13 +940,15 @@ impl InstallationManager {
cleanup_promises: &IndexMap<
i64,
Box<
- dyn Fn()
- -> Option<std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>>>>>,
+ dyn Fn() -> Option<
+ std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>>>>,
+ >,
>,
>,
) {
- let mut promises: Vec<std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>>>>> =
- vec![];
+ let mut promises: Vec<
+ std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>>>>,
+ > = vec![];
self.loop_.borrow().abort_jobs();
@@ -980,7 +985,7 @@ pub trait InstallationManagerInterface: std::fmt::Debug {
&mut self,
repo: &dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> Result<bool>;
+ ) -> anyhow::Result<bool>;
fn ensure_binaries_presence(&mut self, package: PackageInterfaceHandle);
fn execute(
&mut self,
@@ -989,7 +994,7 @@ pub trait InstallationManagerInterface: std::fmt::Debug {
dev_mode: bool,
run_scripts: bool,
download_only: bool,
- ) -> Result<()>;
+ ) -> anyhow::Result<()>;
fn get_install_path(&mut self, package: PackageInterfaceHandle) -> Option<String>;
fn set_output_progress(&mut self, output_progress: bool);
fn notify_installs(&mut self, io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>);
@@ -1016,7 +1021,7 @@ impl InstallationManagerInterface for InstallationManager {
&mut self,
repo: &dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
self.is_package_installed(repo, package)
}
@@ -1031,7 +1036,7 @@ impl InstallationManagerInterface for InstallationManager {
dev_mode: bool,
run_scripts: bool,
download_only: bool,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
self.execute(repo, operations, dev_mode, run_scripts, download_only)
}
diff --git a/crates/shirabe/src/installer/library_installer.rs b/crates/shirabe/src/installer/library_installer.rs
index 133ba7c..c0b2ebc 100644
--- a/crates/shirabe/src/installer/library_installer.rs
+++ b/crates/shirabe/src/installer/library_installer.rs
@@ -12,7 +12,6 @@ use crate::repository::InstalledRepositoryInterface;
use crate::util::Filesystem;
use crate::util::Platform;
use crate::util::Silencer;
-use anyhow::Result;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, dirname, is_dir, is_link, preg_quote,
@@ -146,7 +145,7 @@ impl LibraryInstaller {
pub(crate) async fn install_code(
&mut self,
package: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let download_path = self.get_install_path(package.clone()).unwrap();
self.get_download_manager()
@@ -161,7 +160,7 @@ impl LibraryInstaller {
&mut self,
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let initial_download_path = self.get_install_path(initial.clone()).unwrap();
let target_download_path = self.get_install_path(target.clone()).unwrap();
if target_download_path != initial_download_path {
@@ -191,7 +190,7 @@ impl LibraryInstaller {
pub(crate) async fn remove_code(
&mut self,
package: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let download_path = self.get_package_base_path(package.clone());
self.get_download_manager()
@@ -271,7 +270,7 @@ impl InstallerInterface for LibraryInstaller {
&mut self,
package: PackageInterfaceHandle,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.initialize_vendor_dir();
let download_path = self.get_install_path(package.clone()).unwrap();
@@ -286,7 +285,7 @@ impl InstallerInterface for LibraryInstaller {
r#type: &str,
package: PackageInterfaceHandle,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.initialize_vendor_dir();
let download_path = self.get_install_path(package.clone()).unwrap();
@@ -301,7 +300,7 @@ impl InstallerInterface for LibraryInstaller {
r#type: &str,
package: PackageInterfaceHandle,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.initialize_vendor_dir();
let download_path = self.get_install_path(package.clone()).unwrap();
@@ -315,7 +314,7 @@ impl InstallerInterface for LibraryInstaller {
&mut self,
repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.initialize_vendor_dir();
let download_path = self.get_install_path(package.clone()).unwrap();
@@ -344,7 +343,7 @@ impl InstallerInterface for LibraryInstaller {
repo: &mut dyn InstalledRepositoryInterface,
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if !repo.has_package(initial.clone()) {
return Err(InvalidArgumentException {
message: format!("Package is not installed: {}", initial),
@@ -376,7 +375,7 @@ impl InstallerInterface for LibraryInstaller {
&mut self,
repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if !repo.has_package(package.clone()) {
return Err(InvalidArgumentException {
message: format!("Package is not installed: {}", package),
diff --git a/crates/shirabe/src/installer/metapackage_installer.rs b/crates/shirabe/src/installer/metapackage_installer.rs
index cebec2c..ae1f49b 100644
--- a/crates/shirabe/src/installer/metapackage_installer.rs
+++ b/crates/shirabe/src/installer/metapackage_installer.rs
@@ -9,7 +9,6 @@ use crate::io::IOInterfaceImmutable;
use crate::io::io_interface;
use crate::package::PackageInterfaceHandle;
use crate::repository::InstalledRepositoryInterface;
-use anyhow::Result;
use shirabe_php_shim::{InvalidArgumentException, PhpMixed};
#[derive(Debug)]
@@ -41,7 +40,7 @@ impl InstallerInterface for MetapackageInstaller {
&mut self,
_package: PackageInterfaceHandle,
_prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
Ok(None)
}
@@ -50,7 +49,7 @@ impl InstallerInterface for MetapackageInstaller {
_type: &str,
_package: PackageInterfaceHandle,
_prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
Ok(None)
}
@@ -59,7 +58,7 @@ impl InstallerInterface for MetapackageInstaller {
_type: &str,
_package: PackageInterfaceHandle,
_prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
Ok(None)
}
@@ -67,7 +66,7 @@ impl InstallerInterface for MetapackageInstaller {
&mut self,
repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.io.write_error3(
&format!(" - {}", InstallOperation::format(package.clone(), false)),
true,
@@ -84,7 +83,7 @@ impl InstallerInterface for MetapackageInstaller {
repo: &mut dyn InstalledRepositoryInterface,
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if !repo.has_package(initial.clone()) {
return Err(InvalidArgumentException {
message: format!("Package is not installed: {}", initial),
@@ -112,7 +111,7 @@ impl InstallerInterface for MetapackageInstaller {
&mut self,
repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if !repo.has_package(package.clone()) {
return Err(InvalidArgumentException {
message: format!("Package is not installed: {}", package),
diff --git a/crates/shirabe/src/installer/plugin_installer.rs b/crates/shirabe/src/installer/plugin_installer.rs
index 28e4e0d..132d408 100644
--- a/crates/shirabe/src/installer/plugin_installer.rs
+++ b/crates/shirabe/src/installer/plugin_installer.rs
@@ -11,7 +11,6 @@ use crate::plugin::PluginManager;
use crate::repository::InstalledRepositoryInterface;
use crate::util::Filesystem;
use crate::util::Platform;
-use anyhow::Result;
use shirabe_php_shim::{PhpMixed, UnexpectedValueException, empty};
#[derive(Debug)]
@@ -49,7 +48,7 @@ impl PluginInstaller {
e: anyhow::Error,
repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
self.inner.io.write_error(&format!(
"Plugin initialization failed ({}), uninstalling plugin",
e
@@ -83,7 +82,7 @@ impl InstallerInterface for PluginInstaller {
r#type: &str,
package: PackageInterfaceHandle,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
if (r#type == "install" || r#type == "update")
&& !self
.get_plugin_manager()
@@ -110,7 +109,7 @@ impl InstallerInterface for PluginInstaller {
&mut self,
package: PackageInterfaceHandle,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
let extra = package.get_extra();
let class = extra.get("class").cloned().unwrap_or(PhpMixed::Null);
if empty(&class) {
@@ -130,7 +129,7 @@ impl InstallerInterface for PluginInstaller {
&mut self,
repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.install(repo, package).await?;
// TODO(plugin): register package in plugin manager after install, rollback on failure
@@ -145,7 +144,7 @@ impl InstallerInterface for PluginInstaller {
repo: &mut dyn InstalledRepositoryInterface,
initial: PackageInterfaceHandle,
target: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.update(repo, initial, target).await?;
// TODO(plugin): deactivate initial and register target in plugin manager after update, rollback on failure
@@ -160,7 +159,7 @@ impl InstallerInterface for PluginInstaller {
&mut self,
repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
// TODO(plugin): uninstall package from plugin manager
self.get_plugin_manager()
.borrow_mut()
@@ -174,7 +173,7 @@ impl InstallerInterface for PluginInstaller {
r#type: &str,
package: PackageInterfaceHandle,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
self.inner.cleanup(r#type, package, prev_package).await
}
diff --git a/crates/shirabe/src/io/buffer_io.rs b/crates/shirabe/src/io/buffer_io.rs
index 5c93d72..af7ae61 100644
--- a/crates/shirabe/src/io/buffer_io.rs
+++ b/crates/shirabe/src/io/buffer_io.rs
@@ -1,7 +1,6 @@
//! ref: composer/src/Composer/IO/BufferIO.php
use crate::io::ConsoleIO;
-use anyhow::Result;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::console::formatter::OutputFormatterInterface;
use shirabe_external_packages::symfony::console::helper::QuestionHelper;
@@ -24,7 +23,7 @@ impl BufferIO {
input: String,
verbosity: i64,
formatter: Option<std::rc::Rc<std::cell::RefCell<dyn OutputFormatterInterface>>>,
- ) -> Result<Self> {
+ ) -> anyhow::Result<Self> {
let mut input_obj = StringInput::new(&input)?;
input_obj.set_interactive(false);
@@ -112,7 +111,7 @@ impl BufferIO {
output
}
- pub fn set_user_inputs(&mut self, inputs: Vec<String>) -> Result<()> {
+ pub fn set_user_inputs(&mut self, inputs: Vec<String>) -> anyhow::Result<()> {
let stream = self.create_stream(inputs)?;
let mut input = self.inner.input.borrow_mut();
@@ -130,7 +129,7 @@ impl BufferIO {
Ok(())
}
- fn create_stream(&self, inputs: Vec<String>) -> Result<PhpResource> {
+ fn create_stream(&self, inputs: Vec<String>) -> anyhow::Result<PhpResource> {
let stream = match fopen("php://memory", "r+") {
Ok(stream) => stream,
Err(_) => {
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index c0b8816..0f609f2 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -8,7 +8,6 @@ use crate::json::JsonValidationException;
use crate::util::Filesystem;
use crate::util::HttpDownloader;
use crate::util::Silencer;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::seld::json_lint::JsonParser;
@@ -114,7 +113,7 @@ impl JsonFile {
path: String,
http_downloader: Option<std::rc::Rc<std::cell::RefCell<HttpDownloader>>>,
io: Option<std::rc::Rc<std::cell::RefCell<dyn IOInterface>>>,
- ) -> Result<Self> {
+ ) -> anyhow::Result<Self> {
if http_downloader.is_none() && Preg::is_match(r"{^https?://}i", &path) {
return Err(InvalidArgumentException {
message: "http urls require a HttpDownloader instance to be passed".to_string(),
@@ -144,8 +143,8 @@ impl JsonFile {
/// @throws ParsingException
/// @throws \RuntimeException
/// @return mixed
- pub fn read(&mut self) -> Result<PhpMixed> {
- let json: Option<String> = match (|| -> Result<Option<String>> {
+ pub fn read(&mut self) -> anyhow::Result<PhpMixed> {
+ let json: Option<String> = match (|| -> anyhow::Result<Option<String>> {
if let Some(http_downloader) = &self.http_downloader {
Ok(http_downloader
.borrow_mut()
@@ -213,11 +212,15 @@ impl JsonFile {
Self::parse_json(Some(&json), Some(&self.path))
}
- pub fn write(&self, hash: PhpMixed) -> Result<()> {
+ pub fn write(&self, hash: PhpMixed) -> anyhow::Result<()> {
self.write_with_options(hash, JsonEncodeOptions::default())
}
- pub fn write_with_options(&self, hash: PhpMixed, options: JsonEncodeOptions) -> Result<()> {
+ pub fn write_with_options(
+ &self,
+ hash: PhpMixed,
+ options: JsonEncodeOptions,
+ ) -> anyhow::Result<()> {
if self.path == "php://memory" {
file_put_contents(
&self.path,
@@ -252,7 +255,7 @@ impl JsonFile {
let mut retries = 3;
while retries > 0 {
retries -= 1;
- let attempt: Result<()> = (|| -> Result<()> {
+ let attempt: anyhow::Result<()> = (|| -> anyhow::Result<()> {
self.file_put_contents_if_modified(
&self.path,
&format!(
@@ -282,7 +285,11 @@ impl JsonFile {
/// Modify file properties only if content modified
///
/// @return int|false
- fn file_put_contents_if_modified(&self, path: &str, content: &str) -> Result<Option<i64>> {
+ fn file_put_contents_if_modified(
+ &self,
+ path: &str,
+ content: &str,
+ ) -> anyhow::Result<Option<i64>> {
// PHP: @file_get_contents($path)
let current_content = Silencer::call(|| Ok(file_get_contents(path)))
.ok()
@@ -303,7 +310,7 @@ impl JsonFile {
/// @return true true on success
///
/// @phpstan-param self::*_SCHEMA $schema
- pub fn validate_schema(&self, schema: i64, schema_file: Option<&str>) -> Result<bool> {
+ pub fn validate_schema(&self, schema: i64, schema_file: Option<&str>) -> anyhow::Result<bool> {
if !Filesystem::is_readable(&self.path) {
return Err(RuntimeException {
message: format!("The file \"{}\" is not readable.", self.path),
@@ -335,7 +342,7 @@ impl JsonFile {
data: &PhpMixed,
schema: i64,
schema_file: Option<&str>,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
let mut is_composer_schema_file = false;
let schema_file = match schema_file {
Some(f) => f.into(),
@@ -486,7 +493,7 @@ impl JsonFile {
///
/// @throws ParsingException
/// @return mixed
- pub fn parse_json(json: Option<&str>, file: Option<&str>) -> Result<PhpMixed> {
+ pub fn parse_json(json: Option<&str>, file: Option<&str>) -> anyhow::Result<PhpMixed> {
let json = match json {
None => return Ok(PhpMixed::Null),
Some(j) => j,
@@ -529,7 +536,7 @@ impl JsonFile {
/// @throws \UnexpectedValueException
/// @throws ParsingException
/// @return bool true on success
- pub(crate) fn validate_syntax(json: &str, file: Option<&str>) -> Result<bool> {
+ pub(crate) fn validate_syntax(json: &str, file: Option<&str>) -> anyhow::Result<bool> {
let mut parser = JsonParser::new();
let result = parser.lint(json);
if result.is_none() {
@@ -585,7 +592,7 @@ impl jsonschema::Retrieve for FileRetriever {
fn retrieve(
&self,
uri: &jsonschema::Uri<String>,
- ) -> Result<serde_json::Value, Box<dyn std::error::Error + Send + Sync>> {
+ ) -> anyhow::Result<serde_json::Value, Box<dyn std::error::Error + Send + Sync>> {
match uri.scheme().as_str() {
"file" => {
let file = std::fs::File::open(uri.path().as_str())?;
diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs
index 07ad11f..b85fbe6 100644
--- a/crates/shirabe/src/package/loader/array_loader.rs
+++ b/crates/shirabe/src/package/loader/array_loader.rs
@@ -15,7 +15,6 @@ use crate::package::RootPackageHandle;
use crate::package::SUPPORTED_LINK_TYPES;
use crate::package::loader::LoaderInterface;
use crate::package::version::VersionParser;
-use anyhow::Result;
use chrono::Utc;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
@@ -152,7 +151,7 @@ impl LoaderInterface for ArrayLoader {
&self,
mut config: IndexMap<String, PhpMixed>,
class: Option<String>,
- ) -> Result<PackageInterfaceHandle> {
+ ) -> anyhow::Result<PackageInterfaceHandle> {
let class = class.unwrap_or_else(|| "Composer\\Package\\CompletePackage".to_string());
if class != "Composer\\Package\\CompletePackage"
@@ -199,7 +198,7 @@ impl ArrayLoader {
pub fn load_packages(
&self,
versions: Vec<IndexMap<String, PhpMixed>>,
- ) -> Result<Vec<PackageInterfaceHandle>> {
+ ) -> anyhow::Result<Vec<PackageInterfaceHandle>> {
let mut packages: Vec<PackageInterfaceHandle> = vec![];
let mut link_cache: IndexMap<
String,
@@ -222,7 +221,7 @@ impl ArrayLoader {
&self,
config: &IndexMap<String, PhpMixed>,
class: &str,
- ) -> Result<CompleteOrRootPackage> {
+ ) -> anyhow::Result<CompleteOrRootPackage> {
if !config.contains_key("name") {
return Err(UnexpectedValueException {
message: format!(
@@ -312,7 +311,7 @@ impl ArrayLoader {
&self,
mut package: CompleteOrRootPackage,
config: &mut IndexMap<String, PhpMixed>,
- ) -> Result<PackageInterfaceHandle> {
+ ) -> anyhow::Result<PackageInterfaceHandle> {
package
.package_mut()
.set_type(if let Some(t) = config.get("type") {
@@ -704,7 +703,7 @@ impl ArrayLoader {
>,
package: &mut CompleteOrRootPackage,
config: &IndexMap<String, PhpMixed>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let name = package.get_name().to_string();
let pretty_version = package.get_pretty_version().to_string();
@@ -786,7 +785,7 @@ impl ArrayLoader {
source_version: &str,
description: &str,
links: IndexMap<String, PhpMixed>,
- ) -> Result<IndexMap<String, Link>> {
+ ) -> anyhow::Result<IndexMap<String, Link>> {
let mut res: IndexMap<String, Link> = IndexMap::new();
for (target, constraint) in links {
if !is_string(&constraint) {
@@ -818,7 +817,7 @@ impl ArrayLoader {
description: &str,
target: &str,
pretty_constraint: &str,
- ) -> Result<Link> {
+ ) -> anyhow::Result<Link> {
// PHP: if (!\is_string($prettyConstraint)) — always true in Rust signature, kept for parity
let _ = pretty_constraint;
@@ -856,7 +855,10 @@ impl ArrayLoader {
/// @param mixed[] $config the entire package config
///
/// @return string|null normalized version of the branch alias or null if there is none
- pub fn get_branch_alias(&self, config: &IndexMap<String, PhpMixed>) -> Result<Option<String>> {
+ pub fn get_branch_alias(
+ &self,
+ config: &IndexMap<String, PhpMixed>,
+ ) -> anyhow::Result<Option<String>> {
if !config.contains_key("version") || !is_scalar(config.get("version").unwrap()) {
return Err(UnexpectedValueException {
message: "no/invalid version defined".to_string(),
diff --git a/crates/shirabe/src/package/loader/json_loader.rs b/crates/shirabe/src/package/loader/json_loader.rs
index d48a2fe..205028f 100644
--- a/crates/shirabe/src/package/loader/json_loader.rs
+++ b/crates/shirabe/src/package/loader/json_loader.rs
@@ -3,7 +3,6 @@
use crate::json::JsonFile;
use crate::package::PackageInterfaceHandle;
use crate::package::loader::LoaderInterface;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{PhpMixed, TypeError};
use std::path::Path;
@@ -22,7 +21,7 @@ impl JsonLoader {
Self { loader }
}
- pub fn load(&self, json: JsonLoaderInput) -> Result<PackageInterfaceHandle> {
+ pub fn load(&self, json: JsonLoaderInput) -> anyhow::Result<PackageInterfaceHandle> {
let config = match json {
JsonLoaderInput::File(mut json_file) => json_file.read()?,
JsonLoaderInput::String(ref s) if Path::new(s).exists() => {
diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs
index 09c2def..94f4625 100644
--- a/crates/shirabe/src/package/locker.rs
+++ b/crates/shirabe/src/package/locker.rs
@@ -23,7 +23,6 @@ use crate::repository::RepositoryInterfaceHandle;
use crate::repository::RootPackageRepository;
use crate::util::Git as GitUtil;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::seld::json_lint::ParsingException;
@@ -84,7 +83,7 @@ impl Locker {
}
/// Returns the md5 hash of the sorted content of the composer file.
- pub fn get_content_hash(composer_file_contents: &str) -> Result<String> {
+ pub fn get_content_hash(composer_file_contents: &str) -> anyhow::Result<String> {
let content = JsonFile::parse_json(Some(composer_file_contents), Some("composer.json"))?;
let content_map: IndexMap<String, PhpMixed> = match &content {
PhpMixed::Array(m) => m.iter().map(|(k, v)| (k.clone(), v.clone())).collect(),
@@ -151,7 +150,7 @@ impl Locker {
}
/// Checks whether the lock file is still up to date with the current hash
- pub fn is_fresh(&mut self) -> Result<bool> {
+ pub fn is_fresh(&mut self) -> anyhow::Result<bool> {
let lock = self.lock_file.read()?;
let lock_map: IndexMap<String, PhpMixed> = match lock {
PhpMixed::Array(m) => m.into_iter().collect(),
@@ -182,7 +181,7 @@ impl Locker {
pub fn get_locked_repository(
&mut self,
with_dev_reqs: bool,
- ) -> Result<LockArrayRepositoryHandle> {
+ ) -> anyhow::Result<LockArrayRepositoryHandle> {
let lock_data = self.get_lock_data()?;
let packages: LockArrayRepositoryHandle =
LockArrayRepositoryHandle::new(LockArrayRepository::new(vec![])?);
@@ -281,7 +280,7 @@ impl Locker {
}
/// @return string[] Names of dependencies installed through require-dev
- pub fn get_dev_package_names(&mut self) -> Result<Vec<String>> {
+ pub fn get_dev_package_names(&mut self) -> anyhow::Result<Vec<String>> {
let mut names: Vec<String> = vec![];
let lock_data = self.get_lock_data()?;
if let Some(PhpMixed::List(list)) = lock_data.get("packages-dev") {
@@ -298,7 +297,7 @@ impl Locker {
}
/// Returns the platform requirements stored in the lock file
- pub fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> Result<Vec<Link>> {
+ pub fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> anyhow::Result<Vec<Link>> {
let lock_data = self.get_lock_data()?;
let mut requirements: IndexMap<String, Link> = IndexMap::new();
@@ -341,7 +340,7 @@ impl Locker {
}
/// @return key-of<BasePackage::STABILITIES>
- pub fn get_minimum_stability(&mut self) -> Result<String> {
+ pub fn get_minimum_stability(&mut self) -> anyhow::Result<String> {
let lock_data = self.get_lock_data()?;
Ok(lock_data
@@ -352,7 +351,7 @@ impl Locker {
}
/// @return array<string, string>
- pub fn get_stability_flags(&mut self) -> Result<IndexMap<String, String>> {
+ pub fn get_stability_flags(&mut self) -> anyhow::Result<IndexMap<String, String>> {
let lock_data = self.get_lock_data()?;
Ok(lock_data
@@ -368,7 +367,7 @@ impl Locker {
.unwrap_or_default())
}
- pub fn get_prefer_stable(&mut self) -> Result<Option<bool>> {
+ pub fn get_prefer_stable(&mut self) -> anyhow::Result<Option<bool>> {
let lock_data = self.get_lock_data()?;
// return null if not set to allow caller logic to choose the
@@ -376,14 +375,14 @@ impl Locker {
Ok(lock_data.get("prefer-stable").and_then(|v| v.as_bool()))
}
- pub fn get_prefer_lowest(&mut self) -> Result<Option<bool>> {
+ pub fn get_prefer_lowest(&mut self) -> anyhow::Result<Option<bool>> {
let lock_data = self.get_lock_data()?;
Ok(lock_data.get("prefer-lowest").and_then(|v| v.as_bool()))
}
/// @return array<string, string>
- pub fn get_platform_overrides(&mut self) -> Result<IndexMap<String, String>> {
+ pub fn get_platform_overrides(&mut self) -> anyhow::Result<IndexMap<String, String>> {
let lock_data = self.get_lock_data()?;
Ok(lock_data
@@ -400,7 +399,7 @@ impl Locker {
}
/// @return string[][]
- pub fn get_aliases(&mut self) -> Result<Vec<IndexMap<String, String>>> {
+ pub fn get_aliases(&mut self) -> anyhow::Result<Vec<IndexMap<String, String>>> {
let lock_data = self.get_lock_data()?;
Ok(lock_data
@@ -425,7 +424,7 @@ impl Locker {
.unwrap_or_default())
}
- pub fn get_plugin_api(&mut self) -> Result<String> {
+ pub fn get_plugin_api(&mut self) -> anyhow::Result<String> {
let lock_data = self.get_lock_data()?;
Ok(lock_data
@@ -436,7 +435,7 @@ impl Locker {
}
/// @return array<string, mixed>
- pub fn get_lock_data(&mut self) -> Result<IndexMap<String, PhpMixed>> {
+ pub fn get_lock_data(&mut self) -> anyhow::Result<IndexMap<String, PhpMixed>> {
if let Some(cache) = self.lock_data_cache.borrow().clone() {
return Ok(cache);
}
@@ -473,7 +472,7 @@ impl Locker {
prefer_lowest: bool,
platform_overrides: IndexMap<String, PhpMixed>,
write: bool,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
// keep old default branch names normalized to DEFAULT_BRANCH_ALIAS for BC as that is how Composer 1 outputs the lock file
// when loading the lock file the version is anyway ignored in Composer 2, so it has no adverse effect
let aliases: Vec<IndexMap<String, PhpMixed>> = array_map(
@@ -635,7 +634,7 @@ impl Locker {
Ok(false)
}
- fn is_locked_result(&mut self) -> Result<bool> {
+ fn is_locked_result(&mut self) -> anyhow::Result<bool> {
Ok(self.is_locked())
}
@@ -646,7 +645,7 @@ impl Locker {
data_processor: Option<
Box<dyn FnOnce(IndexMap<String, PhpMixed>) -> IndexMap<String, PhpMixed>>,
>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let contents = file_get_contents(composer_json.get_path());
let contents = match contents {
Some(s) => s,
@@ -719,7 +718,7 @@ impl Locker {
}
/// @param PackageInterface[] $packages
- fn lock_packages(&mut self, packages: &[PackageInterfaceHandle]) -> Result<PhpMixed> {
+ fn lock_packages(&mut self, packages: &[PackageInterfaceHandle]) -> anyhow::Result<PhpMixed> {
let mut locked: Vec<IndexMap<String, PhpMixed>> = vec![];
for package in packages {
@@ -791,7 +790,10 @@ impl Locker {
}
/// Returns the packages's datetime for its source reference.
- fn get_package_time(&mut self, package: PackageInterfaceHandle) -> Result<Option<String>> {
+ fn get_package_time(
+ &mut self,
+ package: PackageInterfaceHandle,
+ ) -> anyhow::Result<Option<String>> {
if !function_exists("proc_open") {
return Ok(None);
}
@@ -895,7 +897,7 @@ impl Locker {
&mut self,
package: RootPackageInterfaceHandle,
include_dev: bool,
- ) -> Result<Vec<String>> {
+ ) -> anyhow::Result<Vec<String>> {
let mut missing_requirement_info: Vec<String> = vec![];
let mut missing_requirements = false;
let mut sets: Vec<SetEntry> = vec![SetEntry {
@@ -1006,18 +1008,21 @@ impl Locker {
pub trait LockerInterface: std::fmt::Debug {
fn get_json_file(&self) -> &JsonFile;
fn is_locked(&mut self) -> bool;
- fn is_fresh(&mut self) -> Result<bool>;
- fn get_locked_repository(&mut self, with_dev_reqs: bool) -> Result<LockArrayRepositoryHandle>;
- fn get_dev_package_names(&mut self) -> Result<Vec<String>>;
- fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> Result<Vec<Link>>;
- fn get_minimum_stability(&mut self) -> Result<String>;
- fn get_stability_flags(&mut self) -> Result<IndexMap<String, String>>;
- fn get_prefer_stable(&mut self) -> Result<Option<bool>>;
- fn get_prefer_lowest(&mut self) -> Result<Option<bool>>;
- fn get_platform_overrides(&mut self) -> Result<IndexMap<String, String>>;
- fn get_aliases(&mut self) -> Result<Vec<IndexMap<String, String>>>;
- fn get_plugin_api(&mut self) -> Result<String>;
- fn get_lock_data(&mut self) -> Result<IndexMap<String, PhpMixed>>;
+ fn is_fresh(&mut self) -> anyhow::Result<bool>;
+ fn get_locked_repository(
+ &mut self,
+ with_dev_reqs: bool,
+ ) -> anyhow::Result<LockArrayRepositoryHandle>;
+ fn get_dev_package_names(&mut self) -> anyhow::Result<Vec<String>>;
+ fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> anyhow::Result<Vec<Link>>;
+ fn get_minimum_stability(&mut self) -> anyhow::Result<String>;
+ fn get_stability_flags(&mut self) -> anyhow::Result<IndexMap<String, String>>;
+ fn get_prefer_stable(&mut self) -> anyhow::Result<Option<bool>>;
+ fn get_prefer_lowest(&mut self) -> anyhow::Result<Option<bool>>;
+ fn get_platform_overrides(&mut self) -> anyhow::Result<IndexMap<String, String>>;
+ fn get_aliases(&mut self) -> anyhow::Result<Vec<IndexMap<String, String>>>;
+ fn get_plugin_api(&mut self) -> anyhow::Result<String>;
+ fn get_lock_data(&mut self) -> anyhow::Result<IndexMap<String, PhpMixed>>;
#[allow(clippy::too_many_arguments, reason = "to keep PHP signature")]
fn set_lock_data(
&mut self,
@@ -1032,19 +1037,19 @@ pub trait LockerInterface: std::fmt::Debug {
prefer_lowest: bool,
platform_overrides: IndexMap<String, PhpMixed>,
write: bool,
- ) -> Result<bool>;
+ ) -> anyhow::Result<bool>;
fn update_hash(
&mut self,
composer_json: &JsonFile,
data_processor: Option<
Box<dyn FnOnce(IndexMap<String, PhpMixed>) -> IndexMap<String, PhpMixed>>,
>,
- ) -> Result<()>;
+ ) -> anyhow::Result<()>;
fn get_missing_requirement_info(
&mut self,
package: RootPackageInterfaceHandle,
include_dev: bool,
- ) -> Result<Vec<String>>;
+ ) -> anyhow::Result<Vec<String>>;
}
impl LockerInterface for Locker {
@@ -1056,51 +1061,54 @@ impl LockerInterface for Locker {
self.is_locked()
}
- fn is_fresh(&mut self) -> Result<bool> {
+ fn is_fresh(&mut self) -> anyhow::Result<bool> {
self.is_fresh()
}
- fn get_locked_repository(&mut self, with_dev_reqs: bool) -> Result<LockArrayRepositoryHandle> {
+ fn get_locked_repository(
+ &mut self,
+ with_dev_reqs: bool,
+ ) -> anyhow::Result<LockArrayRepositoryHandle> {
self.get_locked_repository(with_dev_reqs)
}
- fn get_dev_package_names(&mut self) -> Result<Vec<String>> {
+ fn get_dev_package_names(&mut self) -> anyhow::Result<Vec<String>> {
self.get_dev_package_names()
}
- fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> Result<Vec<Link>> {
+ fn get_platform_requirements(&mut self, with_dev_reqs: bool) -> anyhow::Result<Vec<Link>> {
self.get_platform_requirements(with_dev_reqs)
}
- fn get_minimum_stability(&mut self) -> Result<String> {
+ fn get_minimum_stability(&mut self) -> anyhow::Result<String> {
self.get_minimum_stability()
}
- fn get_stability_flags(&mut self) -> Result<IndexMap<String, String>> {
+ fn get_stability_flags(&mut self) -> anyhow::Result<IndexMap<String, String>> {
self.get_stability_flags()
}
- fn get_prefer_stable(&mut self) -> Result<Option<bool>> {
+ fn get_prefer_stable(&mut self) -> anyhow::Result<Option<bool>> {
self.get_prefer_stable()
}
- fn get_prefer_lowest(&mut self) -> Result<Option<bool>> {
+ fn get_prefer_lowest(&mut self) -> anyhow::Result<Option<bool>> {
self.get_prefer_lowest()
}
- fn get_platform_overrides(&mut self) -> Result<IndexMap<String, String>> {
+ fn get_platform_overrides(&mut self) -> anyhow::Result<IndexMap<String, String>> {
self.get_platform_overrides()
}
- fn get_aliases(&mut self) -> Result<Vec<IndexMap<String, String>>> {
+ fn get_aliases(&mut self) -> anyhow::Result<Vec<IndexMap<String, String>>> {
self.get_aliases()
}
- fn get_plugin_api(&mut self) -> Result<String> {
+ fn get_plugin_api(&mut self) -> anyhow::Result<String> {
self.get_plugin_api()
}
- fn get_lock_data(&mut self) -> Result<IndexMap<String, PhpMixed>> {
+ fn get_lock_data(&mut self) -> anyhow::Result<IndexMap<String, PhpMixed>> {
self.get_lock_data()
}
@@ -1118,7 +1126,7 @@ impl LockerInterface for Locker {
prefer_lowest: bool,
platform_overrides: IndexMap<String, PhpMixed>,
write: bool,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
self.set_lock_data(
packages,
dev_packages,
@@ -1140,7 +1148,7 @@ impl LockerInterface for Locker {
data_processor: Option<
Box<dyn FnOnce(IndexMap<String, PhpMixed>) -> IndexMap<String, PhpMixed>>,
>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
self.update_hash(composer_json, data_processor)
}
@@ -1148,7 +1156,7 @@ impl LockerInterface for Locker {
&mut self,
package: RootPackageInterfaceHandle,
include_dev: bool,
- ) -> Result<Vec<String>> {
+ ) -> anyhow::Result<Vec<String>> {
self.get_missing_requirement_info(package, include_dev)
}
}
diff --git a/crates/shirabe/src/package/version/version_bumper.rs b/crates/shirabe/src/package/version/version_bumper.rs
index 4deb450..4f2d324 100644
--- a/crates/shirabe/src/package/version/version_bumper.rs
+++ b/crates/shirabe/src/package/version/version_bumper.rs
@@ -5,7 +5,6 @@ use crate::package::dumper::ArrayDumper;
use crate::package::loader::ArrayLoader;
use crate::package::version::VersionParser;
use crate::util::Platform;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_semver::Intervals;
@@ -19,7 +18,7 @@ impl VersionBumper {
&self,
constraint: &AnyConstraint,
package: PackageInterfaceHandle,
- ) -> Result<String> {
+ ) -> anyhow::Result<String> {
let parser = VersionParser::new();
let pretty_constraint = constraint.get_pretty_string();
if pretty_constraint.starts_with("dev-") {
diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs
index 6fba7c4..249646c 100644
--- a/crates/shirabe/src/package/version/version_guesser.rs
+++ b/crates/shirabe/src/package/version/version_guesser.rs
@@ -11,7 +11,6 @@ use crate::util::Platform;
use crate::util::ProcessExecutor;
use crate::util::Svn as SvnUtil;
use crate::util::sync_executor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
@@ -28,9 +27,9 @@ pub trait VersionGuesserInterface: std::fmt::Debug {
&mut self,
package_config: &IndexMap<String, PhpMixed>,
path: &str,
- ) -> Result<Option<VersionData>>;
+ ) -> anyhow::Result<Option<VersionData>>;
- fn get_root_version_from_env(&self) -> Result<String>;
+ fn get_root_version_from_env(&self) -> anyhow::Result<String>;
}
/// Try to guess the current version number based on different VCS configuration.
@@ -103,7 +102,7 @@ impl VersionGuesser {
&mut self,
package_config: &IndexMap<String, PhpMixed>,
path: &str,
- ) -> Result<Option<VersionData>> {
+ ) -> anyhow::Result<Option<VersionData>> {
// For testing only (ref VersionGuesserMock::guessVersion returns null).
if self.mock {
return Ok(None);
@@ -207,7 +206,7 @@ impl VersionGuesser {
&mut self,
package_config: &IndexMap<String, PhpMixed>,
path: &str,
- ) -> Result<VersionData> {
+ ) -> anyhow::Result<VersionData> {
GitUtil::clean_env(&self.process);
let mut commit: Option<String> = None;
let mut version: Option<String> = None;
@@ -365,7 +364,7 @@ impl VersionGuesser {
}
/// @return array{version: string, pretty_version: string}|null
- fn version_from_git_tags(&mut self, path: &str) -> Result<Option<(String, String)>> {
+ fn version_from_git_tags(&mut self, path: &str) -> anyhow::Result<Option<(String, String)>> {
// try to fetch current version from git tags
let mut output = String::new();
if 0 == self.process.borrow_mut().execute_args(
@@ -394,7 +393,7 @@ impl VersionGuesser {
&mut self,
package_config: &IndexMap<String, PhpMixed>,
path: &str,
- ) -> Result<Option<VersionData>> {
+ ) -> anyhow::Result<Option<VersionData>> {
// try to fetch current version from hg branch
let mut output = String::new();
if 0 == self.process.borrow_mut().execute_args(
@@ -492,7 +491,7 @@ impl VersionGuesser {
mut branches: Vec<String>,
scm_cmdline: Vec<String>,
path: &str,
- ) -> Result<FeatureVersionResult> {
+ ) -> anyhow::Result<FeatureVersionResult> {
let mut pretty_version: Option<String> = version.clone();
let mut version = version;
@@ -546,7 +545,7 @@ impl VersionGuesser {
// PHP runs every candidate diff in parallel and cancels the siblings once a zero-length
// diff is found; the single-threaded sync bridge block_on's each diff serially and stops
// at the first zero-length match.
- let result: Result<()> = (|| -> Result<()> {
+ let result: anyhow::Result<()> = (|| -> anyhow::Result<()> {
let mut last_index: i64 = -1;
for (index, candidate) in branches.iter().enumerate() {
let index = index as i64;
@@ -635,7 +634,7 @@ impl VersionGuesser {
}
/// @return array{version: string|null, commit: '', pretty_version: string|null}
- fn guess_fossil_version(&mut self, path: &str) -> Result<VersionData> {
+ fn guess_fossil_version(&mut self, path: &str) -> anyhow::Result<VersionData> {
let mut version: Option<String> = None;
let mut pretty_version: Option<String> = None;
@@ -687,7 +686,7 @@ impl VersionGuesser {
&mut self,
package_config: &IndexMap<String, PhpMixed>,
path: &str,
- ) -> Result<Option<VersionData>> {
+ ) -> anyhow::Result<Option<VersionData>> {
SvnUtil::clean_env();
// try to fetch current version from svn
@@ -760,7 +759,7 @@ impl VersionGuesser {
Ok(None)
}
- pub fn get_root_version_from_env(&self) -> Result<String> {
+ pub fn get_root_version_from_env(&self) -> anyhow::Result<String> {
let version = Platform::get_env("COMPOSER_ROOT_VERSION");
let version = match version {
Some(v) if !v.is_empty() => v,
@@ -789,11 +788,11 @@ impl VersionGuesserInterface for VersionGuesser {
&mut self,
package_config: &IndexMap<String, PhpMixed>,
path: &str,
- ) -> Result<Option<VersionData>> {
+ ) -> anyhow::Result<Option<VersionData>> {
VersionGuesser::guess_version(self, package_config, path)
}
- fn get_root_version_from_env(&self) -> Result<String> {
+ fn get_root_version_from_env(&self) -> anyhow::Result<String> {
VersionGuesser::get_root_version_from_env(self)
}
}
diff --git a/crates/shirabe/src/platform/runtime.rs b/crates/shirabe/src/platform/runtime.rs
index fcee930..255aa9d 100644
--- a/crates/shirabe/src/platform/runtime.rs
+++ b/crates/shirabe/src/platform/runtime.rs
@@ -1,6 +1,5 @@
//! ref: composer/src/Composer/Platform/Runtime.php
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
@@ -19,10 +18,10 @@ pub trait RuntimeInterface: std::fmt::Debug {
/// `[class, method]` list), matching PHP `invoke($callable, $arguments)`.
fn invoke(&self, callable: PhpMixed, arguments: Vec<PhpMixed>) -> PhpMixed;
fn has_class(&self, class: &str) -> bool;
- fn construct(&self, class: &str, arguments: Vec<PhpMixed>) -> Result<PhpMixed>;
+ fn construct(&self, class: &str, arguments: Vec<PhpMixed>) -> anyhow::Result<PhpMixed>;
fn get_extensions(&self) -> Vec<String>;
fn get_extension_version(&self, extension: &str) -> String;
- fn get_extension_info(&self, extension: &str) -> Result<String>;
+ fn get_extension_info(&self, extension: &str) -> anyhow::Result<String>;
}
#[derive(Debug)]
@@ -54,7 +53,7 @@ impl RuntimeInterface for Runtime {
class_exists(class)
}
- fn construct(&self, class: &str, arguments: Vec<PhpMixed>) -> Result<PhpMixed> {
+ fn construct(&self, class: &str, arguments: Vec<PhpMixed>) -> anyhow::Result<PhpMixed> {
if arguments.is_empty() {
Ok(instantiate_class(class, vec![]))
} else {
@@ -71,7 +70,7 @@ impl RuntimeInterface for Runtime {
version.unwrap_or_else(|| "0".to_string())
}
- fn get_extension_info(&self, extension: &str) -> Result<String> {
+ fn get_extension_info(&self, extension: &str) -> anyhow::Result<String> {
// Depends on \ReflectionExtension::info() and output buffering; no shim equivalent exists.
let _ = extension;
todo!()
diff --git a/crates/shirabe/src/repository/array_repository.rs b/crates/shirabe/src/repository/array_repository.rs
index eec49f2..dc31baa 100644
--- a/crates/shirabe/src/repository/array_repository.rs
+++ b/crates/shirabe/src/repository/array_repository.rs
@@ -11,7 +11,6 @@ use crate::repository::{
AbandonedInfo, FindPackageConstraint, LoadPackagesResult, ProviderInfo, RepositoryInterface,
RepositoryInterfaceHandle, RepositoryInterfaceWeakHandle, SearchResult,
};
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{implode, preg_quote, strtolower};
@@ -119,7 +118,7 @@ impl ArrayRepository {
}
/// @param array<PackageInterface> $packages
- pub fn new(packages: Vec<PackageInterfaceHandle>) -> Result<Self> {
+ pub fn new(packages: Vec<PackageInterfaceHandle>) -> anyhow::Result<Self> {
let this = Self {
packages: RefCell::new(None),
package_map: RefCell::new(None),
@@ -132,7 +131,7 @@ impl ArrayRepository {
}
/// Adds a new package to the repository
- pub fn add_package(&self, package: PackageInterfaceHandle) -> Result<()> {
+ pub fn add_package(&self, package: PackageInterfaceHandle) -> anyhow::Result<()> {
if self.packages.borrow().is_none() {
self.initialize();
}
diff --git a/crates/shirabe/src/repository/filesystem_repository.rs b/crates/shirabe/src/repository/filesystem_repository.rs
index ebe7600..0e17841 100644
--- a/crates/shirabe/src/repository/filesystem_repository.rs
+++ b/crates/shirabe/src/repository/filesystem_repository.rs
@@ -18,7 +18,6 @@ use crate::repository::{FindPackageConstraint, LoadPackagesResult, ProviderInfo,
use crate::util::Filesystem;
use crate::util::Platform;
use crate::util::Silencer;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
@@ -55,7 +54,7 @@ impl FilesystemRepository {
dump_versions: bool,
root_package: Option<RootPackageInterfaceHandle>,
filesystem: Option<std::rc::Rc<std::cell::RefCell<Filesystem>>>,
- ) -> Result<Self> {
+ ) -> anyhow::Result<Self> {
let filesystem = filesystem
.unwrap_or_else(|| std::rc::Rc::new(std::cell::RefCell::new(Filesystem::new(None))));
if dump_versions && root_package.is_none() {
@@ -88,7 +87,7 @@ impl FilesystemRepository {
self.inner.get_repo_name()
}
- fn ensure_initialized(&mut self) -> Result<()> {
+ fn ensure_initialized(&mut self) -> anyhow::Result<()> {
if !self.inner.is_initialized() {
self.initialize()?;
}
@@ -96,14 +95,14 @@ impl FilesystemRepository {
}
/// Initializes repository (reads file, or remote address).
- pub(crate) fn initialize(&mut self) -> Result<()> {
+ pub(crate) fn initialize(&mut self) -> anyhow::Result<()> {
self.inner.initialize();
if !self.file.exists() {
return Ok(());
}
- let packages: PhpMixed = match (|| -> Result<PhpMixed> {
+ let packages: PhpMixed = match (|| -> anyhow::Result<PhpMixed> {
let data = self.file.read()?;
let packages_value = if let PhpMixed::Array(ref m) = data {
if m.contains_key("packages") {
@@ -177,20 +176,20 @@ impl FilesystemRepository {
Ok(())
}
- pub fn reload(&mut self) -> Result<()> {
+ pub fn reload(&mut self) -> anyhow::Result<()> {
self.inner.reset_packages();
self.initialize()
}
- pub fn add_package(&mut self, package: PackageInterfaceHandle) -> Result<()> {
+ pub fn add_package(&mut self, package: PackageInterfaceHandle) -> anyhow::Result<()> {
self.inner.add_package(package)
}
- pub fn remove_package(&mut self, package: PackageInterfaceHandle) -> Result<()> {
+ pub fn remove_package(&mut self, package: PackageInterfaceHandle) -> anyhow::Result<()> {
self.inner.remove_package(package)
}
- pub fn get_canonical_packages(&mut self) -> Result<Vec<PackageInterfaceHandle>> {
+ pub fn get_canonical_packages(&mut self) -> anyhow::Result<Vec<PackageInterfaceHandle>> {
self.ensure_initialized()?;
Ok(self.inner.get_canonical_packages())
}
@@ -208,7 +207,7 @@ impl FilesystemRepository {
&mut self,
dev_mode: bool,
installation_manager: &mut dyn InstallationManagerInterface,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let mut data: IndexMap<String, PhpMixed> = IndexMap::new();
data.insert("packages".to_string(), PhpMixed::List(vec![]));
data.insert("dev".to_string(), PhpMixed::Bool(dev_mode));
@@ -455,7 +454,7 @@ impl FilesystemRepository {
install_paths: &IndexMap<String, Option<String>>,
dev_mode: bool,
repo_dir: &str,
- ) -> Result<IndexMap<String, PhpMixed>> {
+ ) -> anyhow::Result<IndexMap<String, PhpMixed>> {
let dev_packages = array_flip(&PhpMixed::List(
self.inner
.dev_package_names
@@ -757,7 +756,7 @@ impl FilesystemRepository {
}
impl RepositoryInterface for FilesystemRepository {
- fn count(&self) -> Result<usize> {
+ fn count(&self) -> anyhow::Result<usize> {
self.inner.count()
}
@@ -769,7 +768,7 @@ impl RepositoryInterface for FilesystemRepository {
&mut self,
name: &str,
constraint: FindPackageConstraint,
- ) -> Result<Option<BasePackageHandle>> {
+ ) -> anyhow::Result<Option<BasePackageHandle>> {
self.ensure_initialized()?;
self.inner.find_package(name, constraint)
}
@@ -778,12 +777,12 @@ impl RepositoryInterface for FilesystemRepository {
&mut self,
name: &str,
constraint: Option<FindPackageConstraint>,
- ) -> Result<Vec<BasePackageHandle>> {
+ ) -> anyhow::Result<Vec<BasePackageHandle>> {
self.ensure_initialized()?;
self.inner.find_packages(name, constraint)
}
- fn get_packages(&mut self) -> Result<Vec<BasePackageHandle>> {
+ fn get_packages(&mut self) -> anyhow::Result<Vec<BasePackageHandle>> {
self.ensure_initialized()?;
self.inner.get_packages()
}
@@ -794,7 +793,7 @@ impl RepositoryInterface for FilesystemRepository {
acceptable_stabilities: IndexMap<String, i64>,
stability_flags: IndexMap<String, i64>,
already_loaded: IndexMap<String, IndexMap<String, PackageInterfaceHandle>>,
- ) -> Result<LoadPackagesResult> {
+ ) -> anyhow::Result<LoadPackagesResult> {
self.ensure_initialized()?;
self.inner.load_packages(
package_name_map,
@@ -809,12 +808,15 @@ impl RepositoryInterface for FilesystemRepository {
query: String,
mode: i64,
r#type: Option<String>,
- ) -> Result<Vec<SearchResult>> {
+ ) -> anyhow::Result<Vec<SearchResult>> {
self.ensure_initialized()?;
self.inner.search(query, mode, r#type)
}
- fn get_providers(&mut self, package_name: String) -> Result<IndexMap<String, ProviderInfo>> {
+ fn get_providers(
+ &mut self,
+ package_name: String,
+ ) -> anyhow::Result<IndexMap<String, ProviderInfo>> {
self.ensure_initialized()?;
self.inner.get_providers(package_name)
}
diff --git a/crates/shirabe/src/repository/filter_repository.rs b/crates/shirabe/src/repository/filter_repository.rs
index 0882973..bdf17c5 100644
--- a/crates/shirabe/src/repository/filter_repository.rs
+++ b/crates/shirabe/src/repository/filter_repository.rs
@@ -8,7 +8,6 @@ use crate::repository::{
FindPackageConstraint, LoadPackagesResult, ProviderInfo, RepositoryInterface,
RepositoryInterfaceHandle, SearchResult,
};
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{InvalidArgumentException, PhpMixed};
@@ -26,7 +25,7 @@ impl FilterRepository {
pub fn new(
repo: RepositoryInterfaceHandle,
options: IndexMap<String, PhpMixed>,
- ) -> Result<Self> {
+ ) -> anyhow::Result<Self> {
let mut only: Option<String> = None;
let mut exclude: Option<String> = None;
let mut canonical = true;
diff --git a/crates/shirabe/src/repository/installed_filesystem_repository.rs b/crates/shirabe/src/repository/installed_filesystem_repository.rs
index 8ce07e4..9d505cb 100644
--- a/crates/shirabe/src/repository/installed_filesystem_repository.rs
+++ b/crates/shirabe/src/repository/installed_filesystem_repository.rs
@@ -12,7 +12,6 @@ use crate::repository::{
FindPackageConstraint, LoadPackagesResult, ProviderInfo, RepositoryInterface, SearchResult,
};
use crate::util::Filesystem;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_semver::constraint::AnyConstraint;
@@ -30,7 +29,7 @@ impl InstalledFilesystemRepository {
dump_versions: bool,
root_package: Option<RootPackageInterfaceHandle>,
filesystem: Option<std::rc::Rc<std::cell::RefCell<Filesystem>>>,
- ) -> Result<Self> {
+ ) -> anyhow::Result<Self> {
Ok(Self {
inner: FilesystemRepository::new(
repository_file,
@@ -49,7 +48,7 @@ impl InstalledFilesystemRepository {
dump_versions: bool,
root_package: Option<RootPackageInterfaceHandle>,
filesystem: Option<std::rc::Rc<std::cell::RefCell<Filesystem>>>,
- ) -> Result<Self> {
+ ) -> anyhow::Result<Self> {
Ok(Self {
mock: true,
..Self::new(repository_file, dump_versions, root_package, filesystem)?
diff --git a/crates/shirabe/src/repository/repository_set.rs b/crates/shirabe/src/repository/repository_set.rs
index c19f61a..b858151 100644
--- a/crates/shirabe/src/repository/repository_set.rs
+++ b/crates/shirabe/src/repository/repository_set.rs
@@ -20,7 +20,6 @@ use crate::repository::InstalledRepository;
use crate::repository::LockArrayRepositoryHandle;
use crate::repository::PlatformRepository;
use crate::repository::{FindPackageConstraint, RepositoryInterfaceHandle};
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{LogicException, RuntimeException, ksort, strtolower};
use shirabe_semver::constraint::AnyConstraint;
@@ -161,7 +160,7 @@ impl RepositorySet {
/// repository the search for that package ends, and following repos will not be consulted.
///
/// @param RepositoryInterface $repo A package repository
- pub fn add_repository(&mut self, repo: RepositoryInterfaceHandle) -> Result<()> {
+ pub fn add_repository(&mut self, repo: RepositoryInterfaceHandle) -> anyhow::Result<()> {
if self.locked {
return Err(RuntimeException {
message: "Pool has already been created from this repository set, it cannot be modified anymore.".to_string(),
@@ -276,7 +275,7 @@ impl RepositorySet {
package_names: Vec<String>,
allow_partial_advisories: bool,
ignore_unreachable: bool,
- ) -> Result<SecurityAdvisoriesResult> {
+ ) -> anyhow::Result<SecurityAdvisoriesResult> {
let mut map: IndexMap<String, AnyConstraint> = IndexMap::new();
for name in &package_names {
map.insert(name.clone(), MatchAllConstraint::new(None).into());
@@ -303,7 +302,7 @@ impl RepositorySet {
packages: Vec<PackageInterfaceHandle>,
allow_partial_advisories: bool,
ignore_unreachable: bool,
- ) -> Result<SecurityAdvisoriesResult> {
+ ) -> anyhow::Result<SecurityAdvisoriesResult> {
let mut map: IndexMap<String, AnyConstraint> = IndexMap::new();
for package in packages {
// ignore root alias versions as they are not actual package versions and should not matter when it comes to vulnerabilities
@@ -363,10 +362,10 @@ impl RepositorySet {
allow_partial_advisories: bool,
ignore_unreachable: bool,
unreachable_repos: &mut Vec<String>,
- ) -> Result<IndexMap<String, Vec<AnySecurityAdvisory>>> {
+ ) -> anyhow::Result<IndexMap<String, Vec<AnySecurityAdvisory>>> {
let mut repo_advisories: Vec<IndexMap<String, Vec<AnySecurityAdvisory>>> = vec![];
for repository in &self.repositories {
- let attempt: Result<()> = (|| -> Result<()> {
+ let attempt: anyhow::Result<()> = (|| -> anyhow::Result<()> {
let mut repo_ref = repository.borrow_mut();
let Some(advisory_repo) = repo_ref.as_advisory_provider_mut() else {
return Ok(());
@@ -455,7 +454,7 @@ impl RepositorySet {
ignored_types: Vec<String>,
allowed_types: Option<Vec<String>>,
security_advisory_pool_filter: Option<SecurityAdvisoryPoolFilter>,
- ) -> Result<Pool> {
+ ) -> anyhow::Result<Pool> {
let root_aliases = self
.root_aliases
.iter()
@@ -511,7 +510,7 @@ impl RepositorySet {
}
/// Create a pool for dependency resolution from the packages in this repository set.
- pub fn create_pool_with_all_packages(&mut self) -> Result<Pool> {
+ pub fn create_pool_with_all_packages(&mut self) -> anyhow::Result<Pool> {
for repo in &self.repositories {
let is_installed = {
let repo_ref = repo.borrow();
@@ -581,7 +580,7 @@ impl RepositorySet {
&mut self,
package_name: &str,
locked_repo: Option<LockArrayRepositoryHandle>,
- ) -> Result<Pool> {
+ ) -> anyhow::Result<Pool> {
// TODO unify this with above in some simpler version without "request"?
self.create_pool_for_packages(vec![package_name.to_string()], locked_repo)
}
@@ -591,7 +590,7 @@ impl RepositorySet {
&mut self,
package_names: Vec<String>,
locked_repo: Option<LockArrayRepositoryHandle>,
- ) -> Result<Pool> {
+ ) -> anyhow::Result<Pool> {
let mut request = Request::new(locked_repo);
let mut allowed_packages: Vec<String> = vec![];
diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
index 9557847..764a2d2 100644
--- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs
+++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
@@ -14,7 +14,6 @@ use crate::util::Forgejo;
use crate::util::ForgejoRepositoryData;
use crate::util::ForgejoUrl;
use crate::util::http::Response;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
@@ -49,7 +48,7 @@ impl ForgejoDriver {
}
}
- pub fn initialize(&mut self) -> Result<()> {
+ pub fn initialize(&mut self) -> anyhow::Result<()> {
let forgejo_url = ForgejoUrl::create(&self.inner.url)?;
self.inner.origin_url = forgejo_url.origin_url.clone();
@@ -90,7 +89,11 @@ impl ForgejoDriver {
Ok(())
}
- pub fn get_file_content(&mut self, file: &str, identifier: &str) -> Result<Option<String>> {
+ pub fn get_file_content(
+ &mut self,
+ file: &str,
+ identifier: &str,
+ ) -> anyhow::Result<Option<String>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_file_content(file, identifier);
}
@@ -177,7 +180,7 @@ impl ForgejoDriver {
pub fn get_change_date(
&mut self,
identifier: &str,
- ) -> Result<Option<chrono::DateTime<chrono::FixedOffset>>> {
+ ) -> anyhow::Result<Option<chrono::DateTime<chrono::FixedOffset>>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_change_date(identifier);
}
@@ -214,7 +217,7 @@ impl ForgejoDriver {
Ok(Some(date))
}
- pub fn get_root_identifier(&mut self) -> Result<String> {
+ pub fn get_root_identifier(&mut self) -> anyhow::Result<String> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_root_identifier();
}
@@ -227,7 +230,7 @@ impl ForgejoDriver {
.clone())
}
- pub fn get_branches(&mut self) -> Result<IndexMap<String, String>> {
+ pub fn get_branches(&mut self) -> anyhow::Result<IndexMap<String, String>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_branches();
}
@@ -270,7 +273,7 @@ impl ForgejoDriver {
Ok(self.branches.clone().unwrap_or_default())
}
- pub fn get_tags(&mut self) -> Result<IndexMap<String, String>> {
+ pub fn get_tags(&mut self) -> anyhow::Result<IndexMap<String, String>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_tags();
}
@@ -330,7 +333,7 @@ impl ForgejoDriver {
pub fn get_composer_information(
&mut self,
identifier: &str,
- ) -> Result<Option<IndexMap<String, PhpMixed>>> {
+ ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_composer_information(identifier);
}
@@ -526,7 +529,7 @@ impl ForgejoDriver {
Ok(true)
}
- fn setup_git_driver(&mut self, url: &str) -> Result<()> {
+ fn setup_git_driver(&mut self, url: &str) -> anyhow::Result<()> {
let mut git_driver = GitDriver {
inner: VcsDriverBase::new(
{
@@ -549,7 +552,7 @@ impl ForgejoDriver {
Ok(())
}
- fn fetch_repository_data(&mut self) -> Result<()> {
+ fn fetch_repository_data(&mut self) -> anyhow::Result<()> {
if self.repository_data.is_some() {
return Ok(());
}
diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
index f28a005..45c0c68 100644
--- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
@@ -13,7 +13,6 @@ use crate::repository::vcs::VcsDriverBase;
use crate::repository::vcs::VcsDriverInterface;
use crate::util::Bitbucket;
use crate::util::http::Response;
-use anyhow::Result;
use chrono::{DateTime, FixedOffset};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
@@ -84,7 +83,7 @@ impl GitBitbucketDriver {
}
/// @inheritDoc
- pub fn initialize(&mut self) -> Result<()> {
+ pub fn initialize(&mut self) -> anyhow::Result<()> {
let mut m: indexmap::IndexMap<CaptureKey, String> = indexmap::IndexMap::new();
if !Preg::is_match3(
r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(?:\.git|/?)?$#i",
@@ -150,7 +149,7 @@ impl GitBitbucketDriver {
/// sets some parameters which are used in other methods
///
/// @phpstan-impure
- fn get_repo_data(&mut self) -> Result<bool> {
+ fn get_repo_data(&mut self) -> anyhow::Result<bool> {
let resource = format!(
"https://api.bitbucket.org/2.0/repositories/{}/{}?{}",
self.owner.clone(),
@@ -246,7 +245,7 @@ impl GitBitbucketDriver {
pub fn get_composer_information(
&mut self,
identifier: &str,
- ) -> Result<Option<IndexMap<String, PhpMixed>>> {
+ ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> {
if let Some(fallback) = self.fallback_driver.as_mut() {
return fallback.get_composer_information(identifier);
}
@@ -416,7 +415,11 @@ impl GitBitbucketDriver {
}
/// @inheritDoc
- pub fn get_file_content(&mut self, file: &str, identifier: &str) -> Result<Option<String>> {
+ pub fn get_file_content(
+ &mut self,
+ file: &str,
+ identifier: &str,
+ ) -> anyhow::Result<Option<String>> {
if let Some(fallback) = self.fallback_driver.as_mut() {
return fallback.get_file_content(file, identifier);
}
@@ -444,7 +447,10 @@ impl GitBitbucketDriver {
}
/// @inheritDoc
- pub fn get_change_date(&mut self, identifier: &str) -> Result<Option<DateTime<FixedOffset>>> {
+ pub fn get_change_date(
+ &mut self,
+ identifier: &str,
+ ) -> anyhow::Result<Option<DateTime<FixedOffset>>> {
if let Some(fallback) = self.fallback_driver.as_mut() {
return fallback.get_change_date(identifier);
}
@@ -476,7 +482,7 @@ impl GitBitbucketDriver {
pub fn get_source(&self, identifier: &str) -> IndexMap<String, String> {
if let Some(fallback) = self.fallback_driver.as_ref() {
// TODO(phase-c): PHP getSource is infallible (: array), but the Rust trait made it
- // Result, so the fallback's Result is flattened here. The faithful fix is making the
+ // anyhow::Result, so the fallback's anyhow::Result is flattened here. The faithful fix is making the
// VcsDriverInterface get_source/get_dist infallible across all implementations.
return fallback.get_source(identifier).unwrap_or_default();
}
@@ -514,7 +520,7 @@ impl GitBitbucketDriver {
}
/// @inheritDoc
- pub fn get_tags(&mut self) -> Result<IndexMap<String, String>> {
+ pub fn get_tags(&mut self) -> anyhow::Result<IndexMap<String, String>> {
if let Some(fallback) = self.fallback_driver.as_mut() {
return fallback.get_tags();
}
@@ -593,7 +599,7 @@ impl GitBitbucketDriver {
}
/// @inheritDoc
- pub fn get_branches(&mut self) -> Result<IndexMap<String, String>> {
+ pub fn get_branches(&mut self) -> anyhow::Result<IndexMap<String, String>> {
if let Some(fallback) = self.fallback_driver.as_mut() {
return fallback.get_branches();
}
@@ -680,7 +686,7 @@ impl GitBitbucketDriver {
&mut self,
url: &str,
fetching_repo_data: bool,
- ) -> Result<Response> {
+ ) -> anyhow::Result<Response> {
match self.inner.get_contents(url) {
Ok(r) => Ok(r),
Err(e) => {
@@ -741,7 +747,7 @@ impl GitBitbucketDriver {
///
/// @return true
/// @throws \RuntimeException
- fn attempt_clone_fallback(&mut self) -> Result<bool> {
+ fn attempt_clone_fallback(&mut self) -> anyhow::Result<bool> {
match self.setup_fallback_driver(&self.generate_ssh_url()) {
Ok(()) => Ok(true),
Err(e) => {
@@ -759,7 +765,7 @@ impl GitBitbucketDriver {
}
}
- fn setup_fallback_driver(&mut self, url: &str) -> Result<()> {
+ fn setup_fallback_driver(&mut self, url: &str) -> anyhow::Result<()> {
let mut repo_config: IndexMap<String, PhpMixed> = IndexMap::new();
repo_config.insert("url".to_string(), PhpMixed::String(url.to_string()));
let mut driver = GitDriver::new(
@@ -796,7 +802,7 @@ impl GitBitbucketDriver {
}
/// @inheritDoc
- pub fn get_root_identifier(&mut self) -> Result<String> {
+ pub fn get_root_identifier(&mut self) -> anyhow::Result<String> {
if let Some(fallback) = self.fallback_driver.as_mut() {
return fallback.get_root_identifier();
}
diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs
index e8e67ea..d68bf4e 100644
--- a/crates/shirabe/src/repository/vcs/github_driver.rs
+++ b/crates/shirabe/src/repository/vcs/github_driver.rs
@@ -12,7 +12,6 @@ use crate::repository::vcs::GitDriver;
use crate::repository::vcs::VcsDriverBase;
use crate::util::GitHub;
use crate::util::http::Response;
-use anyhow::Result;
use chrono::{DateTime, FixedOffset};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
@@ -69,7 +68,7 @@ impl GitHubDriver {
}
}
- pub fn initialize(&mut self) -> Result<()> {
+ pub fn initialize(&mut self) -> anyhow::Result<()> {
let mut match_: IndexMap<CaptureKey, String> = IndexMap::new();
if !Preg::is_match3(
r"#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#",
@@ -177,7 +176,7 @@ impl GitHubDriver {
)
}
- pub fn get_root_identifier(&mut self) -> Result<String> {
+ pub fn get_root_identifier(&mut self) -> anyhow::Result<String> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_root_identifier();
}
@@ -255,7 +254,7 @@ impl GitHubDriver {
pub fn get_composer_information(
&mut self,
identifier: &str,
- ) -> Result<Option<IndexMap<String, PhpMixed>>> {
+ ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_composer_information(identifier);
}
@@ -713,7 +712,11 @@ impl GitHubDriver {
result_mixed
}
- pub fn get_file_content(&mut self, file: &str, identifier: &str) -> Result<Option<String>> {
+ pub fn get_file_content(
+ &mut self,
+ file: &str,
+ identifier: &str,
+ ) -> anyhow::Result<Option<String>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_file_content(file, identifier);
}
@@ -791,7 +794,10 @@ impl GitHubDriver {
Ok(Some(content))
}
- pub fn get_change_date(&mut self, identifier: &str) -> Result<Option<DateTime<FixedOffset>>> {
+ pub fn get_change_date(
+ &mut self,
+ identifier: &str,
+ ) -> anyhow::Result<Option<DateTime<FixedOffset>>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_change_date(identifier);
}
@@ -825,7 +831,7 @@ impl GitHubDriver {
Ok(Some(date))
}
- pub fn get_tags(&mut self) -> Result<IndexMap<String, String>> {
+ pub fn get_tags(&mut self) -> anyhow::Result<IndexMap<String, String>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_tags();
}
@@ -875,7 +881,7 @@ impl GitHubDriver {
Ok(self.tags.clone().unwrap_or_default())
}
- pub fn get_branches(&mut self) -> Result<IndexMap<String, String>> {
+ pub fn get_branches(&mut self) -> anyhow::Result<IndexMap<String, String>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_branches();
}
@@ -979,7 +985,7 @@ impl GitHubDriver {
/// Gives back the loaded <github-api>/repos/<owner>/<repo> result
///
/// @return mixed[]|null
- pub fn get_repo_data(&mut self) -> Result<Option<IndexMap<String, PhpMixed>>> {
+ pub fn get_repo_data(&mut self) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> {
self.fetch_root_identifier()?;
Ok(self.repo_data.clone())
@@ -1004,7 +1010,7 @@ impl GitHubDriver {
&mut self,
url: &str,
fetching_repo_data: bool,
- ) -> Result<Response, TransportException> {
+ ) -> anyhow::Result<Response, TransportException> {
let response_result = self.inner.get_contents(url);
match response_result {
Ok(r) => Ok(r),
@@ -1145,7 +1151,7 @@ impl GitHubDriver {
/// Fetch root identifier from GitHub
///
/// @throws TransportException
- pub(crate) fn fetch_root_identifier(&mut self) -> Result<()> {
+ pub(crate) fn fetch_root_identifier(&mut self) -> anyhow::Result<()> {
if self.repo_data.is_some() {
return Ok(());
}
@@ -1220,7 +1226,7 @@ impl GitHubDriver {
pub(crate) fn attempt_clone_fallback(
&mut self,
e: Option<&TransportException>,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
if !self.allow_git_fallback {
return Err(RuntimeException {
message: format!(
@@ -1257,7 +1263,7 @@ impl GitHubDriver {
}
}
- pub(crate) fn setup_git_driver(&mut self, url: &str) -> Result<()> {
+ pub(crate) fn setup_git_driver(&mut self, url: &str) -> anyhow::Result<()> {
if !self.allow_git_fallback {
return Err(RuntimeException {
message: "Fallback to git driver disabled".to_string(),
diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
index 136d0d6..3f66223 100644
--- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs
+++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
@@ -13,7 +13,6 @@ use crate::repository::vcs::VcsDriverBase;
use crate::util::GitLab;
use crate::util::HttpDownloader;
use crate::util::http::Response;
-use anyhow::Result;
use chrono::{DateTime, FixedOffset};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
@@ -80,7 +79,7 @@ impl GitLabDriver {
/// Extracts information from the repository url.
///
/// SSH urls use https by default. Set "secure-http": false on the repository config to use http instead.
- pub fn initialize(&mut self) -> Result<()> {
+ pub fn initialize(&mut self) -> anyhow::Result<()> {
let mut match_: IndexMap<CaptureKey, String> = IndexMap::new();
if !Preg::is_match3(Self::URL_REGEX, &self.inner.url, Some(&mut match_)) {
return Err(InvalidArgumentException {
@@ -262,7 +261,7 @@ impl GitLabDriver {
pub fn get_composer_information(
&mut self,
identifier: &str,
- ) -> Result<Option<IndexMap<String, PhpMixed>>> {
+ ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_composer_information(identifier);
}
@@ -416,7 +415,11 @@ impl GitLabDriver {
.unwrap_or(None))
}
- pub fn get_file_content(&mut self, file: &str, identifier: &str) -> Result<Option<String>> {
+ pub fn get_file_content(
+ &mut self,
+ file: &str,
+ identifier: &str,
+ ) -> anyhow::Result<Option<String>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_file_content(file, identifier);
}
@@ -451,7 +454,10 @@ impl GitLabDriver {
Ok(content)
}
- pub fn get_change_date(&mut self, identifier: &str) -> Result<Option<DateTime<FixedOffset>>> {
+ pub fn get_change_date(
+ &mut self,
+ identifier: &str,
+ ) -> anyhow::Result<Option<DateTime<FixedOffset>>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_change_date(identifier);
}
@@ -546,7 +552,7 @@ impl GitLabDriver {
result
}
- pub fn get_root_identifier(&mut self) -> Result<String> {
+ pub fn get_root_identifier(&mut self) -> anyhow::Result<String> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_root_identifier();
}
@@ -560,7 +566,7 @@ impl GitLabDriver {
.to_string())
}
- pub fn get_branches(&mut self) -> Result<IndexMap<String, String>> {
+ pub fn get_branches(&mut self) -> anyhow::Result<IndexMap<String, String>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_branches();
}
@@ -572,7 +578,7 @@ impl GitLabDriver {
Ok(self.branches.clone().unwrap_or_default())
}
- pub fn get_tags(&mut self) -> Result<IndexMap<String, String>> {
+ pub fn get_tags(&mut self) -> anyhow::Result<IndexMap<String, String>> {
if let Some(ref mut git_driver) = self.git_driver {
return git_driver.get_tags();
}
@@ -621,7 +627,10 @@ impl GitLabDriver {
}
/// @return string[] where keys are named references like tags or branches and the value a sha
- pub(crate) fn get_references(&mut self, r#type: &str) -> Result<IndexMap<String, String>> {
+ pub(crate) fn get_references(
+ &mut self,
+ r#type: &str,
+ ) -> anyhow::Result<IndexMap<String, String>> {
let per_page = 100;
let mut resource: Option<String> = Some(format!(
"{}/repository/{}?per_page={}",
@@ -684,7 +693,7 @@ impl GitLabDriver {
Ok(references)
}
- pub(crate) fn fetch_project(&mut self) -> Result<()> {
+ pub(crate) fn fetch_project(&mut self) -> anyhow::Result<()> {
if self.project.is_some() {
return Ok(());
}
@@ -718,7 +727,7 @@ impl GitLabDriver {
///
/// @return true
/// @throws \RuntimeException
- pub(crate) fn attempt_clone_fallback(&mut self) -> Result<bool> {
+ pub(crate) fn attempt_clone_fallback(&mut self) -> anyhow::Result<bool> {
let url = if !self.is_private {
self.generate_public_url()
} else {
@@ -768,7 +777,7 @@ impl GitLabDriver {
)
}
- pub(crate) fn setup_git_driver(&mut self, url: &str) -> Result<()> {
+ pub(crate) fn setup_git_driver(&mut self, url: &str) -> anyhow::Result<()> {
let mut repo_config: IndexMap<String, PhpMixed> = IndexMap::new();
repo_config.insert("url".to_string(), PhpMixed::String(url.to_string()));
let mut git_driver = GitDriver::new(
@@ -787,7 +796,7 @@ impl GitLabDriver {
&mut self,
url: &str,
fetching_repo_data: bool,
- ) -> Result<Response, TransportException> {
+ ) -> anyhow::Result<Response, TransportException> {
let response_result = self.inner.get_contents(url);
match response_result {
Ok(response) => {
@@ -1027,7 +1036,7 @@ impl GitLabDriver {
/// Gives back the loaded <gitlab-api>/projects/<owner>/<repo> result
///
/// @return mixed[]|null
- pub fn get_repo_data(&mut self) -> Result<Option<IndexMap<String, PhpMixed>>> {
+ pub fn get_repo_data(&mut self) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> {
self.fetch_project()?;
Ok(self.project.clone())
diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs
index cb4ff87..7df7f02 100644
--- a/crates/shirabe/src/repository/vcs/svn_driver.rs
+++ b/crates/shirabe/src/repository/vcs/svn_driver.rs
@@ -11,7 +11,6 @@ use crate::util::Filesystem;
use crate::util::ProcessExecutor;
use crate::util::Svn as SvnUtil;
use crate::util::Url;
-use anyhow::Result;
use chrono::{DateTime, FixedOffset, Utc};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
@@ -68,7 +67,7 @@ impl SvnDriver {
}
}
- pub fn initialize(&mut self) -> Result<()> {
+ pub fn initialize(&mut self) -> anyhow::Result<()> {
let normalized = Self::normalize_url(&self.inner.url);
self.inner.url = normalized.trim_end_matches('/').to_string();
self.base_url = self.inner.url.clone();
@@ -164,7 +163,7 @@ impl SvnDriver {
pub fn get_composer_information(
&mut self,
identifier: &str,
- ) -> Result<Option<IndexMap<String, PhpMixed>>> {
+ ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> {
if !self.inner.info_cache.contains_key(identifier) {
if self.should_cache(identifier)
&& let Some(mut res) = self
@@ -255,7 +254,11 @@ impl SvnDriver {
Ok(cached)
}
- pub fn get_file_content(&mut self, file: &str, identifier: &str) -> Result<Option<String>> {
+ pub fn get_file_content(
+ &mut self,
+ file: &str,
+ identifier: &str,
+ ) -> anyhow::Result<Option<String>> {
let identifier = format!("/{}/", trim(identifier, Some("/")));
let (path, rev) = if let Some(m) =
@@ -292,7 +295,10 @@ impl SvnDriver {
Ok(Some(output))
}
- pub fn get_change_date(&mut self, identifier: &str) -> Result<Option<DateTime<FixedOffset>>> {
+ pub fn get_change_date(
+ &mut self,
+ identifier: &str,
+ ) -> anyhow::Result<Option<DateTime<FixedOffset>>> {
let identifier = format!("/{}/", trim(identifier, Some("/")));
let (path, rev) = if let Some(m) =
@@ -329,7 +335,7 @@ impl SvnDriver {
Ok(None)
}
- pub fn get_tags(&mut self) -> Result<&IndexMap<String, String>> {
+ pub fn get_tags(&mut self) -> anyhow::Result<&IndexMap<String, String>> {
if self.tags.is_none() {
let mut tags: IndexMap<String, String> = IndexMap::new();
@@ -373,7 +379,7 @@ impl SvnDriver {
Ok(self.tags.as_ref().unwrap())
}
- pub fn get_branches(&mut self) -> Result<&IndexMap<String, String>> {
+ pub fn get_branches(&mut self) -> anyhow::Result<&IndexMap<String, String>> {
if self.branches.is_none() {
let mut branches: IndexMap<String, String> = IndexMap::new();
@@ -464,7 +470,7 @@ impl SvnDriver {
_config: std::rc::Rc<std::cell::RefCell<Config>>,
url: &str,
deep: bool,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
let url = Self::normalize_url(url);
if Preg::is_match(r"#(^svn://|^svn\+ssh://|svn\.)#i", &url) {
return Ok(true);
@@ -527,7 +533,7 @@ impl SvnDriver {
/// @param non-empty-list<string> $command The svn command to run.
/// @param string $url The SVN URL.
/// @throws \RuntimeException
- pub(crate) fn execute(&mut self, command: Vec<String>, url: &str) -> Result<String> {
+ pub(crate) fn execute(&mut self, command: Vec<String>, url: &str) -> anyhow::Result<String> {
if self.util.is_none() {
self.util = Some(SvnUtil::new(
self.base_url.clone(),
diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs
index d799532..8d747c6 100644
--- a/crates/shirabe/src/repository/vcs_repository.rs
+++ b/crates/shirabe/src/repository/vcs_repository.rs
@@ -26,7 +26,6 @@ use crate::util::HttpDownloader;
use crate::util::Platform;
use crate::util::ProcessExecutor;
use crate::util::Url;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{InvalidArgumentException, PhpMixed, in_array, str_replace, strpos};
@@ -103,7 +102,7 @@ impl VcsRepository {
process: Option<std::rc::Rc<std::cell::RefCell<ProcessExecutor>>>,
drivers: Option<IndexMap<String, VcsDriverKind>>,
version_cache: Option<Box<dyn VersionCacheInterface>>,
- ) -> Result<Self> {
+ ) -> anyhow::Result<Self> {
let inner = ArrayRepository::new(vec![])?;
let drivers = drivers.unwrap_or_else(|| {
let mut m: IndexMap<String, VcsDriverKind> = IndexMap::new();
@@ -297,7 +296,7 @@ impl VcsRepository {
Ok(())
}
- pub fn initialize(&self) -> Result<()> {
+ pub fn initialize(&self) -> anyhow::Result<()> {
self.inner.initialize();
let is_verbose = self.is_verbose;
@@ -436,7 +435,7 @@ impl VcsRepository {
.overwrite_error4(&msg, false, None, io_interface::NORMAL);
}
- let result: Result<()> = (|| -> Result<()> {
+ let result: anyhow::Result<()> = (|| -> anyhow::Result<()> {
let data_opt = self
.driver
.borrow_mut()
@@ -708,7 +707,7 @@ impl VcsRepository {
CachedPackageResult::None => {}
}
- let result: Result<()> = (|| -> Result<()> {
+ let result: anyhow::Result<()> = (|| -> anyhow::Result<()> {
let data_opt = self
.driver
.borrow_mut()
@@ -847,7 +846,7 @@ impl VcsRepository {
driver: &dyn VcsDriverInterface,
mut data: IndexMap<String, PhpMixed>,
identifier: &str,
- ) -> Result<IndexMap<String, PhpMixed>> {
+ ) -> anyhow::Result<IndexMap<String, PhpMixed>> {
// keep the name of the main identifier for all packages
// this ensures that a package can be renamed in one place and that all old tags
// will still be installable using that new name without requiring re-tagging
@@ -963,7 +962,7 @@ impl VcsRepository {
is_verbose: bool,
is_very_verbose: bool,
is_default_branch: bool,
- ) -> Result<CachedPackageResult> {
+ ) -> anyhow::Result<CachedPackageResult> {
if self.version_cache.is_none() {
return Ok(CachedPackageResult::None);
}
diff --git a/crates/shirabe/src/repository/writable_array_repository.rs b/crates/shirabe/src/repository/writable_array_repository.rs
index c4b31aa..e415a1e 100644
--- a/crates/shirabe/src/repository/writable_array_repository.rs
+++ b/crates/shirabe/src/repository/writable_array_repository.rs
@@ -7,7 +7,6 @@ use crate::repository::ArrayRepository;
use crate::repository::RepositoryInterface;
use crate::repository::RepositoryInterfaceWeakHandle;
use crate::repository::{FindPackageConstraint, LoadPackagesResult, ProviderInfo, SearchResult};
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_semver::constraint::AnyConstraint;
@@ -19,7 +18,7 @@ pub struct WritableArrayRepository {
}
impl WritableArrayRepository {
- pub fn new(packages: Vec<crate::package::PackageInterfaceHandle>) -> Result<Self> {
+ pub fn new(packages: Vec<crate::package::PackageInterfaceHandle>) -> anyhow::Result<Self> {
Ok(Self {
inner: ArrayRepository::new(packages)?,
dev_package_names: Vec::new(),
@@ -44,7 +43,7 @@ impl WritableArrayRepository {
&mut self,
dev_mode: bool,
_installation_manager: &InstallationManager,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
self.dev_mode = Some(dev_mode);
Ok(())
}
@@ -61,7 +60,10 @@ impl WritableArrayRepository {
self.inner.is_initialized()
}
- pub fn add_package(&mut self, package: crate::package::PackageInterfaceHandle) -> Result<()> {
+ pub fn add_package(
+ &mut self,
+ package: crate::package::PackageInterfaceHandle,
+ ) -> anyhow::Result<()> {
self.inner.add_package(package)
}
@@ -72,12 +74,12 @@ impl WritableArrayRepository {
pub fn remove_package(
&mut self,
package: crate::package::PackageInterfaceHandle,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
self.inner.remove_package(package);
Ok(())
}
- pub fn initialize(&mut self) -> Result<()> {
+ pub fn initialize(&mut self) -> anyhow::Result<()> {
self.inner.initialize();
Ok(())
}
@@ -134,7 +136,7 @@ impl RepositoryInterface for WritableArrayRepository {
&mut self,
name: &str,
constraint: FindPackageConstraint,
- ) -> Result<Option<BasePackageHandle>> {
+ ) -> anyhow::Result<Option<BasePackageHandle>> {
self.inner.find_package(name, constraint)
}
@@ -142,11 +144,11 @@ impl RepositoryInterface for WritableArrayRepository {
&mut self,
name: &str,
constraint: Option<FindPackageConstraint>,
- ) -> Result<Vec<BasePackageHandle>> {
+ ) -> anyhow::Result<Vec<BasePackageHandle>> {
self.inner.find_packages(name, constraint)
}
- fn get_packages(&mut self) -> Result<Vec<BasePackageHandle>> {
+ fn get_packages(&mut self) -> anyhow::Result<Vec<BasePackageHandle>> {
self.inner.get_packages()
}
@@ -156,7 +158,7 @@ impl RepositoryInterface for WritableArrayRepository {
acceptable_stabilities: IndexMap<String, i64>,
stability_flags: IndexMap<String, i64>,
already_loaded: IndexMap<String, IndexMap<String, PackageInterfaceHandle>>,
- ) -> Result<LoadPackagesResult> {
+ ) -> anyhow::Result<LoadPackagesResult> {
self.inner.load_packages(
package_name_map,
acceptable_stabilities,
@@ -170,11 +172,14 @@ impl RepositoryInterface for WritableArrayRepository {
query: String,
mode: i64,
r#type: Option<String>,
- ) -> Result<Vec<SearchResult>> {
+ ) -> anyhow::Result<Vec<SearchResult>> {
self.inner.search(query, mode, r#type)
}
- fn get_providers(&mut self, package_name: String) -> Result<IndexMap<String, ProviderInfo>> {
+ fn get_providers(
+ &mut self,
+ package_name: String,
+ ) -> anyhow::Result<IndexMap<String, ProviderInfo>> {
self.inner.get_providers(package_name)
}
diff --git a/crates/shirabe/src/repository/writable_repository_interface.rs b/crates/shirabe/src/repository/writable_repository_interface.rs
index 9cdecb5..7a50506 100644
--- a/crates/shirabe/src/repository/writable_repository_interface.rs
+++ b/crates/shirabe/src/repository/writable_repository_interface.rs
@@ -3,22 +3,21 @@
use crate::installer::InstallationManager;
use crate::package::PackageInterfaceHandle;
use crate::repository::RepositoryInterface;
-use anyhow::Result;
pub trait WritableRepositoryInterface: RepositoryInterface {
fn write(
&mut self,
dev_mode: bool,
installation_manager: &mut InstallationManager,
- ) -> Result<()>;
+ ) -> anyhow::Result<()>;
- fn add_package(&mut self, package: PackageInterfaceHandle) -> Result<()>;
+ fn add_package(&mut self, package: PackageInterfaceHandle) -> anyhow::Result<()>;
- fn remove_package(&mut self, package: PackageInterfaceHandle) -> Result<()>;
+ fn remove_package(&mut self, package: PackageInterfaceHandle) -> anyhow::Result<()>;
- fn get_canonical_packages(&mut self) -> Result<Vec<PackageInterfaceHandle>>;
+ fn get_canonical_packages(&mut self) -> anyhow::Result<Vec<PackageInterfaceHandle>>;
- fn reload(&mut self) -> Result<()>;
+ fn reload(&mut self) -> anyhow::Result<()>;
fn set_dev_package_names(&mut self, dev_package_names: Vec<String>);
diff --git a/crates/shirabe/src/self_update/keys.rs b/crates/shirabe/src/self_update/keys.rs
index b1da7b5..3fa29f7 100644
--- a/crates/shirabe/src/self_update/keys.rs
+++ b/crates/shirabe/src/self_update/keys.rs
@@ -1,13 +1,12 @@
//! ref: composer/src/Composer/SelfUpdate/Keys.php
-use anyhow::Result;
use regex::Regex;
use shirabe_php_shim::hash;
pub struct Keys;
impl Keys {
- pub fn fingerprint(path: &str) -> Result<String> {
+ pub fn fingerprint(path: &str) -> anyhow::Result<String> {
let content = std::fs::read_to_string(path)?;
let re = Regex::new(r"\s").unwrap();
let cleaned = re.replace_all(&content, "");
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 8a89842..13199e9 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -8,7 +8,6 @@ use crate::io::io_interface;
use crate::util::Bitbucket;
use crate::util::GitHub;
use crate::util::GitLab;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
@@ -54,7 +53,7 @@ impl AuthHelper {
}
/// @param 'prompt'|bool $storeAuth
- pub fn store_auth(&self, origin: &str, store_auth: StoreAuth) -> Result<()> {
+ pub fn store_auth(&self, origin: &str, store_auth: StoreAuth) -> anyhow::Result<()> {
let mut store: Option<()> = None;
let mut config = self.config.borrow_mut();
let config_source = config.get_auth_config_source_mut();
@@ -123,7 +122,7 @@ impl AuthHelper {
headers: Vec<String>,
retry_count: i64,
response_body: Option<&str>,
- ) -> Result<PromptAuthResult> {
+ ) -> anyhow::Result<PromptAuthResult> {
let mut store_auth: StoreAuth = StoreAuth::Bool(false);
let github_domains = self.config.borrow_mut().get("github-domains");
@@ -450,7 +449,7 @@ impl AuthHelper {
mut options: IndexMap<String, PhpMixed>,
origin: &str,
url: &str,
- ) -> Result<IndexMap<String, PhpMixed>> {
+ ) -> anyhow::Result<IndexMap<String, PhpMixed>> {
if !options.contains_key("http") {
options.insert("http".to_string(), PhpMixed::Array(IndexMap::new()));
}
diff --git a/crates/shirabe/src/util/forgejo_url.rs b/crates/shirabe/src/util/forgejo_url.rs
index d336b87..157ea53 100644
--- a/crates/shirabe/src/util/forgejo_url.rs
+++ b/crates/shirabe/src/util/forgejo_url.rs
@@ -1,6 +1,5 @@
//! ref: composer/src/Composer/Util/ForgejoUrl.php
-use anyhow::Result;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::InvalidArgumentException;
@@ -25,7 +24,7 @@ impl ForgejoUrl {
}
}
- pub fn create(repo_url: &str) -> Result<Self> {
+ pub fn create(repo_url: &str) -> anyhow::Result<Self> {
match Self::try_from(Some(repo_url)) {
Some(url) => Ok(url),
None => Err(InvalidArgumentException {
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index ee9f9e6..bd7b13b 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -13,7 +13,6 @@ use crate::util::Platform;
use crate::util::ProcessExecutor;
use crate::util::Url;
use crate::util::{AuthHelper, StoreAuth};
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
@@ -56,7 +55,7 @@ impl Git {
output: &str,
path: &str,
io: Option<std::rc::Rc<std::cell::RefCell<dyn IOInterface>>>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
if str_contains(output, "fatal: detected dubious ownership") {
let msg = format!(
"The repository at \"{}\" does not have the correct ownership and git refuses to use it:{}{}{}",
@@ -106,7 +105,7 @@ impl Git {
cwd: Option<&str>,
initial_clone: bool,
command_output: Option<&mut PhpMixed>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let mut callables: Vec<Box<dyn Fn(&str) -> Vec<String>>> = vec![];
for cmd in commands {
let cmd_clone = cmd.clone();
@@ -138,7 +137,7 @@ impl Git {
cwd: Option<&str>,
initial_clone: bool,
command_output: Option<&mut PhpMixed>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
self.run_command(command_callable, url, cwd, initial_clone, command_output)
}
@@ -152,7 +151,7 @@ impl Git {
cwd: Option<&str>,
initial_clone: bool,
mut command_output: Option<&mut PhpMixed>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let command_callables = command_callable;
let mut last_command: PhpMixed = PhpMixed::String(String::new());
@@ -786,7 +785,7 @@ impl Git {
Ok(())
}
- pub fn sync_mirror(&mut self, url: &str, dir: &str) -> Result<bool> {
+ pub fn sync_mirror(&mut self, url: &str, dir: &str) -> anyhow::Result<bool> {
let composer_disable_network = Platform::get_env("COMPOSER_DISABLE_NETWORK");
if composer_disable_network
.as_ref()
@@ -821,7 +820,7 @@ impl Git {
&& trim(&output, None) == "."
{
// PHP try/finally
- let try_result: Result<()> = (|| -> Result<()> {
+ let try_result: anyhow::Result<()> = (|| -> anyhow::Result<()> {
let commands = vec![
vec![
"git".to_string(),
@@ -917,7 +916,7 @@ impl Git {
dir: &str,
r#ref: &str,
pretty_version: Option<&str>,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
if self.check_ref_is_in_mirror(dir, r#ref)? {
if Preg::is_match(r"{^[a-f0-9]{40}$}", r#ref)
&& let Some(pretty_version) = pretty_version
@@ -1048,7 +1047,7 @@ impl Git {
Preg::replace(r"{^commit [a-f0-9]{40}\n?}m", "", output)
}
- fn check_ref_is_in_mirror(&mut self, dir: &str, r#ref: &str) -> Result<bool> {
+ fn check_ref_is_in_mirror(&mut self, dir: &str, r#ref: &str) -> anyhow::Result<bool> {
let mut output = String::new();
if is_dir(dir)
&& self.process.borrow_mut().execute_args(
@@ -1121,7 +1120,7 @@ impl Git {
return None;
}
- let result: Result<Option<String>> = (|| -> Result<Option<String>> {
+ let result: anyhow::Result<Option<String>> = (|| -> anyhow::Result<Option<String>> {
let mut output_mixed = PhpMixed::Null;
if is_local_path_repository {
let mut output = String::new();
@@ -1262,7 +1261,7 @@ impl Git {
/// @param non-empty-string $message
///
/// @return never
- fn throw_exception(&mut self, message: &str, url: &str) -> Result<()> {
+ fn throw_exception(&mut self, message: &str, url: &str) -> anyhow::Result<()> {
// git might delete a directory when it fails and php will not know
clearstatcache();
diff --git a/crates/shirabe/src/util/hg.rs b/crates/shirabe/src/util/hg.rs
index cdfcd4e..56e5044 100644
--- a/crates/shirabe/src/util/hg.rs
+++ b/crates/shirabe/src/util/hg.rs
@@ -5,7 +5,6 @@ use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
use crate::util::ProcessExecutor;
use crate::util::Url;
-use anyhow::Result;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::rawurlencode;
use std::sync::OnceLock;
@@ -37,7 +36,7 @@ impl Hg {
command_callable: impl Fn(String) -> Vec<String>,
url: String,
cwd: Option<String>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
self.config.borrow_mut().prohibit_url_by_config(
&url,
Some(self.io.clone()),
@@ -126,7 +125,7 @@ impl Hg {
self.throw_exception(&format!("Failed to clone {}, \n\n{}", url, error), &url)
}
- fn throw_exception(&self, message: &str, url: &str) -> Result<()> {
+ fn throw_exception(&self, message: &str, url: &str) -> anyhow::Result<()> {
if Self::get_version(&self.process).is_none() {
anyhow::bail!(
"{}",
diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs
index 18e320c..eeb4b6f 100644
--- a/crates/shirabe/src/util/http_downloader.rs
+++ b/crates/shirabe/src/util/http_downloader.rs
@@ -14,7 +14,6 @@ use crate::util::StreamContextFactory;
use crate::util::Url;
use crate::util::http::CurlDownloader;
use crate::util::http::Response;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
@@ -215,7 +214,11 @@ impl HttpDownloader {
}
/// Download a file synchronously
- pub fn get(&mut self, url: &str, options: IndexMap<String, PhpMixed>) -> Result<Response> {
+ pub fn get(
+ &mut self,
+ url: &str,
+ options: IndexMap<String, PhpMixed>,
+ ) -> anyhow::Result<Response> {
if self.mock.is_some() {
return self.mock_get(url, &options);
}
@@ -246,7 +249,7 @@ impl HttpDownloader {
&mut self,
url: &str,
options: IndexMap<String, PhpMixed>,
- ) -> Result<Response> {
+ ) -> anyhow::Result<Response> {
if self.mock.is_some() {
return self.mock_get(url, &options);
}
@@ -276,7 +279,7 @@ impl HttpDownloader {
url: &str,
to: &str,
options: IndexMap<String, PhpMixed>,
- ) -> Result<Response> {
+ ) -> anyhow::Result<Response> {
if self.mock.is_some() {
return self.mock_get(url, &options);
}
@@ -306,7 +309,7 @@ impl HttpDownloader {
url: &str,
to: &str,
options: IndexMap<String, PhpMixed>,
- ) -> Result<Response> {
+ ) -> anyhow::Result<Response> {
if self.mock.is_some() {
return self.mock_get(url, &options);
}
@@ -345,7 +348,7 @@ impl HttpDownloader {
/// Queues a job and starts it if there is capacity. Mirrors PHP `addJob`: for non-curl (rfs)
/// jobs the work runs synchronously here (PHP runs it in the Promise resolver during
/// construction); for curl jobs the work is driven later by `start_job` / `count_active_jobs`.
- fn add_job(&mut self, mut request: Request, sync: bool) -> Result<JobHandle> {
+ fn add_job(&mut self, mut request: Request, sync: bool) -> anyhow::Result<JobHandle> {
request.options = array_replace_recursive(self.options.clone(), request.options);
let id = self.id_gen;
@@ -593,11 +596,11 @@ impl HttpDownloader {
/// Wait for current async download jobs to complete
///
/// @param int|null $index For internal use only, the job id
- pub fn wait(&mut self) -> Result<()> {
+ pub fn wait(&mut self) -> anyhow::Result<()> {
self.wait_id(None)
}
- fn wait_id(&mut self, index: Option<i64>) -> Result<()> {
+ fn wait_id(&mut self, index: Option<i64>) -> anyhow::Result<()> {
loop {
let job_count = self.count_active_jobs(index)?;
if job_count == 0 {
@@ -613,7 +616,7 @@ impl HttpDownloader {
}
/// @internal
- pub fn count_active_jobs(&mut self, index: Option<i64>) -> Result<i64> {
+ pub fn count_active_jobs(&mut self, index: Option<i64>) -> anyhow::Result<i64> {
if self.running_jobs < self.max_jobs {
let queued_ids: Vec<i64> = self
.jobs
@@ -676,7 +679,7 @@ impl HttpDownloader {
}
/// @param int $index Job id
- fn get_response(&mut self, index: i64) -> Result<Response> {
+ fn get_response(&mut self, index: i64) -> anyhow::Result<Response> {
if !self.jobs.contains_key(&index) {
return Err(LogicException {
message: "Invalid request id".to_string(),
@@ -712,7 +715,7 @@ impl HttpDownloader {
io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
url: &str,
data: &IndexMap<String, PhpMixed>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let clean_message = |msg: &str| -> anyhow::Result<String> {
if !io.is_decorated() {
return Ok(Preg::replace(
@@ -949,7 +952,7 @@ impl HttpDownloader {
&mut self,
file_url: &str,
options: &IndexMap<String, PhpMixed>,
- ) -> Result<Response> {
+ ) -> anyhow::Result<Response> {
if file_url.is_empty() {
return Err(LogicException {
message: "url cannot be an empty string".to_string(),
@@ -1019,7 +1022,7 @@ impl HttpDownloader {
status: i64,
headers: Vec<String>,
body: String,
- ) -> Result<Response> {
+ ) -> anyhow::Result<Response> {
if status < 400 {
return Ok(Response::new(
url.to_string(),
diff --git a/crates/shirabe/src/util/loop.rs b/crates/shirabe/src/util/loop.rs
index 2a0e6d3..4efd770 100644
--- a/crates/shirabe/src/util/loop.rs
+++ b/crates/shirabe/src/util/loop.rs
@@ -2,7 +2,6 @@
use crate::util::HttpDownloader;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use shirabe_external_packages::symfony::console::helper::ProgressBar;
#[derive(Debug)]
@@ -40,9 +39,11 @@ impl Loop {
pub async fn wait<'p>(
&mut self,
- promises: Vec<std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>> + 'p>>>,
+ promises: Vec<
+ std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>> + 'p>>,
+ >,
_progress: Option<&mut ProgressBar>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let mut uncaught: Option<anyhow::Error> = None;
// TODO(phase-c-promise): the asynchronous worker classes (HttpDownloader / ProcessExecutor)
diff --git a/crates/shirabe/src/util/no_proxy_pattern.rs b/crates/shirabe/src/util/no_proxy_pattern.rs
index 3715ea9..0a3d564 100644
--- a/crates/shirabe/src/util/no_proxy_pattern.rs
+++ b/crates/shirabe/src/util/no_proxy_pattern.rs
@@ -1,6 +1,5 @@
//! ref: composer/src/Composer/Util/NoProxyPattern.php
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
@@ -49,7 +48,7 @@ impl NoProxyPattern {
}
/// Returns true if a URL matches the NO_PROXY pattern
- pub fn test(&mut self, url: &str) -> Result<bool> {
+ pub fn test(&mut self, url: &str) -> anyhow::Result<bool> {
if self.noproxy {
return Ok(true);
}
@@ -72,7 +71,7 @@ impl NoProxyPattern {
/// Returns false is the url cannot be parsed, otherwise a data object
///
/// @return bool|stdClass
- pub(crate) fn get_url_data(&self, url: &str) -> Result<Option<UrlData>> {
+ pub(crate) fn get_url_data(&self, url: &str) -> anyhow::Result<Option<UrlData>> {
let host = parse_url(url, PHP_URL_HOST);
if empty(&host) {
return Ok(None);
@@ -110,7 +109,12 @@ impl NoProxyPattern {
}
/// Returns true if the url is matched by a rule
- pub(crate) fn r#match(&mut self, index: i64, host_name: &str, url: &UrlData) -> Result<bool> {
+ pub(crate) fn r#match(
+ &mut self,
+ index: i64,
+ host_name: &str,
+ url: &UrlData,
+ ) -> anyhow::Result<bool> {
let rule = match self.get_rule(index, host_name)? {
Some(r) => r,
None => {
@@ -146,7 +150,7 @@ impl NoProxyPattern {
}
/// Returns true if the target ip is in the network range
- pub(crate) fn match_range(&self, network: &IpData, target: &IpData) -> Result<bool> {
+ pub(crate) fn match_range(&self, network: &IpData, target: &IpData) -> anyhow::Result<bool> {
let net = unpack("C*", &network.ip);
let mask = unpack("C*", network.netmask.as_deref().unwrap_or_default());
let ip = unpack("C*", &target.ip);
@@ -212,7 +216,7 @@ impl NoProxyPattern {
/// Finds or creates rule data for a hostname
///
/// @return null|stdClass Null if the hostname is invalid
- fn get_rule(&mut self, index: i64, host_name: &str) -> Result<Option<UrlData>> {
+ fn get_rule(&mut self, index: i64, host_name: &str) -> anyhow::Result<Option<UrlData>> {
if array_key_exists(&index.to_string(), &{
let mut m: IndexMap<String, ()> = IndexMap::new();
for k in self.rules.keys() {
@@ -248,7 +252,7 @@ impl NoProxyPattern {
host: &str,
ipdata: &mut Option<IpData>,
allow_prefix: bool,
- ) -> Result<bool> {
+ ) -> anyhow::Result<bool> {
*ipdata = None;
let mut netmask: Option<Vec<u8>> = None;
let mut prefix: Option<i64> = None;
@@ -345,7 +349,7 @@ impl NoProxyPattern {
range_ip: &[u8],
size: i64,
prefix: i64,
- ) -> Result<(Vec<u8>, Vec<u8>)> {
+ ) -> anyhow::Result<(Vec<u8>, Vec<u8>)> {
let netmask = self.ip_get_mask(prefix, size);
// Get the network from the address and mask
@@ -435,7 +439,7 @@ impl NoProxyPattern {
/// Splits the hostname into host and port components
///
/// @return mixed[] host, port, if there was error
- fn split_host_port(&self, host_name: &str) -> Result<(String, i64, bool)> {
+ fn split_host_port(&self, host_name: &str) -> anyhow::Result<(String, i64, bool)> {
// host, port, err
let error = (String::new(), 0_i64, true);
let mut port: i64 = 0;
diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs
index bd8e9e6..389618e 100644
--- a/crates/shirabe/src/util/perforce.rs
+++ b/crates/shirabe/src/util/perforce.rs
@@ -5,7 +5,6 @@ use crate::io::IOInterfaceImmutable;
use crate::util::Filesystem;
use crate::util::Platform;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::process::ExecutableFinder;
@@ -351,7 +350,7 @@ impl Perforce {
result
}
- pub fn is_logged_in(&mut self) -> Result<bool> {
+ pub fn is_logged_in(&mut self) -> anyhow::Result<bool> {
let command = self.generate_p4_command(vec!["login".to_string(), "-s".to_string()], false);
let exit_code = self.execute_command(PhpMixed::List(
command.into_iter().map(PhpMixed::String).collect(),
@@ -381,7 +380,7 @@ impl Perforce {
Ok(true)
}
- pub fn connect_client(&mut self) -> Result<()> {
+ pub fn connect_client(&mut self) -> anyhow::Result<()> {
let p4_create_client_command =
self.generate_p4_command(vec!["client".to_string(), "-i".to_string()], true);
@@ -398,7 +397,7 @@ impl Perforce {
Ok(())
}
- pub fn sync_code_base(&mut self, source_reference: Option<&str>) -> Result<()> {
+ pub fn sync_code_base(&mut self, source_reference: Option<&str>) -> anyhow::Result<()> {
let prev_dir = Platform::get_cwd(false)?;
chdir(&self.path);
let mut p4_sync_command =
@@ -503,7 +502,7 @@ impl Perforce {
}
}
- pub fn write_p4_client_spec(&mut self) -> Result<()> {
+ pub fn write_p4_client_spec(&mut self) -> anyhow::Result<()> {
let client_spec = self.get_p4_client_spec();
let spec = match fopen(&client_spec, "w") {
Ok(spec) => spec,
@@ -542,7 +541,7 @@ impl Perforce {
}
}
- pub fn windows_login(&mut self, password: Option<&str>) -> Result<i64> {
+ pub fn windows_login(&mut self, password: Option<&str>) -> anyhow::Result<i64> {
let command = self.generate_p4_command(vec!["login".to_string(), "-a".to_string()], true);
let mut process = Process::new(
@@ -558,7 +557,7 @@ impl Perforce {
process.run(None, indexmap::IndexMap::new())
}
- pub fn p4_login(&mut self) -> Result<()> {
+ pub fn p4_login(&mut self) -> anyhow::Result<()> {
self.query_p4_user();
if !self.is_logged_in()? {
let password = self.query_p4_password();
@@ -597,7 +596,7 @@ impl Perforce {
pub fn get_composer_information(
&mut self,
identifier: &str,
- ) -> Result<Option<IndexMap<String, PhpMixed>>> {
+ ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> {
let composer_file_content = self.get_file_content("composer.json", identifier);
let composer_file_content = match composer_file_content {
@@ -842,11 +841,11 @@ impl Perforce {
pub trait PerforceInterface: std::fmt::Debug {
fn initialize_path(&mut self, path: &str);
fn set_stream(&mut self, stream: &str);
- fn p4_login(&mut self) -> Result<()>;
+ fn p4_login(&mut self) -> anyhow::Result<()>;
fn check_stream(&mut self) -> bool;
- fn write_p4_client_spec(&mut self) -> Result<()>;
- fn connect_client(&mut self) -> Result<()>;
- fn sync_code_base(&mut self, source_reference: Option<String>) -> Result<()>;
+ fn write_p4_client_spec(&mut self) -> anyhow::Result<()>;
+ fn connect_client(&mut self) -> anyhow::Result<()>;
+ fn sync_code_base(&mut self, source_reference: Option<String>) -> anyhow::Result<()>;
fn cleanup_client_spec(&mut self);
fn get_commit_logs(&mut self, from_reference: &str, to_reference: &str) -> Option<String>;
fn get_file_content(&mut self, file: &str, identifier: &str) -> Option<String>;
@@ -856,7 +855,7 @@ pub trait PerforceInterface: std::fmt::Debug {
fn get_composer_information(
&mut self,
identifier: &str,
- ) -> Result<Option<IndexMap<String, PhpMixed>>>;
+ ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>>;
}
impl PerforceInterface for Perforce {
@@ -868,7 +867,7 @@ impl PerforceInterface for Perforce {
Perforce::set_stream(self, stream)
}
- fn p4_login(&mut self) -> Result<()> {
+ fn p4_login(&mut self) -> anyhow::Result<()> {
Perforce::p4_login(self)
}
@@ -876,15 +875,15 @@ impl PerforceInterface for Perforce {
Perforce::check_stream(self)
}
- fn write_p4_client_spec(&mut self) -> Result<()> {
+ fn write_p4_client_spec(&mut self) -> anyhow::Result<()> {
Perforce::write_p4_client_spec(self)
}
- fn connect_client(&mut self) -> Result<()> {
+ fn connect_client(&mut self) -> anyhow::Result<()> {
Perforce::connect_client(self)
}
- fn sync_code_base(&mut self, source_reference: Option<String>) -> Result<()> {
+ fn sync_code_base(&mut self, source_reference: Option<String>) -> anyhow::Result<()> {
Perforce::sync_code_base(self, source_reference.as_deref())
}
@@ -915,7 +914,7 @@ impl PerforceInterface for Perforce {
fn get_composer_information(
&mut self,
identifier: &str,
- ) -> Result<Option<IndexMap<String, PhpMixed>>> {
+ ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> {
Perforce::get_composer_information(self, identifier)
}
}
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs
index b3b7e2b..45ddb30 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -2,7 +2,6 @@
use crate::util::ProcessExecutor;
use crate::util::Silencer;
-use anyhow::Result;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
PHP_ENV, PHP_SERVER, PhpMixed, PhpResource, RuntimeException, defined, file_exists,
@@ -24,7 +23,7 @@ impl Platform {
/// getcwd() equivalent which always returns a string
///
/// @throws \RuntimeException
- pub fn get_cwd(allow_empty: bool) -> Result<String> {
+ pub fn get_cwd(allow_empty: bool) -> anyhow::Result<String> {
let mut cwd = getcwd();
// fallback to realpath('') just in case this works but odds are it would break as well if we are in a case where getcwd fails
@@ -144,7 +143,7 @@ impl Platform {
/// @throws \RuntimeException If the user home could not reliably be determined
/// @return string The formal user home as detected from environment parameters
- pub fn get_user_directory() -> Result<String> {
+ pub fn get_user_directory() -> anyhow::Result<String> {
if let Some(home) = Self::get_env("HOME") {
return Ok(home);
}
@@ -378,7 +377,7 @@ impl Platform {
if php_os_family() == "Linux" {
let mut process = ProcessExecutor::new(None);
let mut output = String::new();
- let result: Result<()> = (|| {
+ let result: anyhow::Result<()> = (|| {
if process.execute_args(&["lsmod".to_string()], &mut output, None) == 0
&& shirabe_php_shim::str_contains(&output, "vboxguest")
{
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index 230695a..463e511 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -5,7 +5,6 @@ use crate::io::IOInterfaceImmutable;
use crate::io::io_interface;
use crate::util::GitHub;
use crate::util::Platform;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::seld::signal::SignalHandler;
@@ -170,7 +169,12 @@ impl ProcessExecutor {
}
/// runs a process on the commandline
- pub fn execute<'o, C, O>(&mut self, command: C, output: O, cwd: Option<&str>) -> Result<i64>
+ pub fn execute<'o, C, O>(
+ &mut self,
+ command: C,
+ output: O,
+ cwd: Option<&str>,
+ ) -> anyhow::Result<i64>
where
C: IntoExecCommand,
O: IntoExecOutput<'o>,
@@ -201,7 +205,7 @@ impl ProcessExecutor {
}
/// runs a process on the commandline in TTY mode
- pub fn execute_tty<C>(&mut self, command: C, cwd: Option<&str>) -> Result<i64>
+ pub fn execute_tty<C>(&mut self, command: C, cwd: Option<&str>) -> anyhow::Result<i64>
where
C: IntoExecCommand,
{
@@ -220,7 +224,7 @@ impl ProcessExecutor {
env: Option<IndexMap<String, String>>,
tty: bool,
output: O,
- ) -> Result<Option<i64>>
+ ) -> anyhow::Result<Option<i64>>
where
O: IntoExecOutput<'o>,
{
@@ -302,7 +306,7 @@ impl ProcessExecutor {
}),
);
- let result: Result<()> = (|| -> Result<()> {
+ let result: anyhow::Result<()> = (|| -> anyhow::Result<()> {
match output.to_callback() {
Ok(callback) => {
process.run(Some(callback), IndexMap::new())?;
@@ -324,7 +328,7 @@ impl ProcessExecutor {
self.error_output = process.get_error_output()?;
Ok(())
})();
- let final_result: Result<()> = match result {
+ let final_result: anyhow::Result<()> = match result {
Ok(()) => Ok(()),
Err(e) => {
if let Some(pse) = e.downcast_ref::<ProcessSignaledException>() {
@@ -352,7 +356,7 @@ impl ProcessExecutor {
cwd: Option<&str>,
tty: bool,
output: O,
- ) -> Result<i64>
+ ) -> anyhow::Result<i64>
where
O: IntoExecOutput<'o>,
{
@@ -409,7 +413,7 @@ impl ProcessExecutor {
command: PhpMixed,
cwd: Option<&str>,
output: O,
- ) -> Result<i64>
+ ) -> anyhow::Result<i64>
where
O: IntoExecOutput<'o>,
{
@@ -574,7 +578,11 @@ impl ProcessExecutor {
}
/// starts a process on the commandline in async mode
- pub async fn execute_async<C>(&mut self, command: C, cwd: Option<&str>) -> Result<Process>
+ pub async fn execute_async<C>(
+ &mut self,
+ command: C,
+ cwd: Option<&str>,
+ ) -> anyhow::Result<Process>
where
C: IntoExecCommand,
{
@@ -677,7 +685,7 @@ impl ProcessExecutor {
self.output_command_run(&command, cwd.as_deref(), true);
- let process_result: Result<Process> = if is_string(&command) {
+ let process_result: anyhow::Result<Process> = if is_string(&command) {
Process::from_shell_commandline(
command.as_string().unwrap_or(""),
cwd.as_deref(),
@@ -760,11 +768,11 @@ impl ProcessExecutor {
}
/// @param ?int $index job id
- pub fn wait(&mut self) -> Result<()> {
+ pub fn wait(&mut self) -> anyhow::Result<()> {
self.wait_id(None)
}
- pub fn wait_id(&mut self, index: Option<i64>) -> Result<()> {
+ pub fn wait_id(&mut self, index: Option<i64>) -> anyhow::Result<()> {
loop {
if 0 == self.count_active_jobs(index)? {
return Ok(());
@@ -780,7 +788,7 @@ impl ProcessExecutor {
}
/// @internal
- pub fn count_active_jobs(&mut self, index: Option<i64>) -> Result<i64> {
+ pub fn count_active_jobs(&mut self, index: Option<i64>) -> anyhow::Result<i64> {
// tick
let ids: Vec<i64> = self.jobs.keys().copied().collect();
for id in &ids {
@@ -1152,7 +1160,7 @@ pub trait IntoExecOutput<'a>: Sized {
/// `Ok(callback)` for a user-supplied output handler (passed straight to `Process::run`),
/// `Err(self)` for the capture/forward cases (a default handler is used and `self` is returned
/// so the captured output can still be written back).
- fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self>;
+ fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self>;
/// Assigns the captured output back to the by-reference target, mirroring PHP's
/// `$output = $process->getOutput()`. Only meaningful when [`capture_output`](Self::capture_output)
@@ -1167,7 +1175,7 @@ impl<'a> IntoExecOutput<'a> for () {
true
}
- fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self> {
+ fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self> {
Err(self)
}
@@ -1181,7 +1189,7 @@ impl<'a> IntoExecOutput<'a> for ProcessForwardOutput {
false
}
- fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self> {
+ fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self> {
Err(self)
}
@@ -1195,7 +1203,7 @@ impl<'a> IntoExecOutput<'a> for &'a mut PhpMixed {
true
}
- fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self> {
+ fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self> {
Err(self)
}
@@ -1211,7 +1219,7 @@ impl<'a> IntoExecOutput<'a> for &'a mut String {
true
}
- fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self> {
+ fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self> {
Err(self)
}
@@ -1228,7 +1236,7 @@ impl<'a> IntoExecOutput<'a> for Box<dyn FnMut(&str, &str) -> bool> {
false
}
- fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self> {
+ fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self> {
Ok(self)
}
diff --git a/crates/shirabe/src/util/silencer.rs b/crates/shirabe/src/util/silencer.rs
index f5ee64d..7286689 100644
--- a/crates/shirabe/src/util/silencer.rs
+++ b/crates/shirabe/src/util/silencer.rs
@@ -1,6 +1,5 @@
//! ref: composer/src/Composer/Util/Silencer.php
-use anyhow::Result;
use shirabe_php_shim::{
E_DEPRECATED, E_NOTICE, E_USER_DEPRECATED, E_USER_NOTICE, E_USER_WARNING, E_WARNING,
error_reporting,
@@ -36,9 +35,9 @@ impl Silencer {
}
}
- pub fn call<F, T>(callable: F) -> Result<T>
+ pub fn call<F, T>(callable: F) -> anyhow::Result<T>
where
- F: FnOnce() -> Result<T>,
+ F: FnOnce() -> anyhow::Result<T>,
{
Self::suppress(None);
match callable() {
diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs
index 5eed44d..4c01a3a 100644
--- a/crates/shirabe/src/util/svn.rs
+++ b/crates/shirabe/src/util/svn.rs
@@ -6,7 +6,6 @@ use crate::io::IOInterfaceImmutable;
use crate::io::io_interface;
use crate::util::Platform;
use crate::util::ProcessExecutor;
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
@@ -92,7 +91,7 @@ impl Svn {
cwd: Option<&str>,
path: Option<&str>,
verbose: bool,
- ) -> Result<String> {
+ ) -> anyhow::Result<String> {
// Ensure we are allowed to use this URL by config
self.config.borrow_mut().prohibit_url_by_config(
url,
@@ -119,7 +118,7 @@ impl Svn {
path: &str,
cwd: Option<&str>,
verbose: bool,
- ) -> Result<String> {
+ ) -> anyhow::Result<String> {
// A local command has no remote url
self.execute_with_auth_retry(command, cwd, "", Some(path), verbose)
.map(|o| o.unwrap_or_default())
@@ -133,7 +132,7 @@ impl Svn {
url: &str,
path: Option<&str>,
verbose: bool,
- ) -> Result<Option<String>> {
+ ) -> anyhow::Result<Option<String>> {
// Regenerate the command at each try, to use the newly user-provided credentials
let command = self.get_command(svn_command.clone(), url, path);
@@ -212,7 +211,7 @@ impl Svn {
/// Repositories requests credentials, let's put them in.
///
/// @throws \RuntimeException
- pub(crate) fn do_auth_dance(&mut self) -> Result<&mut Self> {
+ pub(crate) fn do_auth_dance(&mut self) -> anyhow::Result<&mut Self> {
// cannot ask for credentials in non interactive mode
if !self.io.is_interactive() {
return Err(RuntimeException {
@@ -314,7 +313,7 @@ impl Svn {
/// Get the password for the svn command. Can be empty.
///
/// @throws \LogicException
- pub(crate) fn get_password(&self) -> Result<String> {
+ pub(crate) fn get_password(&self) -> anyhow::Result<String> {
if self.credentials.is_none() {
return Err(LogicException {
message: "No svn auth detected.".to_string(),
@@ -329,7 +328,7 @@ impl Svn {
/// Get the username for the svn command.
///
/// @throws \LogicException
- pub(crate) fn get_username(&self) -> Result<String> {
+ pub(crate) fn get_username(&self) -> anyhow::Result<String> {
if self.credentials.is_none() {
return Err(LogicException {
message: "No svn auth detected.".to_string(),
diff --git a/crates/shirabe/src/util/sync_helper.rs b/crates/shirabe/src/util/sync_helper.rs
index 1014b86..68267ec 100644
--- a/crates/shirabe/src/util/sync_helper.rs
+++ b/crates/shirabe/src/util/sync_helper.rs
@@ -4,7 +4,6 @@ use crate::downloader::DownloadManagerInterface;
use crate::downloader::DownloaderInterface;
use crate::package::PackageInterfaceHandle;
use crate::util::r#loop::Loop;
-use anyhow::Result;
use shirabe_php_shim::PhpMixed;
pub enum DownloaderOrManager<'a> {
@@ -18,7 +17,7 @@ impl<'a> DownloaderOrManager<'a> {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
match self {
Self::Interface(d) => d.borrow_mut().download3(package, path, prev_package).await,
Self::Manager(d) => d.borrow().download(package, path, prev_package).await,
@@ -31,7 +30,7 @@ impl<'a> DownloaderOrManager<'a> {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
match self {
Self::Interface(d) => {
d.borrow_mut()
@@ -50,7 +49,7 @@ impl<'a> DownloaderOrManager<'a> {
&self,
package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
match self {
Self::Interface(d) => d.borrow_mut().install2(package, path).await,
Self::Manager(d) => d.borrow().install(package, path).await,
@@ -62,7 +61,7 @@ impl<'a> DownloaderOrManager<'a> {
package: PackageInterfaceHandle,
prev_package: PackageInterfaceHandle,
path: &str,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
match self {
Self::Interface(d) => d.borrow_mut().update(package, prev_package, path).await,
Self::Manager(d) => d.borrow().update(package, prev_package, path).await,
@@ -75,7 +74,7 @@ impl<'a> DownloaderOrManager<'a> {
package: PackageInterfaceHandle,
path: &str,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<Option<PhpMixed>> {
+ ) -> anyhow::Result<Option<PhpMixed>> {
match self {
Self::Interface(d) => {
d.borrow_mut()
@@ -100,14 +99,14 @@ impl SyncHelper {
path: String,
package: PackageInterfaceHandle,
prev_package: Option<PackageInterfaceHandle>,
- ) -> Result<()> {
+ ) -> anyhow::Result<()> {
let r#type = if prev_package.is_some() {
"update"
} else {
"install"
};
- let result: Result<()> = (|| -> Result<()> {
+ let result: anyhow::Result<()> = (|| -> anyhow::Result<()> {
Self::r#await(
r#loop,
Some(Box::pin(async {
@@ -176,8 +175,10 @@ impl SyncHelper {
pub fn r#await(
r#loop: &std::rc::Rc<std::cell::RefCell<Loop>>,
- promise: Option<std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>> + '_>>>,
- ) -> Result<()> {
+ promise: Option<
+ std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>> + '_>>,
+ >,
+ ) -> anyhow::Result<()> {
if let Some(promise) = promise {
crate::util::sync_executor::block_on(r#loop.borrow_mut().wait(vec![promise], None))?;
}
diff --git a/crates/shirabe/src/util/tar.rs b/crates/shirabe/src/util/tar.rs
index 95a6fde..55b6a96 100644
--- a/crates/shirabe/src/util/tar.rs
+++ b/crates/shirabe/src/util/tar.rs
@@ -1,13 +1,12 @@
//! ref: composer/src/Composer/Util/Tar.php
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{PharData, RuntimeException};
pub struct Tar;
impl Tar {
- pub fn get_composer_json(path_to_archive: &str) -> Result<Option<String>> {
+ pub fn get_composer_json(path_to_archive: &str) -> anyhow::Result<Option<String>> {
let phar = PharData::new(path_to_archive.to_string());
if !phar.valid() {
@@ -17,7 +16,7 @@ impl Tar {
Ok(Some(Self::extract_composer_json_from_folder(&phar)?))
}
- fn extract_composer_json_from_folder(phar: &PharData) -> Result<String> {
+ fn extract_composer_json_from_folder(phar: &PharData) -> anyhow::Result<String> {
if let Some(file) = phar.get("composer.json") {
return Ok(file.get_content());
}
diff --git a/crates/shirabe/src/util/zip.rs b/crates/shirabe/src/util/zip.rs
index dbb2627..a671d63 100644
--- a/crates/shirabe/src/util/zip.rs
+++ b/crates/shirabe/src/util/zip.rs
@@ -1,6 +1,5 @@
//! ref: composer/src/Composer/Util/Zip.php
-use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{
RuntimeException, ZipArchive, dirname, extension_loaded, implode, stream_get_contents,
@@ -9,7 +8,7 @@ use shirabe_php_shim::{
pub struct Zip;
impl Zip {
- pub fn get_composer_json(path_to_zip: &str) -> Result<Option<String>> {
+ pub fn get_composer_json(path_to_zip: &str) -> anyhow::Result<Option<String>> {
if !extension_loaded("zip") {
return Err(RuntimeException {
message: "The Zip Util requires PHP's zip extension".to_string(),
@@ -43,7 +42,7 @@ impl Zip {
Ok(content)
}
- fn locate_file(zip: &ZipArchive, filename: &str) -> Result<i64> {
+ fn locate_file(zip: &ZipArchive, filename: &str) -> anyhow::Result<i64> {
// return root composer.json if it is there and is a file
if let Some(index) = zip.locate_name(filename)
&& zip.get_from_index(index).is_some()
diff --git a/scripts/lint b/scripts/lint
index 89f5fe0..c9e3304 100755
--- a/scripts/lint
+++ b/scripts/lint
@@ -5,6 +5,7 @@ require 'pathname'
LINTERS = {
cargo_workspace_dependencies: [],
contiguous_use_block: [],
+ no_banned_use: [],
no_decorative_section_comment: %w[
crates/shirabe-semver/src/version_parser.rs
],
diff --git a/scripts/linters/no_banned_use.rb b/scripts/linters/no_banned_use.rb
new file mode 100644
index 0000000..341a2b9
--- /dev/null
+++ b/scripts/linters/no_banned_use.rb
@@ -0,0 +1,112 @@
+BANNED_USE_PATHS = %w[
+ anyhow::Result
+].freeze
+
+def no_banned_use(root_dir, excludes = [])
+ pattern = root_dir.join('crates', '**', '*.rs').to_s
+ errors = Dir.glob(pattern).sort.flat_map do |path|
+ relative = Pathname.new(path).relative_path_from(root_dir).to_s
+ next [] if excludes.include?(relative)
+
+ find_banned_uses(path, relative)
+ end
+
+ return true if errors.empty?
+
+ puts 'Found banned `use` imports.'
+ puts 'These items must always be referenced by their fully-qualified path:'
+ errors.each do |err|
+ puts " #{err}"
+ end
+ false
+end
+
+BANNED_USE_START_RE = /\A(?:pub(?:\([^)]*\))?\s+)?use\b/
+
+def find_banned_uses(path, relative)
+ errors = []
+ lines = File.readlines(path)
+ buffer = nil
+ start_idx = nil
+
+ lines.each_with_index do |raw, idx|
+ code = raw.split('//', 2).first || raw
+ stripped = code.strip
+
+ if buffer.nil?
+ next unless stripped =~ BANNED_USE_START_RE
+
+ buffer = +''
+ start_idx = idx
+ end
+
+ buffer << ' ' << stripped
+ next unless buffer.include?(';')
+
+ tree = buffer[/\buse\s+(.*?);/m, 1]
+ expand_use_tree(tree).each do |full|
+ next unless BANNED_USE_PATHS.include?(full)
+
+ errors << "#{relative}:#{start_idx + 1}: `use #{full}` is banned (fully qualify as `#{full}` instead)"
+ end
+
+ buffer = nil
+ end
+
+ errors.uniq
+end
+
+def expand_use_tree(tree)
+ return [] if tree.nil?
+
+ tree = tree.strip
+ brace = tree.index('{')
+
+ if brace.nil?
+ return [strip_use_alias(tree)].reject(&:empty?)
+ end
+
+ prefix = tree[0...brace].sub(/::\s*\z/, '').strip
+ inner = tree[(brace + 1)..].sub(/\}\s*\z/, '')
+
+ split_top_level(inner).flat_map do |child|
+ expand_use_tree(child).map do |sub|
+ if sub.empty? || sub == 'self'
+ prefix
+ elsif prefix.empty?
+ sub
+ else
+ "#{prefix}::#{sub}"
+ end
+ end
+ end
+end
+
+def strip_use_alias(segment)
+ segment.sub(/\s+as\s+\S+\s*\z/, '').strip
+end
+
+def split_top_level(str)
+ parts = []
+ current = +''
+ depth = 0
+
+ str.each_char do |ch|
+ case ch
+ when '{' then depth += 1; current << ch
+ when '}' then depth -= 1; current << ch
+ when ','
+ if depth.zero?
+ parts << current
+ current = +''
+ else
+ current << ch
+ end
+ else
+ current << ch
+ end
+ end
+ parts << current
+
+ parts.map(&:strip).reject(&:empty?)
+end