aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe-class-map-generator/src/class_map.rs4
-rw-r--r--crates/shirabe-class-map-generator/src/class_map_generator.rs23
-rw-r--r--crates/shirabe-class-map-generator/src/php_file_cleaner.rs6
-rw-r--r--crates/shirabe-class-map-generator/src/php_file_parser.rs4
-rw-r--r--crates/shirabe-external-packages/src/composer/pcre/preg.rs104
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs4
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs4
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs4
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/table.rs3
-rw-r--r--crates/shirabe/src/advisory/auditor.rs2
-rw-r--r--crates/shirabe/src/advisory/partial_security_advisory.rs2
-rw-r--r--crates/shirabe/src/autoload/autoload_generator.rs30
-rw-r--r--crates/shirabe/src/cache.rs27
-rw-r--r--crates/shirabe/src/command/archive_command.rs4
-rw-r--r--crates/shirabe/src/command/bump_command.rs7
-rw-r--r--crates/shirabe/src/command/config_command.rs203
-rw-r--r--crates/shirabe/src/command/create_project_command.rs3
-rw-r--r--crates/shirabe/src/command/diagnose_command.rs1
-rw-r--r--crates/shirabe/src/command/fund_command.rs2
-rw-r--r--crates/shirabe/src/command/global_command.rs4
-rw-r--r--crates/shirabe/src/command/init_command.rs24
-rw-r--r--crates/shirabe/src/command/package_discovery_trait.rs5
-rw-r--r--crates/shirabe/src/command/reinstall_command.rs2
-rw-r--r--crates/shirabe/src/command/remove_command.rs6
-rw-r--r--crates/shirabe/src/command/repository_command.rs3
-rw-r--r--crates/shirabe/src/command/require_command.rs4
-rw-r--r--crates/shirabe/src/command/script_alias_command.rs2
-rw-r--r--crates/shirabe/src/command/show_command.rs10
-rw-r--r--crates/shirabe/src/command/update_command.rs8
-rw-r--r--crates/shirabe/src/composer.rs2
-rw-r--r--crates/shirabe/src/config.rs13
-rw-r--r--crates/shirabe/src/console/html_output_formatter.rs2
-rw-r--r--crates/shirabe/src/dependency_resolver/lock_transaction.rs8
-rw-r--r--crates/shirabe/src/dependency_resolver/pool_builder.rs6
-rw-r--r--crates/shirabe/src/dependency_resolver/problem.rs24
-rw-r--r--crates/shirabe/src/downloader/download_manager.rs2
-rw-r--r--crates/shirabe/src/downloader/fossil_downloader.rs4
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs51
-rw-r--r--crates/shirabe/src/downloader/svn_downloader.rs48
-rw-r--r--crates/shirabe/src/downloader/zip_downloader.rs4
-rw-r--r--crates/shirabe/src/event_dispatcher/event_dispatcher.rs24
-rw-r--r--crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs8
-rw-r--r--crates/shirabe/src/installer/binary_installer.rs6
-rw-r--r--crates/shirabe/src/installer/library_installer.rs2
-rw-r--r--crates/shirabe/src/installer/suggested_packages_reporter.rs1
-rw-r--r--crates/shirabe/src/io/base_io.rs2
-rw-r--r--crates/shirabe/src/io/buffer_io.rs4
-rw-r--r--crates/shirabe/src/io/console_io.rs6
-rw-r--r--crates/shirabe/src/json/json_file.rs11
-rw-r--r--crates/shirabe/src/json/json_manipulator.rs172
-rw-r--r--crates/shirabe/src/package/archiver/archivable_files_finder.rs3
-rw-r--r--crates/shirabe/src/package/archiver/archive_manager.rs4
-rw-r--r--crates/shirabe/src/package/archiver/base_exclude_filter.rs7
-rw-r--r--crates/shirabe/src/package/archiver/git_exclude_filter.rs2
-rw-r--r--crates/shirabe/src/package/loader/array_loader.rs6
-rw-r--r--crates/shirabe/src/package/loader/root_package_loader.rs23
-rw-r--r--crates/shirabe/src/package/loader/validating_array_loader.rs21
-rw-r--r--crates/shirabe/src/package/locker.rs6
-rw-r--r--crates/shirabe/src/package/package.rs17
-rw-r--r--crates/shirabe/src/package/version/version_bumper.rs9
-rw-r--r--crates/shirabe/src/package/version/version_guesser.rs65
-rw-r--r--crates/shirabe/src/package/version/version_parser.rs4
-rw-r--r--crates/shirabe/src/package/version/version_selector.rs4
-rw-r--r--crates/shirabe/src/platform/version.rs18
-rw-r--r--crates/shirabe/src/plugin/plugin_manager.rs4
-rw-r--r--crates/shirabe/src/question/strict_confirmation_question.rs4
-rw-r--r--crates/shirabe/src/repository/array_repository.rs9
-rw-r--r--crates/shirabe/src/repository/composer_repository.rs28
-rw-r--r--crates/shirabe/src/repository/filesystem_repository.rs6
-rw-r--r--crates/shirabe/src/repository/filter_repository.rs4
-rw-r--r--crates/shirabe/src/repository/package_repository.rs1
-rw-r--r--crates/shirabe/src/repository/path_repository.rs4
-rw-r--r--crates/shirabe/src/repository/platform_repository.rs171
-rw-r--r--crates/shirabe/src/repository/repository_factory.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/forgejo_driver.rs2
-rw-r--r--crates/shirabe/src/repository/vcs/fossil_driver.rs10
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs11
-rw-r--r--crates/shirabe/src/repository/vcs/git_driver.rs26
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs46
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs17
-rw-r--r--crates/shirabe/src/repository/vcs/hg_driver.rs16
-rw-r--r--crates/shirabe/src/repository/vcs/perforce_driver.rs2
-rw-r--r--crates/shirabe/src/repository/vcs/svn_driver.rs26
-rw-r--r--crates/shirabe/src/repository/vcs/vcs_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs_repository.rs8
-rw-r--r--crates/shirabe/src/self_update/versions.rs2
-rw-r--r--crates/shirabe/src/util/auth_helper.rs2
-rw-r--r--crates/shirabe/src/util/composer_mirror.rs12
-rw-r--r--crates/shirabe/src/util/config_validator.rs15
-rw-r--r--crates/shirabe/src/util/filesystem.rs24
-rw-r--r--crates/shirabe/src/util/forgejo_url.rs2
-rw-r--r--crates/shirabe/src/util/git.rs106
-rw-r--r--crates/shirabe/src/util/github.rs6
-rw-r--r--crates/shirabe/src/util/gitlab.rs3
-rw-r--r--crates/shirabe/src/util/hg.rs4
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs8
-rw-r--r--crates/shirabe/src/util/http/response.rs4
-rw-r--r--crates/shirabe/src/util/http_downloader.rs12
-rw-r--r--crates/shirabe/src/util/no_proxy_pattern.rs2
-rw-r--r--crates/shirabe/src/util/perforce.rs3
-rw-r--r--crates/shirabe/src/util/platform.rs3
-rw-r--r--crates/shirabe/src/util/process_executor.rs33
-rw-r--r--crates/shirabe/src/util/remote_filesystem.rs41
-rw-r--r--crates/shirabe/src/util/svn.rs4
-rw-r--r--crates/shirabe/src/util/url.rs33
105 files changed, 723 insertions, 1093 deletions
diff --git a/crates/shirabe-class-map-generator/src/class_map.rs b/crates/shirabe-class-map-generator/src/class_map.rs
index 264fd35..8a29373 100644
--- a/crates/shirabe-class-map-generator/src/class_map.rs
+++ b/crates/shirabe-class-map-generator/src/class_map.rs
@@ -67,9 +67,7 @@ impl ClassMap {
for (class, paths) in &self.ambiguous_classes {
let paths: Vec<String> = paths
.iter()
- .filter(|path| {
- !Preg::is_match(duplicates_filter, &strtr(path, "\\", "/")).unwrap_or(false)
- })
+ .filter(|path| !Preg::is_match(duplicates_filter, &strtr(path, "\\", "/")))
.cloned()
.collect();
if !paths.is_empty() {
diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs
index ba59b33..fa55fac 100644
--- a/crates/shirabe-class-map-generator/src/class_map_generator.rs
+++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs
@@ -169,14 +169,12 @@ impl ClassMapGenerator {
continue;
}
- let is_stream_wrapper_path =
- Preg::is_match(&self.stream_wrappers_regex, &file_path).unwrap_or(false);
+ let is_stream_wrapper_path = Preg::is_match(&self.stream_wrappers_regex, &file_path);
if !Self::is_absolute_path(&file_path) && !is_stream_wrapper_path {
file_path = format!("{}/{}", cwd, file_path);
file_path = Self::normalize_path(&file_path);
} else {
- file_path =
- Preg::replace(r"{(?<!:)[\\/]{2,}}", "/", &file_path).unwrap_or(file_path);
+ file_path = Preg::replace(r"{(?<!:)[\\/]{2,}}", "/", &file_path);
}
if file_path.is_empty() {
@@ -213,11 +211,11 @@ impl ClassMapGenerator {
// check the realpath of the file against the excluded paths as the path might be a symlink and the excluded path is realpath'd so symlink are resolved
if let Some(ref excluded) = excluded {
- if Preg::is_match(excluded, &strtr(&real_path, "\\", "/")).unwrap_or(false) {
+ if Preg::is_match(excluded, &strtr(&real_path, "\\", "/")) {
continue;
}
// check non-realpath of file for directories symlink in project dir
- if Preg::is_match(excluded, &strtr(&file_path, "\\", "/")).unwrap_or(false) {
+ if Preg::is_match(excluded, &strtr(&file_path, "\\", "/")) {
continue;
}
}
@@ -332,14 +330,12 @@ impl ClassMapGenerator {
&format!("{{^{}}}", preg_quote(&cwd, None)),
".",
&Self::normalize_path(file_path),
- )
- .unwrap_or_else(|_| Self::normalize_path(file_path));
+ );
let short_base_path = Preg::replace(
&format!("{{^{}}}", preg_quote(&cwd, None)),
".",
&Self::normalize_path(base_path),
- )
- .unwrap_or_else(|_| Self::normalize_path(base_path));
+ );
for class in rejected_classes {
self.class_map.add_psr_violation(
@@ -385,9 +381,7 @@ impl ClassMapGenerator {
r"{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix",
&path,
Some(&mut r#match),
- )
- .unwrap_or(false)
- {
+ ) {
prefix = r#match
.get(&CaptureKey::ByIndex(1))
.cloned()
@@ -421,8 +415,7 @@ impl ClassMapGenerator {
.to_uppercase()
},
&prefix,
- )
- .unwrap_or(prefix);
+ );
format!("{}{}{}", prefix, absolute, parts.join("/"))
}
diff --git a/crates/shirabe-class-map-generator/src/php_file_cleaner.rs b/crates/shirabe-class-map-generator/src/php_file_cleaner.rs
index 2b53307..2b97d34 100644
--- a/crates/shirabe-class-map-generator/src/php_file_cleaner.rs
+++ b/crates/shirabe-class-map-generator/src/php_file_cleaner.rs
@@ -129,9 +129,7 @@ impl PhpFileCleaner {
Some(&mut r#match),
0,
offset,
- )
- .unwrap_or(false)
- {
+ ) {
return clean
+ r#match
.get(&CaptureKey::ByIndex(0))
@@ -268,6 +266,6 @@ impl PhpFileCleaner {
}
fn r#match(&self, regex: &str, r#match: Option<&mut IndexMap<CaptureKey, String>>) -> bool {
- Preg::is_match5(regex, &self.contents, r#match, 0, self.index).unwrap_or(false)
+ Preg::is_match5(regex, &self.contents, r#match, 0, self.index)
}
}
diff --git a/crates/shirabe-class-map-generator/src/php_file_parser.rs b/crates/shirabe-class-map-generator/src/php_file_parser.rs
index a086d78..323ca05 100644
--- a/crates/shirabe-class-map-generator/src/php_file_parser.rs
+++ b/crates/shirabe-class-map-generator/src/php_file_parser.rs
@@ -68,7 +68,7 @@ impl PhpFileParser {
// return early if there is no chance of matching anything in this file
let pattern = format!("{{\\b(?:class|interface|trait{})\\s}}i", extra_types);
- let max_matches = Preg::match_all(&pattern, &contents)?;
+ let max_matches = Preg::match_all(&pattern, &contents);
if max_matches == 0 {
return Ok(vec![]);
}
@@ -86,7 +86,7 @@ impl PhpFileParser {
et = extra_types
);
let mut matches: IndexMap<_, _> = IndexMap::new();
- Preg::match_all3(&pattern2, &contents, Some(&mut matches))?;
+ Preg::match_all3(&pattern2, &contents, Some(&mut matches));
let mut classes = vec![];
let mut namespace = String::new();
diff --git a/crates/shirabe-external-packages/src/composer/pcre/preg.rs b/crates/shirabe-external-packages/src/composer/pcre/preg.rs
index 14be7a2..2f8c46b 100644
--- a/crates/shirabe-external-packages/src/composer/pcre/preg.rs
+++ b/crates/shirabe-external-packages/src/composer/pcre/preg.rs
@@ -11,14 +11,14 @@
use indexmap::IndexMap;
-pub const PREG_PATTERN_ORDER: i64 = 1;
-pub const PREG_SET_ORDER: i64 = 2;
-pub const PREG_OFFSET_CAPTURE: i64 = 256;
-pub const PREG_UNMATCHED_AS_NULL: i64 = 512;
-pub const PREG_SPLIT_NO_EMPTY: i64 = 1;
-pub const PREG_SPLIT_DELIM_CAPTURE: i64 = 2;
-pub const PREG_SPLIT_OFFSET_CAPTURE: i64 = 4;
-pub const PREG_GREP_INVERT: i64 = 1;
+const PREG_PATTERN_ORDER: i64 = 1;
+const PREG_SET_ORDER: i64 = 2;
+const PREG_OFFSET_CAPTURE: i64 = 256;
+const PREG_UNMATCHED_AS_NULL: i64 = 512;
+const PREG_SPLIT_NO_EMPTY: i64 = 1;
+const PREG_SPLIT_DELIM_CAPTURE: i64 = 2;
+const PREG_SPLIT_OFFSET_CAPTURE: i64 = 4;
+const PREG_GREP_INVERT: i64 = 1;
#[derive(Debug)]
pub struct Preg;
@@ -28,7 +28,7 @@ impl Preg {
pattern: &str,
subject: &str,
matches: Option<&mut IndexMap<CaptureKey, String>>,
- ) -> anyhow::Result<bool> {
+ ) -> bool {
Self::match5(pattern, subject, matches, 0, 0)
}
@@ -38,7 +38,7 @@ impl Preg {
matches: Option<&mut IndexMap<CaptureKey, String>>,
flags: i64,
offset: usize,
- ) -> anyhow::Result<bool> {
+ ) -> bool {
Self::check_offset_capture(flags, "matchWithOffsets");
let mut internal: IndexMap<CaptureKey, Option<String>> = IndexMap::new();
@@ -55,10 +55,10 @@ impl Preg {
*out = drop_null_matches(internal);
}
- Ok(result == 1)
+ result == 1
}
- pub fn match_all(pattern: &str, subject: &str) -> anyhow::Result<usize> {
+ pub fn match_all(pattern: &str, subject: &str) -> usize {
Self::match_all5(pattern, subject, None, 0, 0)
}
@@ -66,7 +66,7 @@ impl Preg {
pattern: &str,
subject: &str,
matches: Option<&mut IndexMap<CaptureKey, Vec<String>>>,
- ) -> anyhow::Result<usize> {
+ ) -> usize {
Self::match_all5(pattern, subject, matches, 0, 0)
}
@@ -76,7 +76,7 @@ impl Preg {
matches: Option<&mut IndexMap<CaptureKey, Vec<String>>>,
flags: i64,
offset: usize,
- ) -> anyhow::Result<usize> {
+ ) -> usize {
Self::check_offset_capture(flags, "matchAllWithOffsets");
Self::check_set_order(flags);
@@ -94,7 +94,7 @@ impl Preg {
*out = null_to_empty_match_all(internal);
}
- Ok(result as usize)
+ result as usize
}
pub fn match_all_with_offsets5(
@@ -103,7 +103,7 @@ impl Preg {
matches: Option<&mut IndexMap<CaptureKey, Vec<(String, usize)>>>,
flags: i64,
offset: usize,
- ) -> anyhow::Result<usize> {
+ ) -> usize {
Self::check_set_order(flags);
let mut internal: IndexMap<CaptureKey, Vec<(Option<String>, i64)>> = IndexMap::new();
@@ -120,19 +120,14 @@ impl Preg {
*out = null_to_empty_offset_match_all(internal);
}
- Ok(result as usize)
+ result as usize
}
- pub fn replace(pattern: &str, replacement: &str, subject: &str) -> anyhow::Result<String> {
+ pub fn replace(pattern: &str, replacement: &str, subject: &str) -> String {
Self::replace_impl(pattern, replacement, subject, -1, None)
}
- pub fn replace4(
- pattern: &str,
- replacement: &str,
- subject: &str,
- limit: i64,
- ) -> anyhow::Result<String> {
+ pub fn replace4(pattern: &str, replacement: &str, subject: &str, limit: i64) -> String {
Self::replace_impl(pattern, replacement, subject, limit, None)
}
@@ -142,7 +137,7 @@ impl Preg {
subject: &str,
limit: i64,
count: &mut usize,
- ) -> anyhow::Result<String> {
+ ) -> String {
Self::replace_impl(pattern, replacement, subject, limit, Some(count))
}
@@ -152,19 +147,18 @@ impl Preg {
subject: &str,
limit: i64,
count: Option<&mut usize>,
- ) -> anyhow::Result<String> {
+ ) -> String {
// `$subject` is statically a string here, so the is_scalar/is_array
// guards (ARRAY_MSG / INVALID_TYPE_MSG) of the PHP original are
// unreachable and not reproduced.
- Ok(preg_replace(pattern, replacement, subject, limit, count)
- .unwrap_or_else(|| invalid_regex()))
+ preg_replace(pattern, replacement, subject, limit, count).unwrap_or_else(|| invalid_regex())
}
pub fn replace_callback<F: FnMut(&IndexMap<CaptureKey, String>) -> String>(
pattern: &str,
replacement: F,
subject: &str,
- ) -> anyhow::Result<String> {
+ ) -> String {
Self::replace_callback6(pattern, replacement, subject, -1, None, 0)
}
@@ -175,44 +169,37 @@ impl Preg {
limit: i64,
count: Option<&mut usize>,
flags: i64,
- ) -> anyhow::Result<String> {
+ ) -> String {
let adapter = |internal: &IndexMap<CaptureKey, Option<String>>| -> String {
replacement(&drop_null_matches_ref(internal))
};
- Ok(
- preg_replace_callback(pattern, adapter, subject, limit, count, flags)
- .unwrap_or_else(|| invalid_regex()),
- )
+ preg_replace_callback(pattern, adapter, subject, limit, count, flags)
+ .unwrap_or_else(|| invalid_regex())
}
- pub fn split(pattern: &str, subject: &str) -> anyhow::Result<Vec<String>> {
+ pub fn split(pattern: &str, subject: &str) -> Vec<String> {
Self::split4(pattern, subject, -1, 0)
}
- pub fn split4(
- pattern: &str,
- subject: &str,
- limit: i64,
- flags: i64,
- ) -> anyhow::Result<Vec<String>> {
+ pub fn split4(pattern: &str, subject: &str, limit: i64, flags: i64) -> Vec<String> {
assert!(
flags & PREG_SPLIT_OFFSET_CAPTURE == 0,
"PREG_SPLIT_OFFSET_CAPTURE is not supported as it changes the type of $matches, use splitWithOffsets() instead"
);
- Ok(preg_split(pattern, subject, limit, flags).unwrap_or_else(|| invalid_regex()))
+ preg_split(pattern, subject, limit, flags).unwrap_or_else(|| invalid_regex())
}
- pub fn grep(pattern: &str, array: &[&str]) -> anyhow::Result<Vec<String>> {
+ pub fn grep(pattern: &str, array: &[&str]) -> Vec<String> {
Self::grep3(pattern, array, 0)
}
- pub fn grep3(pattern: &str, array: &[&str], flags: i64) -> anyhow::Result<Vec<String>> {
- Ok(preg_grep(pattern, array, flags).unwrap_or_else(|| invalid_regex()))
+ pub fn grep3(pattern: &str, array: &[&str], flags: i64) -> Vec<String> {
+ preg_grep(pattern, array, flags).unwrap_or_else(|| invalid_regex())
}
- pub fn is_match(pattern: &str, subject: &str) -> anyhow::Result<bool> {
+ pub fn is_match(pattern: &str, subject: &str) -> bool {
Self::match5(pattern, subject, None, 0, 0)
}
@@ -220,7 +207,7 @@ impl Preg {
pattern: &str,
subject: &str,
matches: Option<&mut IndexMap<CaptureKey, String>>,
- ) -> anyhow::Result<bool> {
+ ) -> bool {
Self::match5(pattern, subject, matches, 0, 0)
}
@@ -230,7 +217,7 @@ impl Preg {
matches: Option<&mut IndexMap<CaptureKey, String>>,
flags: i64,
offset: usize,
- ) -> anyhow::Result<bool> {
+ ) -> bool {
Self::match5(pattern, subject, matches, flags, offset)
}
@@ -238,7 +225,7 @@ impl Preg {
pattern: &str,
subject: &str,
matches: &mut IndexMap<String, String>,
- ) -> anyhow::Result<bool> {
+ ) -> bool {
let mut internal: IndexMap<CaptureKey, Option<String>> = IndexMap::new();
let result = preg_match(
pattern,
@@ -256,13 +243,10 @@ impl Preg {
}
}
- Ok(result == 1)
+ result == 1
}
- pub fn is_match_with_indexed_captures(
- pattern: &str,
- subject: &str,
- ) -> anyhow::Result<Option<Vec<String>>> {
+ pub fn is_match_with_indexed_captures(pattern: &str, subject: &str) -> Option<Vec<String>> {
// Classic preg_match semantics (no PREG_UNMATCHED_AS_NULL): trailing
// unmatched groups are truncated, interior unmatched groups become "".
let mut internal: IndexMap<CaptureKey, Option<String>> = IndexMap::new();
@@ -270,7 +254,7 @@ impl Preg {
.unwrap_or_else(|| invalid_regex());
if result == 0 {
- return Ok(None);
+ return None;
}
let max_index = internal
@@ -291,23 +275,23 @@ impl Preg {
captures.push(value);
}
- Ok(Some(captures))
+ Some(captures)
}
pub fn is_match_all3(
pattern: &str,
subject: &str,
matches: Option<&mut IndexMap<CaptureKey, Vec<String>>>,
- ) -> anyhow::Result<bool> {
- Ok(Self::match_all5(pattern, subject, matches, 0, 0)? > 0)
+ ) -> bool {
+ Self::match_all5(pattern, subject, matches, 0, 0) > 0
}
pub fn is_match_all_with_offsets3(
pattern: &str,
subject: &str,
matches: Option<&mut IndexMap<CaptureKey, Vec<(String, usize)>>>,
- ) -> anyhow::Result<bool> {
- Ok(Self::match_all_with_offsets5(pattern, subject, matches, 0, 0)? > 0)
+ ) -> bool {
+ Self::match_all_with_offsets5(pattern, subject, matches, 0, 0) > 0
}
fn check_offset_capture(flags: i64, use_function_name: &str) {
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs
index 8561a69..f89d48e 100644
--- a/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs
@@ -176,7 +176,7 @@ impl JsonDescriptor {
"/\\s*[\\r\\n]\\s*/",
" ",
argument.get_description(),
- )?),
+ )),
);
data.insert(
"default".to_string(),
@@ -237,7 +237,7 @@ impl JsonDescriptor {
"/\\s*[\\r\\n]\\s*/",
" ",
option.get_description(),
- )?),
+ )),
);
data.insert(
"default".to_string(),
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs
index aa4c0e7..93928e7 100644
--- a/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs
@@ -55,7 +55,7 @@ impl MarkdownDescriptor {
if !argument.get_description().is_empty() {
format!(
"{}\n\n",
- Preg::replace("/\\s*[\\r\\n]\\s*/", "\n", argument.get_description())?
+ Preg::replace("/\\s*[\\r\\n]\\s*/", "\n", argument.get_description())
)
} else {
String::new()
@@ -93,7 +93,7 @@ impl MarkdownDescriptor {
if !option.get_description().is_empty() {
format!(
"{}\n\n",
- Preg::replace("/\\s*[\\r\\n]\\s*/", "\n", option.get_description())?
+ Preg::replace("/\\s*[\\r\\n]\\s*/", "\n", option.get_description())
)
} else {
String::new()
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
index 221a341..d330447 100644
--- a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
@@ -70,7 +70,7 @@ impl TextDescriptor {
shirabe_php_shim::str_repeat(" ", (total_width + 4) as usize)
),
argument.get_description(),
- )?),
+ )),
PhpMixed::String(default),
),
&options,
@@ -148,7 +148,7 @@ impl TextDescriptor {
shirabe_php_shim::str_repeat(" ", (total_width + 4) as usize)
),
option.get_description(),
- )?),
+ )),
PhpMixed::String(default),
PhpMixed::String(if option.is_array() {
"<comment> (multiple values allowed)</comment>".to_string()
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs
index f3bdcb0..71d6c78 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs
@@ -677,8 +677,7 @@ impl Table {
let is_not_styled_by_tag = !Preg::is_match(
"/^<(\\w+|(\\w+=[\\w,]+;?)*)>.+<\\/(\\w+|(\\w+=\\w+;?)*)?>$/",
&cell_str,
- )
- .unwrap();
+ );
if is_not_styled_by_tag {
let cell_style = Self::cell_get_style(&cell).unwrap();
match cell_style.get_cell_format() {
diff --git a/crates/shirabe/src/advisory/auditor.rs b/crates/shirabe/src/advisory/auditor.rs
index c7558f4..0c4d80f 100644
--- a/crates/shirabe/src/advisory/auditor.rs
+++ b/crates/shirabe/src/advisory/auditor.rs
@@ -282,7 +282,7 @@ impl Auditor {
continue;
};
if pkg.is_abandoned()
- && (filter.is_none() || !Preg::is_match(filter.as_ref().unwrap(), &pkg.get_name())?)
+ && (filter.is_none() || !Preg::is_match(filter.as_ref().unwrap(), &pkg.get_name()))
{
result.push(pkg);
}
diff --git a/crates/shirabe/src/advisory/partial_security_advisory.rs b/crates/shirabe/src/advisory/partial_security_advisory.rs
index f72ecaa..352e562 100644
--- a/crates/shirabe/src/advisory/partial_security_advisory.rs
+++ b/crates/shirabe/src/advisory/partial_security_advisory.rs
@@ -40,7 +40,7 @@ impl PartialSecurityAdvisory {
Err(_) => {
let affected_version =
Preg::replace(r"(^[>=<^~]*[\d.]+).*", "$1", affected_versions_str);
- match parser.parse_constraints(affected_version.as_deref().unwrap_or("")) {
+ match parser.parse_constraints(&affected_version) {
Ok(c) => c,
Err(_) => SimpleConstraint::new(
"==".to_string(),
diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs
index e8883ab..6ceb02c 100644
--- a/crates/shirabe/src/autoload/autoload_generator.rs
+++ b/crates/shirabe/src/autoload/autoload_generator.rs
@@ -517,9 +517,7 @@ impl AutoloadGenerator {
"{ComposerAutoloaderInit([^:\\s]+)::}",
&content,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
suffix = matches.get(&CaptureKey::ByIndex(1)).cloned();
}
}
@@ -702,8 +700,7 @@ impl AutoloadGenerator {
"{^(([^.+*?\\[^\\]$(){}=!<>|:\\\\#-]+|\\\\[.+*?\\[^\\]$(){}=!<>|:#-])*).*}",
"$1",
pattern,
- )
- .unwrap_or_default();
+ );
// if the pattern is not a subset or superset of $dir, it is unrelated and we skip it
let unrelated = (!str_starts_with(&pattern_processed, &dir_match)
&& !str_starts_with(&dir_match, &pattern_processed))
@@ -1069,7 +1066,7 @@ impl AutoloadGenerator {
}
}
- if Preg::is_match("{\\.phar([\\\\/]|$)}", &path).unwrap_or(false) {
+ if Preg::is_match("{\\.phar([\\\\/]|$)}", &path) {
base_dir = format!("'phar://' . {}", base_dir);
}
@@ -1095,9 +1092,7 @@ impl AutoloadGenerator {
let links = array_merge_map(package.get_replaces(), package.get_provides());
for (_k, link) in &links {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3("{^ext-(.+)$}iD", link.get_target(), Some(&mut matches))
- .unwrap_or(false)
- {
+ if Preg::match3("{^ext-(.+)$}iD", link.get_target(), Some(&mut matches)) {
if let Some(ext) = matches.get(&CaptureKey::ByIndex(1)).cloned() {
extension_providers
.entry(ext)
@@ -1141,7 +1136,6 @@ impl AutoloadGenerator {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
if check_platform.as_bool() == Some(true)
&& Preg::match3("{^ext-(.+)$}iD", link.get_target(), Some(&mut matches))
- .unwrap_or(false)
{
let ext_key = matches
.get(&CaptureKey::ByIndex(1))
@@ -1591,11 +1585,8 @@ impl AutoloadGenerator {
);
m
});
- let value = shirabe_php_shim::ltrim(
- &Preg::replace("/^ */m", " $0$0", &value).unwrap_or_default(),
- None,
- );
- let value = Preg::replace("/ +$/m", "", &value).unwrap_or_default();
+ let value = shirabe_php_shim::ltrim(&Preg::replace("/^ */m", " $0$0", &value), None);
+ let value = Preg::replace("/ +$/m", "", &value);
file.push_str(&format!(
" public static ${} = {};\n\n",
@@ -1712,8 +1703,7 @@ impl AutoloadGenerator {
&format!("{{^{}}}", target_dir),
"",
&ltrim(&path_str, Some("\\/")),
- )
- .unwrap_or_default(),
+ ),
Some("\\/"),
);
} else {
@@ -1732,8 +1722,7 @@ impl AutoloadGenerator {
"{/+}",
"/",
&preg_quote(&trim(&strtr(&path_str, "\\", "/"), Some("/")), None),
- )
- .unwrap_or_default();
+ );
// add support for wildcards * and **
let p = shirabe_php_shim::strtr_array(&p, &{
@@ -1762,8 +1751,7 @@ impl AutoloadGenerator {
String::new()
},
&p,
- )
- .unwrap_or_default();
+ );
let updir: Option<String> = updir_cell.into_inner();
let install_path_for_resolve = if install_path.is_empty() {
strtr(&Platform::get_cwd(false).unwrap_or_default(), "\\", "/")
diff --git a/crates/shirabe/src/cache.rs b/crates/shirabe/src/cache.rs
index 47665d0..a193d0b 100644
--- a/crates/shirabe/src/cache.rs
+++ b/crates/shirabe/src/cache.rs
@@ -74,7 +74,6 @@ impl Cache {
pub fn is_usable(path: &str) -> bool {
!Preg::is_match(r"{(^|[\\\\/])(\$null|nul|NUL|/dev/null)([\\\\/]|$)}", path)
- .unwrap_or(false)
}
pub fn is_enabled(&mut self) -> bool {
@@ -104,8 +103,7 @@ impl Cache {
/// @return string|false
pub fn read(&mut self, file: &str) -> Option<String> {
if self.is_enabled() {
- let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file)
- .unwrap_or_default();
+ let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file);
let full_path = format!("{}{}", self.root, file);
if file_exists(&full_path) {
self.io
@@ -122,8 +120,7 @@ impl Cache {
let was_enabled = self.enabled == Some(true);
if self.is_enabled() && !self.read_only {
- let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file)
- .unwrap_or_default();
+ let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file);
self.io
.write_error(&format!("Writing {}{} into cache", self.root, file));
@@ -160,7 +157,7 @@ impl Cache {
r"{^file_put_contents\(\): Only ([0-9]+) of ([0-9]+) bytes written}",
&e.message,
Some(&mut m),
- )? {
+ ) {
// Remove partial file.
unlink(&temp_file_name);
@@ -195,8 +192,7 @@ impl Cache {
/// Copy a file into the cache
pub fn copy_from(&mut self, file: &str, source: &str) -> bool {
if self.is_enabled() && !self.read_only {
- let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file)
- .unwrap_or_default();
+ let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file);
let full_path = format!("{}{}", self.root, file);
self.filesystem
.borrow_mut()
@@ -225,8 +221,7 @@ impl Cache {
/// Copy a file out of the cache
pub fn copy_to(&mut self, file: &str, target: &str) -> Result<bool> {
if self.is_enabled() {
- let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file)
- .unwrap_or_default();
+ let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file);
let full_path = format!("{}{}", self.root, file);
if file_exists(&full_path) {
let touch_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
@@ -277,8 +272,7 @@ impl Cache {
pub fn remove(&mut self, file: &str) -> bool {
if self.is_enabled() && !self.read_only {
- let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file)
- .unwrap_or_default();
+ let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file);
let full_path = format!("{}{}", self.root, file);
if file_exists(&full_path) {
return self
@@ -309,8 +303,7 @@ impl Cache {
/// @phpstan-return int<0, max>|false
pub fn get_age(&mut self, file: &str) -> Option<i64> {
if self.is_enabled() {
- let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file)
- .unwrap_or_default();
+ let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file);
let full_path = format!("{}{}", self.root, file);
if file_exists(&full_path) {
if let Some(mtime) = filemtime(&full_path) {
@@ -385,8 +378,7 @@ impl Cache {
/// @return string|false
pub fn sha1(&mut self, file: &str) -> Option<String> {
if self.is_enabled() {
- let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file)
- .unwrap_or_default();
+ let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file);
let full_path = format!("{}{}", self.root, file);
if file_exists(&full_path) {
return hash_file("sha1", &full_path);
@@ -399,8 +391,7 @@ impl Cache {
/// @return string|false
pub fn sha256(&mut self, file: &str) -> Option<String> {
if self.is_enabled() {
- let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file)
- .unwrap_or_default();
+ let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file);
let full_path = format!("{}{}", self.root, file);
if file_exists(&full_path) {
return hash_file("sha256", &full_path);
diff --git a/crates/shirabe/src/command/archive_command.rs b/crates/shirabe/src/command/archive_command.rs
index 71d353e..ee11ae2 100644
--- a/crates/shirabe/src/command/archive_command.rs
+++ b/crates/shirabe/src/command/archive_command.rs
@@ -284,9 +284,7 @@ impl ArchiveCommand {
r"{@(stable|RC|beta|alpha|dev)$}i",
version_str,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
let m1 = matches
.get(&CaptureKey::ByIndex(1))
.cloned()
diff --git a/crates/shirabe/src/command/bump_command.rs b/crates/shirabe/src/command/bump_command.rs
index 6f947c2..56548a9 100644
--- a/crates/shirabe/src/command/bump_command.rs
+++ b/crates/shirabe/src/command/bump_command.rs
@@ -222,10 +222,7 @@ impl BumpCommand {
let packages_filter = if !packages_filter.is_empty() {
let packages_filter: Vec<String> = packages_filter
.iter()
- .map(|constraint| {
- Preg::replace(r"{[:= ].+}", "", constraint)
- .unwrap_or_else(|_| constraint.clone())
- })
+ .map(|constraint| Preg::replace(r"{[:= ].+}", "", constraint))
.collect();
let mut unique_lower: Vec<String> = packages_filter
.iter()
@@ -235,7 +232,7 @@ impl BumpCommand {
.collect();
let pattern = base_package::package_names_to_regexp(&unique_lower, "{^(?:%s)$}iD");
for (key, reqs) in tasks.iter_mut() {
- reqs.retain(|pkg_name, _| Preg::is_match(&pattern, pkg_name).unwrap_or(false));
+ reqs.retain(|pkg_name, _| Preg::is_match(&pattern, pkg_name));
}
packages_filter
} else {
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index e55b92e..522a9e9 100644
--- a/crates/shirabe/src/command/config_command.rs
+++ b/crates/shirabe/src/command/config_command.rs
@@ -346,9 +346,7 @@ impl ConfigCommand {
"/^repos?(?:itories)?(?:\\.(.+))?/",
&setting_key,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
if matches.get(&CaptureKey::ByIndex(1)).is_none() {
value = data
.get("repositories")
@@ -594,9 +592,7 @@ impl ConfigCommand {
"/^preferred-install\\.(.+)/",
&setting_key,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
if input.borrow().get_option("unset")?.as_bool() == Some(true) {
self.config_source
.as_mut()
@@ -635,9 +631,7 @@ impl ConfigCommand {
"{^allow-plugins\\.([a-zA-Z0-9/*-]+)}",
&setting_key,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
if input.borrow().get_option("unset")?.as_bool() == Some(true) {
self.config_source
.as_mut()
@@ -707,9 +701,7 @@ impl ConfigCommand {
"/^repos?(?:itories)?\\.(.+)/",
&setting_key,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
if input.borrow().get_option("unset")?.as_bool() == Some(true) {
self.config_source
.as_mut()
@@ -774,7 +766,7 @@ impl ConfigCommand {
// handle extra
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3("/^extra\\.(.+)/", &setting_key, Some(&mut matches)).unwrap_or(false) {
+ if Preg::is_match3("/^extra\\.(.+)/", &setting_key, Some(&mut matches)) {
if input.borrow().get_option("unset")?.as_bool() == Some(true) {
self.config_source
.as_mut()
@@ -833,7 +825,7 @@ impl ConfigCommand {
// handle suggest
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3("/^suggest\\.(.+)/", &setting_key, Some(&mut matches)).unwrap_or(false) {
+ if Preg::is_match3("/^suggest\\.(.+)/", &setting_key, Some(&mut matches)) {
if input.borrow().get_option("unset")?.as_bool() == Some(true) {
self.config_source
.as_mut()
@@ -868,8 +860,7 @@ impl ConfigCommand {
// handle platform
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3("/^platform\\.(.+)/", &setting_key, Some(&mut matches)).unwrap_or(false)
- {
+ if Preg::is_match3("/^platform\\.(.+)/", &setting_key, Some(&mut matches)) {
if input.borrow().get_option("unset")?.as_bool() == Some(true) {
self.config_source
.as_mut()
@@ -991,10 +982,20 @@ impl ConfigCommand {
// handle auth
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3("/^(bitbucket-oauth|github-oauth|gitlab-oauth|gitlab-token|http-basic|custom-headers|bearer|forgejo-token)\\.(.+)/", &setting_key, Some(&mut matches)).unwrap_or(false) {
+ if Preg::is_match3(
+ "/^(bitbucket-oauth|github-oauth|gitlab-oauth|gitlab-token|http-basic|custom-headers|bearer|forgejo-token)\\.(.+)/",
+ &setting_key,
+ Some(&mut matches),
+ ) {
if input.borrow().get_option("unset")?.as_bool() == Some(true) {
- self.auth_config_source.as_mut().unwrap().remove_config_setting(&format!("{}.{}", matches[1], matches[2]));
- self.config_source.as_mut().unwrap().remove_config_setting(&format!("{}.{}", matches[1], matches[2]));
+ self.auth_config_source
+ .as_mut()
+ .unwrap()
+ .remove_config_setting(&format!("{}.{}", matches[1], matches[2]));
+ self.config_source
+ .as_mut()
+ .unwrap()
+ .remove_config_setting(&format!("{}.{}", matches[1], matches[2]));
return Ok(0);
}
@@ -1003,23 +1004,60 @@ impl ConfigCommand {
if matches[1] == "bitbucket-oauth" {
if 2 != values.len() {
return Err(RuntimeException {
- message: format!("Expected two arguments (consumer-key, consumer-secret), got {}", values.len()),
+ message: format!(
+ "Expected two arguments (consumer-key, consumer-secret), got {}",
+ values.len()
+ ),
code: 0,
}
.into());
}
- self.config_source.as_mut().unwrap().remove_config_setting(&key);
+ self.config_source
+ .as_mut()
+ .unwrap()
+ .remove_config_setting(&key);
let mut obj: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- obj.insert("consumer-key".to_string(), Box::new(PhpMixed::String(values[0].clone())));
- obj.insert("consumer-secret".to_string(), Box::new(PhpMixed::String(values[1].clone())));
- self.auth_config_source.as_mut().unwrap().add_config_setting(&key, PhpMixed::Array(obj));
+ obj.insert(
+ "consumer-key".to_string(),
+ Box::new(PhpMixed::String(values[0].clone())),
+ );
+ obj.insert(
+ "consumer-secret".to_string(),
+ Box::new(PhpMixed::String(values[1].clone())),
+ );
+ self.auth_config_source
+ .as_mut()
+ .unwrap()
+ .add_config_setting(&key, PhpMixed::Array(obj));
} else if matches[1] == "gitlab-token" && 2 == values.len() {
- self.config_source.as_mut().unwrap().remove_config_setting(&key);
+ self.config_source
+ .as_mut()
+ .unwrap()
+ .remove_config_setting(&key);
let mut obj: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- obj.insert("username".to_string(), Box::new(PhpMixed::String(values[0].clone())));
- obj.insert("token".to_string(), Box::new(PhpMixed::String(values[1].clone())));
- self.auth_config_source.as_mut().unwrap().add_config_setting(&key, PhpMixed::Array(obj));
- } else if in_array(matches[1].as_str().into(), &vec!["github-oauth".to_string(), "gitlab-oauth".to_string(), "gitlab-token".to_string(), "bearer".to_string()].into(), true) {
+ obj.insert(
+ "username".to_string(),
+ Box::new(PhpMixed::String(values[0].clone())),
+ );
+ obj.insert(
+ "token".to_string(),
+ Box::new(PhpMixed::String(values[1].clone())),
+ );
+ self.auth_config_source
+ .as_mut()
+ .unwrap()
+ .add_config_setting(&key, PhpMixed::Array(obj));
+ } else if in_array(
+ matches[1].as_str().into(),
+ &vec![
+ "github-oauth".to_string(),
+ "gitlab-oauth".to_string(),
+ "gitlab-token".to_string(),
+ "bearer".to_string(),
+ ]
+ .into(),
+ true,
+ ) {
if 1 != values.len() {
return Err(RuntimeException {
message: "Too many arguments, expected only one token".to_string(),
@@ -1027,21 +1065,42 @@ impl ConfigCommand {
}
.into());
}
- self.config_source.as_mut().unwrap().remove_config_setting(&key);
- self.auth_config_source.as_mut().unwrap().add_config_setting(&key, PhpMixed::String(values[0].clone()));
+ self.config_source
+ .as_mut()
+ .unwrap()
+ .remove_config_setting(&key);
+ self.auth_config_source
+ .as_mut()
+ .unwrap()
+ .add_config_setting(&key, PhpMixed::String(values[0].clone()));
} else if matches[1] == "http-basic" {
if 2 != values.len() {
return Err(RuntimeException {
- message: format!("Expected two arguments (username, password), got {}", values.len()),
+ message: format!(
+ "Expected two arguments (username, password), got {}",
+ values.len()
+ ),
code: 0,
}
.into());
}
- self.config_source.as_mut().unwrap().remove_config_setting(&key);
+ self.config_source
+ .as_mut()
+ .unwrap()
+ .remove_config_setting(&key);
let mut obj: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- obj.insert("username".to_string(), Box::new(PhpMixed::String(values[0].clone())));
- obj.insert("password".to_string(), Box::new(PhpMixed::String(values[1].clone())));
- self.auth_config_source.as_mut().unwrap().add_config_setting(&key, PhpMixed::Array(obj));
+ obj.insert(
+ "username".to_string(),
+ Box::new(PhpMixed::String(values[0].clone())),
+ );
+ obj.insert(
+ "password".to_string(),
+ Box::new(PhpMixed::String(values[1].clone())),
+ );
+ self.auth_config_source
+ .as_mut()
+ .unwrap()
+ .add_config_setting(&key, PhpMixed::Array(obj));
} else if matches[1] == "custom-headers" {
if values.len() == 0 {
return Err(RuntimeException {
@@ -1056,7 +1115,9 @@ impl ConfigCommand {
for header in &values {
if !is_string(&PhpMixed::String(header.clone())) {
return Err(RuntimeException {
- message: "Headers must be strings in \"Header-Name: Header-Value\" format".to_string(),
+ message:
+ "Headers must be strings in \"Header-Name: Header-Value\" format"
+ .to_string(),
code: 0,
}
.into());
@@ -1064,9 +1125,12 @@ impl ConfigCommand {
// Check if the header is in correct "Name: Value" format
let mut header_parts: IndexMap<CaptureKey, String> = IndexMap::new();
- if !Preg::is_match3("/^[^:]+:\\s*.+$/", header, Some(&mut header_parts)).unwrap_or(false) {
+ if !Preg::is_match3("/^[^:]+:\\s*.+$/", header, Some(&mut header_parts)) {
return Err(RuntimeException {
- message: format!("Header \"{}\" is not in \"Header-Name: Header-Value\" format", header),
+ message: format!(
+ "Header \"{}\" is not in \"Header-Name: Header-Value\" format",
+ header
+ ),
code: 0,
}
.into());
@@ -1075,21 +1139,42 @@ impl ConfigCommand {
formatted_headers.push(Box::new(PhpMixed::String(header.clone())));
}
- self.config_source.as_mut().unwrap().remove_config_setting(&key);
- self.auth_config_source.as_mut().unwrap().add_config_setting(&key, PhpMixed::List(formatted_headers));
+ self.config_source
+ .as_mut()
+ .unwrap()
+ .remove_config_setting(&key);
+ self.auth_config_source
+ .as_mut()
+ .unwrap()
+ .add_config_setting(&key, PhpMixed::List(formatted_headers));
} else if matches[1] == "forgejo-token" {
if 2 != values.len() {
return Err(RuntimeException {
- message: format!("Expected two arguments (username, access token), got {}", values.len()),
+ message: format!(
+ "Expected two arguments (username, access token), got {}",
+ values.len()
+ ),
code: 0,
}
.into());
}
- self.config_source.as_mut().unwrap().remove_config_setting(&key);
+ self.config_source
+ .as_mut()
+ .unwrap()
+ .remove_config_setting(&key);
let mut obj: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- obj.insert("username".to_string(), Box::new(PhpMixed::String(values[0].clone())));
- obj.insert("token".to_string(), Box::new(PhpMixed::String(values[1].clone())));
- self.auth_config_source.as_mut().unwrap().add_config_setting(&key, PhpMixed::Array(obj));
+ obj.insert(
+ "username".to_string(),
+ Box::new(PhpMixed::String(values[0].clone())),
+ );
+ obj.insert(
+ "token".to_string(),
+ Box::new(PhpMixed::String(values[1].clone())),
+ );
+ self.auth_config_source
+ .as_mut()
+ .unwrap()
+ .add_config_setting(&key, PhpMixed::Array(obj));
}
return Ok(0);
@@ -1097,7 +1182,7 @@ impl ConfigCommand {
// handle script
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3("/^scripts\\.(.+)/", &setting_key, Some(&mut matches)).unwrap_or(false) {
+ if Preg::is_match3("/^scripts\\.(.+)/", &setting_key, Some(&mut matches)) {
if input.borrow().get_option("unset")?.as_bool() == Some(true) {
self.config_source
.as_mut()
@@ -1293,9 +1378,7 @@ impl ConfigCommand {
|| (key == "repositories" && k.is_none()))
{
let mut new_k = k.clone().unwrap_or_default();
- new_k.push_str(
- &Preg::replace("{^config\\.}", "", &format!("{}.", key)).unwrap_or_default(),
- );
+ new_k.push_str(&Preg::replace("{^config\\.}", "", &format!("{}.", key)));
k = Some(new_k);
self.list_configuration(
value_inner,
@@ -1353,14 +1436,13 @@ impl ConfigCommand {
} else {
k.clone().unwrap()
};
- let id = Preg::replace("{\\..*$}", "", &id_source).unwrap_or_default();
+ let id = Preg::replace("{\\..*$}", "", &id_source);
let id = Preg::replace(
"{[^a-z0-9]}i",
"-",
&strtolower(&shirabe_php_shim::trim(&id, Some(" \t\n\r\0\u{0B}"))),
- )
- .unwrap_or_default();
- let id = Preg::replace("{-+}", "-", &id).unwrap_or_default();
+ );
+ let id = Preg::replace("{-+}", "-", &id);
link = format!("https://getcomposer.org/doc/06-config.md#{}", id);
}
if is_string(&raw_val)
@@ -1594,14 +1676,11 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"cache-files-maxsize".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(
- Preg::is_match3(
- "/^\\s*([0-9.]+)\\s*(?:([kmg])(?:i?b)?)?\\s*$/i",
- val.as_string().unwrap_or(""),
- None,
- )
- .unwrap_or(false),
- )
+ PhpMixed::Bool(Preg::is_match3(
+ "/^\\s*([0-9.]+)\\s*(?:([kmg])(?:i?b)?)?\\s*$/i",
+ val.as_string().unwrap_or(""),
+ None,
+ ))
}),
Box::new(|val| val.clone()),
),
diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs
index aa4245d..5579a87 100644
--- a/crates/shirabe/src/command/create_project_command.rs
+++ b/crates/shirabe/src/command/create_project_command.rs
@@ -705,8 +705,7 @@ impl CreateProjectCommand {
),
package_version.as_deref().unwrap_or(""),
Some(&mut matched),
- )
- .unwrap_or(false);
+ );
if ok {
stability = Some(
matched
diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs
index 6c37459..56dffc1 100644
--- a/crates/shirabe/src/command/diagnose_command.rs
+++ b/crates/shirabe/src/command/diagnose_command.rs
@@ -1183,7 +1183,6 @@ impl DiagnoseCommand {
phpinfo_str.as_ref().unwrap(),
Some(&mut phpinfo_match),
)
- .unwrap_or(false)
{
let configure = phpinfo_match
.get(&CaptureKey::ByIndex(1))
diff --git a/crates/shirabe/src/command/fund_command.rs b/crates/shirabe/src/command/fund_command.rs
index 6223def..8bfae47 100644
--- a/crates/shirabe/src/command/fund_command.rs
+++ b/crates/shirabe/src/command/fund_command.rs
@@ -191,7 +191,7 @@ impl FundCommand {
.and_then(|v| v.as_string())
.unwrap_or("");
if r#type == "github" {
- if let Ok(Some(matches)) =
+ if let Some(matches) =
Preg::is_match_with_indexed_captures(r"^https://github.com/([^/]+)$", &url)
{
if let Some(sponsor) = matches.into_iter().nth(1) {
diff --git a/crates/shirabe/src/command/global_command.rs b/crates/shirabe/src/command/global_command.rs
index e978dff..0184772 100644
--- a/crates/shirabe/src/command/global_command.rs
+++ b/crates/shirabe/src/command/global_command.rs
@@ -86,7 +86,7 @@ impl GlobalCommand {
input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
) -> Result<i64> {
- let tokens = Preg::split(r"{\s+}", &Self::input_to_string(&*input.borrow())?)?;
+ let tokens = Preg::split(r"{\s+}", &Self::input_to_string(&*input.borrow())?);
let mut args: Vec<String> = vec![];
for token in &tokens {
if !token.is_empty() && !token.starts_with('-') {
@@ -150,7 +150,7 @@ impl GlobalCommand {
"",
&Self::input_to_string(&*input.borrow())?,
1,
- )?;
+ );
self.get_application()?.reset_composer();
Ok(StringInput::new(&new_input_str)?)
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index d7af222..b41492d 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -154,7 +154,6 @@ impl InitCommand {
.and_then(|v| v.as_string())
.unwrap_or(""),
)
- .unwrap_or(false)
{
return Err(InvalidArgumentException {
message: format!(
@@ -576,9 +575,7 @@ impl InitCommand {
if !Preg::is_match(
r"{^[a-z0-9]([_.-]?[a-z0-9]+)*\/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*$}D",
value.as_string().unwrap_or(""),
- )
- .unwrap_or(false)
- {
+ ) {
return Err(InvalidArgumentException {
message: format!(
"The package name {} is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+",
@@ -903,7 +900,7 @@ impl InitCommand {
value_str
};
- if !Preg::is_match(r"{^[^/][A-Za-z0-9\-_/]+/$}", &value_or_default).unwrap_or(false)
+ if !Preg::is_match(r"{^[^/][A-Za-z0-9\-_/]+/$}", &value_or_default)
{
return Err(InvalidArgumentException {
message: format!(
@@ -932,9 +929,7 @@ impl InitCommand {
r#"/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’\"()]+)(?:\s+<(?P<email>.+?)>)?$/u"#,
author,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
let email = m.get(&CaptureKey::ByName("email".to_string())).cloned();
if let Some(ref email) = email {
if !self.is_valid_email(email) {
@@ -995,7 +990,7 @@ impl InitCommand {
let namespace: Vec<String> = array_map(
|part: &String| {
- let part = Preg::replace(r"/[^a-z0-9]/i", " ", &part).unwrap_or_default();
+ let part = Preg::replace(r"/[^a-z0-9]/i", " ", &part);
let part = ucwords(&part);
str_replace(" ", "", &part)
},
@@ -1022,7 +1017,7 @@ impl InitCommand {
{
self.git_config = Some(IndexMap::new());
let mut m: IndexMap<CaptureKey, Vec<String>> = IndexMap::new();
- if Preg::is_match_all3(r"{^([^=]+)=(.*)$}m", &output, Some(&mut m)).unwrap_or(false) {
+ if Preg::is_match_all3(r"{^([^=]+)=(.*)$}m", &output, Some(&mut m)) {
let keys: Vec<String> = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
let values: Vec<String> =
m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default();
@@ -1062,7 +1057,7 @@ impl InitCommand {
let lines = file(ignore_file, FILE_IGNORE_NEW_LINES).unwrap_or_default();
for line in &lines {
- if Preg::is_match(&pattern, line).unwrap_or(false) {
+ if Preg::is_match(&pattern, line) {
return true;
}
}
@@ -1159,11 +1154,10 @@ impl InitCommand {
r"{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}",
"$1$3-$2$4",
name,
- )
- .unwrap_or_default();
+ );
let name = strtolower(&name);
- let name = Preg::replace(r"{^[_.-]+|[_.-]+$|[^a-z0-9_.-]}u", "", &name).unwrap_or_default();
- let name = Preg::replace(r"{([_.-]){2,}}u", "$1", &name).unwrap_or_default();
+ let name = Preg::replace(r"{^[_.-]+|[_.-]+$|[^a-z0-9_.-]}u", "", &name);
+ let name = Preg::replace(r"{([_.-]){2,}}u", "$1", &name);
name
}
diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs
index 917a716..c48b4d5 100644
--- a/crates/shirabe/src/command/package_discovery_trait.rs
+++ b/crates/shirabe/src/command/package_discovery_trait.rs
@@ -175,7 +175,6 @@ pub trait PackageDiscoveryTrait {
r"{^\d+(\.\d+)?$}",
requirement.get("version").map(|s| s.as_str()).unwrap_or(""),
)
- .unwrap_or(false)
{
io.write_error3(
&format!(
@@ -379,9 +378,7 @@ pub trait PackageDiscoveryTrait {
r"{^\s*(?P<name>[\S/]+)(?:\s+(?P<version>\S+))?\s*$}",
&selection,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
if let Some(v) =
m.get(&CaptureKey::ByName("version".to_string())).cloned()
{
diff --git a/crates/shirabe/src/command/reinstall_command.rs b/crates/shirabe/src/command/reinstall_command.rs
index 48f48a5..5053492 100644
--- a/crates/shirabe/src/command/reinstall_command.rs
+++ b/crates/shirabe/src/command/reinstall_command.rs
@@ -124,7 +124,7 @@ impl ReinstallCommand {
let pattern_regexp = base_package::package_name_to_regexp(pattern);
let mut matched = false;
for package in local_repo.get_canonical_packages()? {
- if Preg::is_match(&pattern_regexp, &package.get_name()).unwrap_or(false) {
+ if Preg::is_match(&pattern_regexp, &package.get_name()) {
matched = true;
package_names_to_reinstall.push(package.get_name());
packages_to_reinstall.push(package);
diff --git a/crates/shirabe/src/command/remove_command.rs b/crates/shirabe/src/command/remove_command.rs
index b81b7ca..75f1dcb 100644
--- a/crates/shirabe/src/command/remove_command.rs
+++ b/crates/shirabe/src/command/remove_command.rs
@@ -383,8 +383,7 @@ impl RemoveCommand {
let matches_in_type = Preg::grep(
&base_package::package_name_to_regexp(package),
&type_keys_refs,
- )
- .unwrap_or_default();
+ );
let alt_type_keys: Vec<String> = composer_data
.as_array()
@@ -397,8 +396,7 @@ impl RemoveCommand {
let matches_in_alt_type = Preg::grep(
&base_package::package_name_to_regexp(package),
&alt_type_keys_refs,
- )
- .unwrap_or_default();
+ );
if !type_keys.is_empty() && !matches_in_type.is_empty() {
for matched_package in &matches_in_type {
diff --git a/crates/shirabe/src/command/repository_command.rs b/crates/shirabe/src/command/repository_command.rs
index 3e0292a..417266f 100644
--- a/crates/shirabe/src/command/repository_command.rs
+++ b/crates/shirabe/src/command/repository_command.rs
@@ -133,8 +133,7 @@ impl RepositoryCommand {
}));
}
let arg1_str = arg1.as_deref().unwrap();
- let repo_config: PhpMixed = if Preg::is_match(r"^\s*\{", arg1_str).unwrap_or(false)
- {
+ let repo_config: PhpMixed = if Preg::is_match(r"^\s*\{", arg1_str) {
JsonFile::parse_json(Some(arg1_str), None)?
} else {
if arg2.is_none() {
diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs
index 9e47a02..e1cbba4 100644
--- a/crates/shirabe/src/command/require_command.rs
+++ b/crates/shirabe/src/command/require_command.rs
@@ -1099,9 +1099,7 @@ impl RequireCommand {
.get(package_name)
.map(|s| s.as_str())
.unwrap_or(""),
- )
- .unwrap_or(false)
- {
+ ) {
self.get_io().warning(
&format!(
"Version {} looks like it may be a feature branch which is unlikely to keep working in the long run and may be in an unstable state",
diff --git a/crates/shirabe/src/command/script_alias_command.rs b/crates/shirabe/src/command/script_alias_command.rs
index 29c38cf..95c80fb 100644
--- a/crates/shirabe/src/command/script_alias_command.rs
+++ b/crates/shirabe/src/command/script_alias_command.rs
@@ -130,7 +130,7 @@ impl ScriptAliasCommand {
// TODO(phase-c): InputInterface lacks to_string; use a placeholder until it is modeled.
let input_as_string = String::new();
let _ = input;
- let script_alias_input = Preg::replace4(r"{^\S+ ?}", "", &input_as_string, 1)?;
+ let script_alias_input = Preg::replace4(r"{^\S+ ?}", "", &input_as_string, 1);
let mut flags = indexmap::IndexMap::new();
flags.insert(
"script-alias-input".to_string(),
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs
index 27bda55..05b6b3e 100644
--- a/crates/shirabe/src/command/show_command.rs
+++ b/crates/shirabe/src/command/show_command.rs
@@ -801,7 +801,7 @@ impl ShowCommand {
}
let matches_filter = match &package_filter_regex {
None => true,
- Some(r) => Preg::is_match(r, &p.get_name())?,
+ Some(r) => Preg::is_match(r, &p.get_name()),
};
if matches_filter {
let matches_list = match &package_list_filter {
@@ -882,7 +882,7 @@ impl ShowCommand {
if show_latest && *show_version {
for package_or_name in type_packages.values() {
if let PackageOrName::Pkg(package) = package_or_name {
- if !Preg::is_match(&ignored_packages_regex, &package.get_pretty_name())?
+ if !Preg::is_match(&ignored_packages_regex, &package.get_pretty_name())
{
let latest = self.find_latest_package(
package.clone(),
@@ -954,7 +954,7 @@ impl ShowCommand {
package_is_up_to_date =
package_is_up_to_date || (latest_package.is_none() && show_major_only);
let package_is_ignored =
- Preg::is_match(&ignored_packages_regex, &package.get_pretty_name())?;
+ Preg::is_match(&ignored_packages_regex, &package.get_pretty_name());
if input.borrow().get_option("outdated")?.as_bool() == Some(true)
&& (package_is_up_to_date || package_is_ignored)
{
@@ -2689,7 +2689,7 @@ impl ShowCommand {
r"{^(?P<zero_major>(?:0\.)+)?(?P<first_meaningful>\d+)\.}",
&package.get_version(),
Some(&mut groups),
- )?
+ )
{
let zero_major = groups
.get(&CaptureKey::ByName("zero_major".to_string()))
@@ -2713,7 +2713,7 @@ impl ShowCommand {
}
if patch_only {
- let trimmed_version = Preg::replace(r"{(\.0)+$}D", "", &package.get_version())?;
+ let trimmed_version = Preg::replace(r"{(\.0)+$}D", "", &package.get_version());
let parts_needed = if trimmed_version.starts_with('0') {
4
} else {
diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs
index 6f604d5..26b05f5 100644
--- a/crates/shirabe/src/command/update_command.rs
+++ b/crates/shirabe/src/command/update_command.rs
@@ -136,7 +136,7 @@ impl UpdateCommand {
if packages.len() > 0 {
let allowlist_packages_with_requirements: Vec<String> =
array_filter(&packages, |pkg: &String| -> bool {
- Preg::is_match(r"{\S+[ =:]\S+}", pkg).unwrap_or(false)
+ Preg::is_match(r"{\S+[ =:]\S+}", pkg)
});
for (package, constraint) in
self.format_requirements(allowlist_packages_with_requirements.clone())?
@@ -146,7 +146,7 @@ impl UpdateCommand {
// replace the foo/bar:req by foo/bar in the allowlist
for package in &allowlist_packages_with_requirements {
- let package_name = Preg::replace(r"{^([^ =:]+)[ =:].*$}", "$1", package)?;
+ let package_name = Preg::replace(r"{^([^ =:]+)[ =:].*$}", "$1", package);
if let Some(idx) = array_search_in_vec(package, &packages) {
packages[idx] = package_name;
}
@@ -220,7 +220,7 @@ impl UpdateCommand {
let matches = Preg::is_match_with_indexed_captures(
r"{^(\d+\.\d+\.\d+)}",
&package.get_version(),
- )?;
+ );
let Some(matches) = matches else {
continue;
};
@@ -575,7 +575,7 @@ impl UpdateCommand {
let mut version_selector = self.create_version_selector(composer)?;
for package in &installed_packages {
if let Some(filter) = &filter {
- if !Preg::is_match(filter, &package.get_name()).unwrap_or(false) {
+ if !Preg::is_match(filter, &package.get_name()) {
continue;
}
}
diff --git a/crates/shirabe/src/composer.rs b/crates/shirabe/src/composer.rs
index fe700cf..7711d7f 100644
--- a/crates/shirabe/src/composer.rs
+++ b/crates/shirabe/src/composer.rs
@@ -25,7 +25,7 @@ pub fn get_version() -> String {
if VERSION == "@package_version@" {
return SOURCE_VERSION.to_string();
}
- if BRANCH_ALIAS_VERSION != "" && Preg::is_match("{^[a-f0-9]{40}$}", VERSION).unwrap_or(false) {
+ if BRANCH_ALIAS_VERSION != "" && Preg::is_match("{^[a-f0-9]{40}$}", VERSION) {
return format!("{}+{}", BRANCH_ALIAS_VERSION, VERSION);
}
VERSION.to_string()
diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs
index 5333173..7e63dff 100644
--- a/crates/shirabe/src/config.rs
+++ b/crates/shirabe/src/config.rs
@@ -506,7 +506,6 @@ impl Config {
r"{^https?://(?:[a-z0-9-.]+\.)?packagist.org(/|$)}",
&repo_url,
)
- .unwrap_or(false)
{
self.disable_repo_by_name("packagist.org");
}
@@ -688,9 +687,7 @@ impl Config {
r"/^\s*([0-9.]+)\s*(?:([kmg])(?:i?b)?)?\s*$/i",
&raw,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
return Err(RuntimeException {
message: format!("Could not parse the value of '{}': {}", key, raw),
code: 0,
@@ -1093,7 +1090,7 @@ impl Config {
}
},
&value_str,
- )?;
+ );
if let Some(e) = error {
return Err(e);
}
@@ -1104,7 +1101,7 @@ impl Config {
///
/// Since the dirs might not exist yet we can not call realpath or it will fail.
fn realpath(&self, path: &str) -> String {
- if Preg::is_match(r"{^(?:/|[a-z]:|[a-z0-9.]+://|\\\\\\\\)}i", path).unwrap_or(false) {
+ if Preg::is_match(r"{^(?:/|[a-z]:|[a-z0-9.]+://|\\\\\\\\)}i", path) {
return path.to_string();
}
@@ -1150,9 +1147,7 @@ impl Config {
repo_options: &IndexMap<String, PhpMixed>,
) -> 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, FILTER_VALIDATE_URL)
- && !Preg::is_match(r"{^https?://}", url).unwrap_or(false)
- {
+ if !filter_var(url, FILTER_VALIDATE_URL) && !Preg::is_match(r"{^https?://}", url) {
return Ok(());
}
diff --git a/crates/shirabe/src/console/html_output_formatter.rs b/crates/shirabe/src/console/html_output_formatter.rs
index b516c83..4ee87a1 100644
--- a/crates/shirabe/src/console/html_output_formatter.rs
+++ b/crates/shirabe/src/console/html_output_formatter.rs
@@ -66,7 +66,7 @@ impl HtmlOutputFormatter {
&pattern,
|matches| self.format_html(matches),
&formatted,
- )?))
+ )))
}
fn format_html(&self, matches: &IndexMap<CaptureKey, String>) -> String {
diff --git a/crates/shirabe/src/dependency_resolver/lock_transaction.rs b/crates/shirabe/src/dependency_resolver/lock_transaction.rs
index 61f5b39..77fa65f 100644
--- a/crates/shirabe/src/dependency_resolver/lock_transaction.rs
+++ b/crates/shirabe/src/dependency_resolver/lock_transaction.rs
@@ -156,14 +156,16 @@ impl LockTransaction {
if package.get_dist_url().is_some()
&& present_package.get_dist_reference().is_some()
- && Preg::is_match(r"{^https?://(?:(?:www\.)?bitbucket\.org|(api\.)?github\.com|(?:www\.)?gitlab\.com)/}i", &package.get_dist_url().unwrap()).unwrap_or(false)
+ && Preg::is_match(
+ r"{^https?://(?:(?:www\.)?bitbucket\.org|(api\.)?github\.com|(?:www\.)?gitlab\.com)/}i",
+ &package.get_dist_url().unwrap(),
+ )
{
let new_dist_url = Preg::replace(
r"{(?<=/|sha=)[a-f0-9]{40}(?=/|$)}i",
&present_package.get_dist_reference().unwrap(),
&package.get_dist_url().unwrap(),
- )
- .unwrap_or_else(|_| package.get_dist_url().unwrap());
+ );
present_package.set_dist_url(Some(new_dist_url));
}
present_package.set_dist_mirrors(package.get_dist_mirrors());
diff --git a/crates/shirabe/src/dependency_resolver/pool_builder.rs b/crates/shirabe/src/dependency_resolver/pool_builder.rs
index a517488..9589276 100644
--- a/crates/shirabe/src/dependency_resolver/pool_builder.rs
+++ b/crates/shirabe/src/dependency_resolver/pool_builder.rs
@@ -802,7 +802,7 @@ impl PoolBuilder {
fn is_update_allowed(&self, package: PackageInterfaceHandle) -> bool {
for pattern in &self.update_allow_list {
let pattern_regexp = base_package::package_name_to_regexp(pattern);
- if Preg::is_match3(&pattern_regexp, &package.get_name(), None).unwrap_or(false) {
+ if Preg::is_match3(&pattern_regexp, &package.get_name(), None) {
return true;
}
}
@@ -830,13 +830,13 @@ impl PoolBuilder {
.borrow_mut()
.get_canonical_packages()?
{
- if Preg::is_match3(&pattern_regexp, &package.get_name(), None).unwrap_or(false) {
+ if Preg::is_match3(&pattern_regexp, &package.get_name(), None) {
continue 'outer;
}
}
// update pattern matches a root require? => all good, probably a new package
for (package_name, _constraint) in request.get_requires() {
- if Preg::is_match3(&pattern_regexp, package_name, None).unwrap_or(false) {
+ if Preg::is_match3(&pattern_regexp, package_name, None) {
if PlatformRepository::is_platform_package(package_name) {
matched_platform_package = true;
continue;
diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs
index b8fa03f..93d82be 100644
--- a/crates/shirabe/src/dependency_resolver/problem.rs
+++ b/crates/shirabe/src/dependency_resolver/problem.rs
@@ -236,14 +236,12 @@ impl Problem {
&message,
Some(&mut m),
)
- .unwrap_or(false)
} else {
false
};
if matched {
message = str_replace("%", "%%", &message);
- let template =
- Preg::replace(r"{^\S+ \S+ }", "%s%s ", &message).unwrap_or(message.clone());
+ let template = Preg::replace(r"{^\S+ \S+ }", "%s%s ", &message);
messages.push(template.clone());
let pkg_key = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
let m2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default();
@@ -311,8 +309,7 @@ impl Problem {
if versions_list.len() > 1 {
// remove the s from requires/conflicts to correct grammar
let message_var =
- Preg::replace(r"{^(%s%s (?:require|conflict))s}", "$1", message)
- .unwrap_or(message.clone());
+ Preg::replace(r"{^(%s%s (?:require|conflict))s}", "$1", message);
result.push(sprintf(
&message_var,
&[
@@ -568,11 +565,10 @@ impl Problem {
if let Some(c) = constraint {
if c.is_constraint()
&& c.get_operator() == SimpleConstraint::STR_OP_EQ
- && Preg::is_match3(r"{^dev-.*#.*}", &c.get_pretty_string(), None).unwrap_or(false)
+ && Preg::is_match3(r"{^dev-.*#.*}", &c.get_pretty_string(), None)
{
let new_constraint =
- Preg::replace(r"{ +as +([^,\s|]+)$}", "", &c.get_pretty_string())
- .unwrap_or_else(|_| c.get_pretty_string());
+ Preg::replace(r"{ +as +([^,\s|]+)$}", "", &c.get_pretty_string());
let packages = repository_set.find_packages(
package_name,
Some(
@@ -983,9 +979,8 @@ impl Problem {
));
}
- if !Preg::is_match3(r"{^[A-Za-z0-9_./-]+$}", package_name, None).unwrap_or(false) {
- let illegal_chars =
- Preg::replace(r"{[A-Za-z0-9_./-]+}", "", package_name).unwrap_or_default();
+ if !Preg::is_match3(r"{^[A-Za-z0-9_./-]+$}", package_name, None) {
+ let illegal_chars = Preg::replace(r"{[A-Za-z0-9_./-]+}", "", package_name);
return Ok((
format!("- Root composer.json requires {}, it ", package_name),
@@ -1196,8 +1191,7 @@ impl Problem {
.or_insert_with(Vec::new)
.push(pretty.clone());
} else {
- let key = Preg::replace(r"{^(\d+)\..*}", "$1", version)
- .unwrap_or_else(|_| version.clone());
+ let key = Preg::replace(r"{^(\d+)\..*}", "$1", version);
by_major
.entry(key)
.or_insert_with(Vec::new)
@@ -1377,9 +1371,7 @@ impl Problem {
&& c.get_operator() == SimpleConstraint::STR_OP_EQ
&& !str_starts_with(&c.get_version(), "dev-")
{
- if !Preg::is_match3(r"{^\d+(?:\.\d+)*$}", &c.get_pretty_string(), None)
- .unwrap_or(false)
- {
+ if !Preg::is_match3(r"{^\d+(?:\.\d+)*$}", &c.get_pretty_string(), None) {
return format!(" {} (exact version match)", c.get_pretty_string());
}
diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs
index 209c6ee..3d4fe9b 100644
--- a/crates/shirabe/src/downloader/download_manager.rs
+++ b/crates/shirabe/src/downloader/download_manager.rs
@@ -459,7 +459,7 @@ impl DownloadManager {
"{{^{}$}}i",
str_replace("\\*", ".*", &preg_quote(pattern, None)),
);
- if Preg::is_match(&pattern_regex, &package.get_name()).unwrap_or(false) {
+ if Preg::is_match(&pattern_regex, &package.get_name()) {
if "dist" == preference || (!package.is_dev() && "auto" == preference) {
return "dist".to_string();
}
diff --git a/crates/shirabe/src/downloader/fossil_downloader.rs b/crates/shirabe/src/downloader/fossil_downloader.rs
index d6b8095..2c4e7de 100644
--- a/crates/shirabe/src/downloader/fossil_downloader.rs
+++ b/crates/shirabe/src/downloader/fossil_downloader.rs
@@ -238,11 +238,11 @@ impl VcsDownloader for FossilDownloader {
let lines: Vec<String> = if trimmed.is_empty() {
vec![]
} else {
- Preg::split(r"{\r?\n}", &trimmed)?
+ Preg::split(r"{\r?\n}", &trimmed)
};
for line in lines {
- if Preg::is_match(&match_pattern, &line)? {
+ if Preg::is_match(&match_pattern, &line) {
break;
}
log.push_str(&line);
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index fd2246a..c38e491 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -99,9 +99,7 @@ impl GitDownloader {
let mut refs = trim(&output, None);
let mut head_match: IndexMap<CaptureKey, String> = IndexMap::new();
- if !Preg::is_match3(r"{^([a-f0-9]+) HEAD$}mi", &refs, Some(&mut head_match))
- .unwrap_or(false)
- {
+ if !Preg::is_match3(r"{^([a-f0-9]+) HEAD$}mi", &refs, Some(&mut head_match)) {
// could not match the HEAD for some reason
return Ok(None);
}
@@ -115,9 +113,7 @@ impl GitDownloader {
&format!("{{^{} refs/heads/(.+)$}}mi", preg_quote(&head_ref, None)),
&refs,
Some(&mut branches_match),
- )
- .unwrap_or(false)
- {
+ ) {
// not on a branch, we are either on a not-modified tag or some sort of detached head, so skip this
return Ok(None);
}
@@ -145,9 +141,7 @@ impl GitDownloader {
),
&refs,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
let matches: Vec<String> =
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
for match_ in matches {
@@ -284,7 +278,7 @@ impl GitDownloader {
// If the non-existent branch is actually the name of a file, the file
// is checked out.
- let mut branch = Preg::replace(r"{(?:^dev-|(?:\.x)?-dev$)}i", "", &pretty_version)?;
+ let mut branch = Preg::replace(r"{(?:^dev-|(?:\.x)?-dev$)}i", "", &pretty_version);
// Closure equivalent: $execute = function(array $command) use (&$output, $path) { ... };
// Inlined below at each call site.
@@ -304,13 +298,12 @@ impl GitDownloader {
// check whether non-commitish are branches or tags, and fetch branches with the remote name
let git_ref = reference.to_string();
- if !Preg::is_match(r"{^[a-f0-9]{40}$}", reference).unwrap_or(false)
+ if !Preg::is_match(r"{^[a-f0-9]{40}$}", reference)
&& branches.is_some()
&& Preg::is_match(
&format!("{{^\\s+composer/{}$}}m", preg_quote(reference, None)),
branches.as_deref().unwrap_or(""),
)
- .unwrap_or(false)
{
let mut command1: Vec<String> = vec!["git".to_string(), "checkout".to_string()];
command1.extend(force.clone());
@@ -350,19 +343,17 @@ impl GitDownloader {
}
// try to checkout branch by name and then reset it so it's on the proper branch name
- if Preg::is_match(r"{^[a-f0-9]{40}$}", reference).unwrap_or(false) {
+ if Preg::is_match(r"{^[a-f0-9]{40}$}", reference) {
// add 'v' in front of the branch if it was stripped when generating the pretty name
if branches.is_some()
&& !Preg::is_match(
&format!("{{^\\s+composer/{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
)
- .unwrap_or(false)
&& Preg::is_match(
&format!("{{^\\s+composer/v{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
)
- .unwrap_or(false)
{
branch = format!("v{}", branch);
}
@@ -516,9 +507,7 @@ impl GitDownloader {
),
url,
Some(&mut match_),
- )
- .unwrap_or(false)
- {
+ ) {
let protocols = self.inner.config.borrow_mut().get("github-protocols");
let m1 = match_
.get(&CaptureKey::ByIndex(1))
@@ -672,9 +661,7 @@ impl GitDownloader {
}
pub(crate) fn get_short_hash(&self, reference: &str) -> String {
- if !self.inner.io.is_verbose()
- && Preg::is_match(r"{^[0-9a-f]{40}$}", reference).unwrap_or(false)
- {
+ if !self.inner.io.is_verbose() && Preg::is_match(r"{^[0-9a-f]{40}$}", reference) {
return substr(reference, 0, Some(10));
}
@@ -804,7 +791,7 @@ impl VcsDownloader for GitDownloader {
.get("cache-vcs-dir")
.as_string()
.unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string()))?,
+ Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
);
let git_version = GitUtil::get_version(&self.inner.process);
@@ -872,7 +859,7 @@ impl VcsDownloader for GitDownloader {
.get("cache-vcs-dir")
.as_string()
.unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string()))?,
+ Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
);
let r#ref = package.get_source_reference().unwrap_or_default();
@@ -1036,7 +1023,7 @@ impl VcsDownloader for GitDownloader {
.get("cache-vcs-dir")
.as_string()
.unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string()))?,
+ Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
);
let r#ref = target.get_source_reference().unwrap_or_default();
@@ -1142,15 +1129,11 @@ impl VcsDownloader for GitDownloader {
r"{^origin\s+(?P<url>\S+)}m",
&output,
Some(&mut origin_match),
- )
- .unwrap_or(false)
- && Preg::is_match3(
- r"{^composer\s+(?P<url>\S+)}m",
- &output,
- Some(&mut composer_match),
- )
- .unwrap_or(false)
- {
+ ) && Preg::is_match3(
+ r"{^composer\s+(?P<url>\S+)}m",
+ &output,
+ Some(&mut composer_match),
+ ) {
let origin_url = origin_match
.get(&CaptureKey::ByName("url".to_string()))
.cloned()
@@ -1229,7 +1212,7 @@ impl VcsDownloader for GitDownloader {
let changes: Vec<String> = array_map(
|elem: &String| format!(" {}", elem),
- &Preg::split(r"{\s*\r?\n\s*}", &changes)?,
+ &Preg::split(r"{\s*\r?\n\s*}", &changes),
);
self.inner.io.write_error3(
&format!(
diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs
index e66d3ae..03fd292 100644
--- a/crates/shirabe/src/downloader/svn_downloader.rs
+++ b/crates/shirabe/src/downloader/svn_downloader.rs
@@ -281,7 +281,6 @@ impl VcsDownloader for SvnDownloader {
let changes_str = changes.unwrap();
let changes: Vec<String> = Preg::split(r"{\s*\r?\n\s*}", &changes_str)
- .unwrap_or_default()
.into_iter()
.map(|elem| format!(" {}", elem))
.collect();
@@ -367,8 +366,8 @@ impl VcsDownloader for SvnDownloader {
to_reference: &str,
path: &str,
) -> anyhow::Result<String> {
- if Preg::is_match(r"{@(\d+)$}", from_reference).unwrap_or(false)
- && Preg::is_match(r"{@(\d+)$}", to_reference).unwrap_or(false)
+ if Preg::is_match(r"{@(\d+)$}", from_reference)
+ && Preg::is_match(r"{@(\d+)$}", to_reference)
{
// retrieve the svn base url from the checkout folder
let command = vec![
@@ -399,25 +398,22 @@ impl VcsDownloader for SvnDownloader {
let url_pattern = "#<url>(.*)</url>#";
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- let base_url =
- if Preg::match3(url_pattern, &output, Some(&mut matches)).unwrap_or(false) {
- matches
- .get(&CaptureKey::ByIndex(1))
- .cloned()
- .unwrap_or_default()
- } else {
- return Err(RuntimeException {
- message: format!("Unable to determine svn url for path {}", path),
- code: 0,
- }
- .into());
- };
+ let base_url = if Preg::match3(url_pattern, &output, Some(&mut matches)) {
+ matches
+ .get(&CaptureKey::ByIndex(1))
+ .cloned()
+ .unwrap_or_default()
+ } else {
+ return Err(RuntimeException {
+ message: format!("Unable to determine svn url for path {}", path),
+ code: 0,
+ }
+ .into());
+ };
// strip paths from references and only keep the actual revision
- let from_revision =
- Preg::replace(r"{.*@(\d+)$}", "$1", &from_reference).unwrap_or_default();
- let to_revision =
- Preg::replace(r"{.*@(\d+)$}", "$1", &to_reference).unwrap_or_default();
+ let from_revision = Preg::replace(r"{.*@(\d+)$}", "$1", &from_reference);
+ let to_revision = Preg::replace(r"{.*@(\d+)$}", "$1", &to_reference);
let command = vec![
"svn".to_string(),
@@ -474,13 +470,11 @@ impl ChangeReportInterface for SvnDownloader {
Some(path.to_string()),
);
- Ok(
- if Preg::is_match("{^ *[^X ] +}m", &output).unwrap_or(false) {
- Some(output)
- } else {
- None
- },
- )
+ Ok(if Preg::is_match("{^ *[^X ] +}m", &output) {
+ Some(output)
+ } else {
+ None
+ })
}
}
diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs
index 0613c15..d4ec2ab 100644
--- a/crates/shirabe/src/downloader/zip_downloader.rs
+++ b/crates/shirabe/src/downloader/zip_downloader.rs
@@ -116,9 +116,7 @@ impl ZipDownloader {
== 0
{
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"^\s*7-Zip(?:\s\[64\])?\s([0-9.]+)", &output, Some(&mut m))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r"^\s*7-Zip(?:\s\[64\])?\s([0-9.]+)", &output, Some(&mut m)) {
let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
if version_compare(&m1, "21.01", "<") {
self.inner.io.write_error(&format!(
diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
index 8d3ac4b..3c23967 100644
--- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
+++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
@@ -291,8 +291,7 @@ impl EventDispatcher {
let mut callable = callable;
if let Callable::String(ref s) = callable {
if str_contains(s, "@no_additional_args") {
- let replaced = Preg::replace("{ ?@no_additional_args}", "", s)
- .unwrap_or_else(|_| s.clone());
+ let replaced = Preg::replace("{ ?@no_additional_args}", "", s);
callable = Callable::String(replaced);
additional_args = Vec::new();
}
@@ -647,17 +646,14 @@ impl EventDispatcher {
if Preg::is_match(
&format!("{{\\b{}$}}", preg_quote(&callable_str, None)),
local_exec,
- )
- .unwrap_or(false)
- {
+ ) {
let caller =
BinaryInstaller::determine_binary_caller(local_exec);
exec = Preg::replace(
&format!("{{^{}}}", preg_quote(&callable_str, None)),
&format!("{} {}", caller, local_exec),
&exec,
- )
- .unwrap_or(exec);
+ );
break;
}
}
@@ -683,14 +679,12 @@ impl EventDispatcher {
"{^\\S+}",
|m| str_replace("/", "\\", &m[0]),
&path_and_args,
- )
- .unwrap_or(path_and_args);
+ );
}
// match somename (not in quote, and not a qualified path) and if it is not a valid path from CWD then try to find it
// in $PATH. This allows support for `@php foo` where foo is a binary name found in PATH but not an actual relative path
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3("{^[^\\'\"\\s/\\\\]+}", &path_and_args, Some(&mut m))
- .unwrap_or(false)
{
let m0 =
m.get(&CaptureKey::ByIndex(0)).cloned().unwrap_or_default();
@@ -703,8 +697,7 @@ impl EventDispatcher {
"{\\.(exe|bat|cmd|com)$}i",
"",
&path_to_exec,
- )
- .unwrap_or(path_to_exec.clone());
+ );
// prefer non-extension file if it exists when executing with PHP
if file_exists(&exec_without_ext) {
path_to_exec = exec_without_ext;
@@ -731,8 +724,7 @@ impl EventDispatcher {
"{^\\S+}",
|m| str_replace("/", "\\", &m[0]),
&exec,
- )
- .unwrap_or(exec);
+ );
}
}
@@ -1088,9 +1080,7 @@ impl EventDispatcher {
PATH_SEPARATOR
),
&path_value,
- )
- .unwrap_or(false)
- {
+ ) {
Platform::put_env(
path_env,
&format!("{}{}{}", bin_dir, PATH_SEPARATOR, path_value),
diff --git a/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs b/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs
index d69773c..efa8634 100644
--- a/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs
+++ b/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs
@@ -48,11 +48,11 @@ impl IgnoreListPlatformRequirementFilter {
return Ok(constraint);
}
- if !allow_upper_bound_override || !Preg::is_match(&self.ignore_upper_bound_regex, req)? {
+ if !allow_upper_bound_override || !Preg::is_match(&self.ignore_upper_bound_regex, req) {
return Ok(constraint);
}
- if Preg::is_match(&self.ignore_regex, req)? {
+ if Preg::is_match(&self.ignore_regex, req) {
return Ok(MatchAllConstraint::new(None).into());
}
@@ -86,14 +86,14 @@ impl PlatformRequirementFilterInterface for IgnoreListPlatformRequirementFilter
if !PlatformRepository::is_platform_package(req) {
return false;
}
- Preg::is_match(&self.ignore_regex, req).unwrap_or(false)
+ Preg::is_match(&self.ignore_regex, req)
}
fn is_upper_bound_ignored(&self, req: &str) -> bool {
if !PlatformRepository::is_platform_package(req) {
return false;
}
- self.is_ignored(req) || Preg::is_match(&self.ignore_upper_bound_regex, req).unwrap_or(false)
+ self.is_ignored(req) || Preg::is_match(&self.ignore_upper_bound_regex, req)
}
fn as_any(&self) -> &dyn std::any::Any {
diff --git a/crates/shirabe/src/installer/binary_installer.rs b/crates/shirabe/src/installer/binary_installer.rs
index 778a8a0..bc7d694 100644
--- a/crates/shirabe/src/installer/binary_installer.rs
+++ b/crates/shirabe/src/installer/binary_installer.rs
@@ -177,9 +177,7 @@ impl BinaryInstaller {
r"{^#!/(?:usr/bin/env )?(?:[^/]+/)*(.+)$}m",
&line,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
return trim(
m.get(&CaptureKey::ByIndex(1))
.map(|s| s.as_str())
@@ -299,8 +297,6 @@ impl BinaryInstaller {
// which allows calling the proxy with a custom php process
if let Some(m) =
Preg::is_match_with_indexed_captures(r"{^(#!.*\r?\n)?[\r\n\t ]*<\?php}", &bin_contents)
- .ok()
- .flatten()
{
// carry over the existing shebang if present, otherwise add our own
let proxy_code = if m.get(1).is_none() {
diff --git a/crates/shirabe/src/installer/library_installer.rs b/crates/shirabe/src/installer/library_installer.rs
index da5533c..9fb3e43 100644
--- a/crates/shirabe/src/installer/library_installer.rs
+++ b/crates/shirabe/src/installer/library_installer.rs
@@ -119,7 +119,7 @@ impl LibraryInstaller {
"",
&install_path,
);
- return replaced.unwrap_or(install_path);
+ return replaced;
}
}
diff --git a/crates/shirabe/src/installer/suggested_packages_reporter.rs b/crates/shirabe/src/installer/suggested_packages_reporter.rs
index 875fdc6..2a2ed9f 100644
--- a/crates/shirabe/src/installer/suggested_packages_reporter.rs
+++ b/crates/shirabe/src/installer/suggested_packages_reporter.rs
@@ -206,6 +206,5 @@ impl SuggestedPackagesReporter {
fn remove_control_characters(&self, string: &str) -> String {
Preg::replace("/[[:cntrl:]]/", "", &string.replace('\n', " "))
- .unwrap_or_else(|_| string.replace('\n', " "))
}
}
diff --git a/crates/shirabe/src/io/base_io.rs b/crates/shirabe/src/io/base_io.rs
index 1d12470..b5d4717 100644
--- a/crates/shirabe/src/io/base_io.rs
+++ b/crates/shirabe/src/io/base_io.rs
@@ -133,7 +133,7 @@ pub trait BaseIO: IOInterface {
config.merge(&config_outer, "implicit-due-to-auth");
}
- if !Preg::is_match(r"^[.A-Za-z0-9_]+$", &token_str).unwrap_or(false) {
+ if !Preg::is_match(r"^[.A-Za-z0-9_]+$", &token_str) {
return Err(anyhow::anyhow!(UnexpectedValueException {
message: format!(
"Your github oauth token for {} contains invalid characters: \"{}\"",
diff --git a/crates/shirabe/src/io/buffer_io.rs b/crates/shirabe/src/io/buffer_io.rs
index 8c10dee..91fdac1 100644
--- a/crates/shirabe/src/io/buffer_io.rs
+++ b/crates/shirabe/src/io/buffer_io.rs
@@ -107,9 +107,7 @@ impl BufferIO {
&output,
);
- // TODO(phase-c): Preg::replace_callback returns Result<String>; PHP getOutput returns the
- // string directly, so this is gated on the get_stream PhpResource model above.
- output.unwrap_or_default()
+ output
}
pub fn set_user_inputs(&mut self, inputs: Vec<String>) -> Result<()> {
diff --git a/crates/shirabe/src/io/console_io.rs b/crates/shirabe/src/io/console_io.rs
index b2e0bb5..3afd300 100644
--- a/crates/shirabe/src/io/console_io.rs
+++ b/crates/shirabe/src/io/console_io.rs
@@ -296,7 +296,7 @@ impl ConsoleIO {
};
if is_string(&messages) {
let message = Self::ensure_valid_utf8(messages.as_string().unwrap_or(""));
- return PhpMixed::String(Preg::replace(&pattern, "", &message).unwrap_or_default());
+ return PhpMixed::String(Preg::replace(&pattern, "", &message));
}
// PHP: $sanitized = []; foreach ($messages as $key => $message) { ... }
@@ -307,7 +307,7 @@ impl ConsoleIO {
let s = Self::ensure_valid_utf8(message.as_string().unwrap_or(""));
sanitized.insert(
key.to_string(),
- PhpMixed::String(Preg::replace(&pattern, "", &s).unwrap_or_default()),
+ PhpMixed::String(Preg::replace(&pattern, "", &s)),
);
}
}
@@ -316,7 +316,7 @@ impl ConsoleIO {
let s = Self::ensure_valid_utf8(message.as_string().unwrap_or(""));
sanitized.insert(
key.clone(),
- PhpMixed::String(Preg::replace(&pattern, "", &s).unwrap_or_default()),
+ PhpMixed::String(Preg::replace(&pattern, "", &s)),
);
}
}
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index f06a0b9..f04a7a4 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -109,7 +109,7 @@ impl JsonFile {
http_downloader: Option<std::rc::Rc<std::cell::RefCell<HttpDownloader>>>,
io: Option<std::rc::Rc<std::cell::RefCell<dyn IOInterface>>>,
) -> Result<Self> {
- if http_downloader.is_none() && Preg::is_match(r"{^https?://}i", &path).unwrap_or(false) {
+ 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(),
code: 0,
@@ -456,8 +456,7 @@ impl JsonFile {
str_repeat(&indent_owned, (strlen(whole) / 4) as usize)
},
&json,
- )
- .unwrap_or(json);
+ );
}
json
@@ -512,8 +511,7 @@ impl JsonFile {
json,
-1,
&mut count,
- )
- .unwrap_or_else(|_| json.to_string());
+ );
if count == 1 {
data = json_decode(&replaced, true)?;
if !matches!(data, PhpMixed::Null) {
@@ -575,8 +573,7 @@ impl JsonFile {
pub fn detect_indenting(json: Option<&str>) -> String {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r##"#^([ \t]+)"#m"##, json.unwrap_or(""), Some(&mut m)).unwrap_or(false)
- {
+ if Preg::is_match3(r##"#^([ \t]+)"#m"##, json.unwrap_or(""), Some(&mut m)) {
return m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
}
diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs
index 63b9cae..a3c0a16 100644
--- a/crates/shirabe/src/json/json_manipulator.rs
+++ b/crates/shirabe/src/json/json_manipulator.rs
@@ -4,11 +4,10 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
- ArrayObject, InvalidArgumentException, LogicException, PREG_BACKTRACK_LIMIT_ERROR, PhpMixed,
- RuntimeException, StdClass, addcslashes, array_key_exists, array_keys, array_reverse, count,
- empty, explode, implode, in_array, is_array, is_int, is_numeric, json_decode, max_i64,
- preg_quote, rtrim, str_contains, str_repeat, str_replace, strlen, strnatcmp, strpos, substr,
- trim, uksort,
+ ArrayObject, InvalidArgumentException, LogicException, PhpMixed, StdClass, addcslashes,
+ array_key_exists, array_keys, array_reverse, count, empty, explode, implode, in_array,
+ is_array, is_int, is_numeric, json_decode, max_i64, preg_quote, rtrim, str_contains,
+ str_repeat, str_replace, strlen, strnatcmp, strpos, substr, trim, uksort,
};
use crate::json::JsonFile;
@@ -37,7 +36,7 @@ impl JsonManipulator {
if contents == "" {
contents = "{}".to_string();
}
- if !Preg::is_match3("#^\\{(.*)\\}$#s", &contents, None).unwrap_or(false) {
+ if !Preg::is_match3("#^\\{(.*)\\}$#s", &contents, None) {
return Err(InvalidArgumentException {
message: "The json file must be an object ({})".to_string(),
code: 0,
@@ -91,7 +90,7 @@ impl JsonManipulator {
preg_quote(&JsonFile::encode(r#type), None),
);
let mut matches: IndexMap<String, String> = IndexMap::new();
- if !Preg::is_match_named(&regex, &self.contents, &mut matches).unwrap_or(false) {
+ if !Preg::is_match_named(&regex, &self.contents, &mut matches) {
return Ok(false);
}
let start = matches.get("start").cloned().unwrap_or_default();
@@ -108,7 +107,7 @@ impl JsonManipulator {
package_regex
);
let mut package_matches: IndexMap<String, String> = IndexMap::new();
- if Preg::is_match_named(&regex, &links, &mut package_matches).unwrap_or(false) {
+ if Preg::is_match_named(&regex, &links, &mut package_matches) {
// update existing link
let existing_package = package_matches.get("package").cloned().unwrap_or_default();
let package_regex = str_replace("/", "\\\\?/", &preg_quote(&existing_package, None));
@@ -131,16 +130,14 @@ impl JsonManipulator {
)
},
&links,
- )?;
+ );
} else {
let mut groups: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
"#^\\s*\\{\\s*\\S+.*?(\\s*\\}\\s*)$#s",
&links,
Some(&mut groups),
- )
- .unwrap_or(false)
- {
+ ) {
let groups_1 = groups
.get(&CaptureKey::ByIndex(1))
.cloned()
@@ -162,7 +159,7 @@ impl JsonManipulator {
"\\$",
),
&links,
- )?;
+ );
} else {
// links empty
links = format!(
@@ -197,7 +194,7 @@ impl JsonManipulator {
let replacements = ["0-$0", "1-$0", "2-$0", "3-$0", "4-$0"];
let mut result = requirement.to_string();
for (p, r) in patterns.iter().zip(replacements.iter()) {
- result = Preg::replace(p, r, &result).unwrap_or(result);
+ result = Preg::replace(p, r, &result);
}
result
} else {
@@ -369,11 +366,9 @@ impl JsonManipulator {
let mut matches: IndexMap<String, String> = IndexMap::new();
let list_match = list_regex.as_ref().map_or(false, |r| {
- Preg::is_match_named(r, &self.contents, &mut matches).unwrap_or(false)
+ Preg::is_match_named(r, &self.contents, &mut matches)
});
- if list_match
- || Preg::is_match_named(&object_regex, &self.contents, &mut matches).unwrap_or(false)
- {
+ if list_match || Preg::is_match_named(&object_regex, &self.contents, &mut matches) {
// invalid match due to un-regexable content, abort
let raw_repo = matches.get("repository").cloned().unwrap_or_default();
if json_decode(&raw_repo, false)?.as_bool() == Some(false) {
@@ -406,7 +401,7 @@ impl JsonManipulator {
)
},
&raw_repo,
- )?,
+ ),
matches.get("end").cloned().unwrap_or_default()
);
@@ -678,18 +673,7 @@ impl JsonManipulator {
);
let mut match_map: IndexMap<String, String> = IndexMap::new();
- let match_result = match Preg::is_match_named(&node_regex, &self.contents, &mut match_map) {
- Ok(b) => Ok(b),
- Err(e) => {
- if let Some(re) = e.downcast_ref::<RuntimeException>() {
- if re.code == PREG_BACKTRACK_LIMIT_ERROR {
- return Ok(false);
- }
- }
- Err(e)
- }
- }?;
- if !match_result {
+ if !Preg::is_match_named(&node_regex, &self.contents, &mut match_map) {
return Ok(false);
}
@@ -708,7 +692,7 @@ impl JsonManipulator {
preg_quote(&name_owned, None)
);
let mut child_match_map: IndexMap<String, String> = IndexMap::new();
- if Preg::is_match_named(&child_regex, &children, &mut child_match_map).unwrap_or(false) {
+ if Preg::is_match_named(&child_regex, &children, &mut child_match_map) {
let value_capture = value.clone();
let sub_name_capture = sub_name.clone();
let formatter = ManipulatorFormatter {
@@ -745,16 +729,14 @@ impl JsonManipulator {
)
},
&children,
- )?;
+ );
} else {
let mut leading_match: IndexMap<String, String> = IndexMap::new();
if Preg::is_match_named(
"#^\\{(?P<leadingspace>\\s*?)(?P<content>\\S+.*?)?(?P<trailingspace>\\s*)\\}$#s",
&children,
&mut leading_match,
- )
- .unwrap_or(false)
- {
+ ) {
let mut whitespace = leading_match
.get("trailingspace")
.cloned()
@@ -789,7 +771,7 @@ impl JsonManipulator {
"\\$",
),
&children,
- )?;
+ );
} else {
whitespace = leading_space.clone();
children = Preg::replace(
@@ -807,7 +789,7 @@ impl JsonManipulator {
"\\$",
),
&children,
- )?;
+ );
}
} else {
let mut value_local = value.clone();
@@ -853,7 +835,7 @@ impl JsonManipulator {
)
},
&self.contents,
- )?;
+ );
Ok(true)
}
@@ -874,18 +856,7 @@ impl JsonManipulator {
preg_quote(&JsonFile::encode(main_node), None)
);
let mut match_map: IndexMap<String, String> = IndexMap::new();
- let match_result = match Preg::is_match_named(&node_regex, &self.contents, &mut match_map) {
- Ok(b) => Ok(b),
- Err(e) => {
- if let Some(re) = e.downcast_ref::<RuntimeException>() {
- if re.code == PREG_BACKTRACK_LIMIT_ERROR {
- return Ok(false);
- }
- }
- Err(e)
- }
- }?;
- if !match_result {
+ if !Preg::is_match_named(&node_regex, &self.contents, &mut match_map) {
return Ok(false);
}
@@ -936,9 +907,7 @@ impl JsonManipulator {
// try and find a match for the subkey
let key_regex = str_replace("/", "\\\\?/", &preg_quote(&name_owned, None));
let mut children_clean: Option<String> = None;
- if Preg::is_match3(&format!("{{\"{}\"\\s*:}}i", key_regex), &children, None)
- .unwrap_or(false)
- {
+ if Preg::is_match3(&format!("{{\"{}\"\\s*:}}i", key_regex), &children, None) {
// find best match for the value of "name"
let mut all_matches: IndexMap<CaptureKey, Vec<String>> = IndexMap::new();
if Preg::is_match_all3(
@@ -949,9 +918,7 @@ impl JsonManipulator {
),
&children,
Some(&mut all_matches),
- )
- .unwrap_or(false)
- {
+ ) {
let mut best_match: String = String::new();
let first_group = all_matches
.get(&CaptureKey::ByIndex(0))
@@ -969,7 +936,7 @@ impl JsonManipulator {
&children,
-1,
&mut count_out,
- )?;
+ );
if 1 != count_out {
let cleaned2 = Preg::replace5(
&format!("{{{}\\s*,?\\s*}}i", preg_quote(&best_match, None)),
@@ -977,7 +944,7 @@ impl JsonManipulator {
&cleaned,
-1,
&mut count_out,
- )?;
+ );
if 1 != count_out {
return Ok(false);
}
@@ -1001,9 +968,7 @@ impl JsonManipulator {
"#^\\{\\s*?(?P<content>\\S+.*?)?(?P<trailingspace>\\s*)\\}$#s",
&children_clean,
&mut empty_match,
- )
- .unwrap_or(false)
- {
+ ) {
if empty_match.get("content").is_none() {
let newline = self.newline.clone();
let indent = self.indent.clone();
@@ -1026,7 +991,7 @@ impl JsonManipulator {
)
},
&self.contents,
- )?;
+ );
// we have a subname, so we restore the rest of $name
if let Some(sub) = sub_name {
@@ -1109,7 +1074,7 @@ impl JsonManipulator {
)
},
&self.contents,
- )?;
+ );
Ok(true)
}
@@ -1137,18 +1102,7 @@ impl JsonManipulator {
);
let mut match_map: IndexMap<String, String> = IndexMap::new();
- let match_result = match Preg::is_match_named(&node_regex, &self.contents, &mut match_map) {
- Ok(b) => Ok(b),
- Err(e) => {
- if let Some(re) = e.downcast_ref::<RuntimeException>() {
- if re.code == PREG_BACKTRACK_LIMIT_ERROR {
- return Ok(false);
- }
- }
- Err(e)
- }
- }?;
- if !match_result {
+ if !Preg::is_match_named(&node_regex, &self.contents, &mut match_map) {
return Ok(false);
}
@@ -1163,9 +1117,7 @@ impl JsonManipulator {
"#^\\[(?P<leadingspace>\\s*?)(?P<content>\\S+.*?)?(?P<trailingspace>\\s*)\\]$#s",
&children,
&mut leading_match,
- )
- .unwrap_or(false)
- {
+ ) {
let leading_whitespace = leading_match
.get("leadingspace")
.cloned()
@@ -1201,7 +1153,7 @@ impl JsonManipulator {
"\\$",
),
&children,
- )?;
+ );
} else {
whitespace = leading_whitespace.clone();
children = Preg::replace(
@@ -1216,7 +1168,7 @@ impl JsonManipulator {
"\\$",
),
&children,
- )?;
+ );
}
} else {
// children present but empty
@@ -1251,7 +1203,7 @@ impl JsonManipulator {
)
},
&self.contents,
- )?;
+ );
Ok(true)
}
@@ -1301,18 +1253,7 @@ impl JsonManipulator {
);
let mut match_map: IndexMap<String, String> = IndexMap::new();
- let match_result = match Preg::is_match_named(&node_regex, &self.contents, &mut match_map) {
- Ok(b) => Ok(b),
- Err(e) => {
- if let Some(re) = e.downcast_ref::<RuntimeException>() {
- if re.code == PREG_BACKTRACK_LIMIT_ERROR {
- return Ok(false);
- }
- }
- Err(e)
- }
- }?;
- if !match_result {
+ if !Preg::is_match_named(&node_regex, &self.contents, &mut match_map) {
return Ok(false);
}
@@ -1356,7 +1297,7 @@ impl JsonManipulator {
)
},
&children,
- )?;
+ );
let children_owned = children;
self.contents = Preg::replace_callback(
@@ -1374,7 +1315,7 @@ impl JsonManipulator {
)
},
&self.contents,
- )?;
+ );
Ok(true)
}
@@ -1400,18 +1341,7 @@ impl JsonManipulator {
preg_quote(&JsonFile::encode(main_node), None)
);
let mut match_map: IndexMap<String, String> = IndexMap::new();
- let match_result = match Preg::is_match_named(&node_regex, &self.contents, &mut match_map) {
- Ok(b) => Ok(b),
- Err(e) => {
- if let Some(re) = e.downcast_ref::<RuntimeException>() {
- if re.code == PREG_BACKTRACK_LIMIT_ERROR {
- return Ok(false);
- }
- }
- Err(e)
- }
- }?;
- if !match_result {
+ if !Preg::is_match_named(&node_regex, &self.contents, &mut match_map) {
return Ok(false);
}
@@ -1463,9 +1393,7 @@ impl JsonManipulator {
),
&children,
&mut child_match,
- )
- .unwrap_or(false)
- {
+ ) {
self.contents = format!(
"{}{}{}{}",
match_map.get("start").cloned().unwrap_or_default(),
@@ -1492,7 +1420,7 @@ impl JsonManipulator {
);
let mut matches: IndexMap<String, String> = IndexMap::new();
if decoded.as_array().and_then(|a| a.get(key)).is_some()
- && Preg::is_match_named(&regex, &self.contents, &mut matches).unwrap_or(false)
+ && Preg::is_match_named(&regex, &self.contents, &mut matches)
{
// invalid match due to un-regexable content, abort
let key_match = matches.get("key").cloned().unwrap_or_default();
@@ -1513,9 +1441,7 @@ impl JsonManipulator {
// append at the end of the file and keep whitespace
let mut tail_match: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3("#[^{\\s](\\s*)\\}$#", &self.contents, Some(&mut tail_match))
- .unwrap_or(false)
- {
+ if Preg::is_match3("#[^{\\s](\\s*)\\}$#", &self.contents, Some(&mut tail_match)) {
let tail_match_1 = tail_match
.get(&CaptureKey::ByIndex(1))
.cloned()
@@ -1534,7 +1460,7 @@ impl JsonManipulator {
"\\$",
),
&self.contents,
- )?;
+ );
return Ok(true);
}
@@ -1553,7 +1479,7 @@ impl JsonManipulator {
"\\$",
),
&self.contents,
- )?;
+ );
Ok(true)
}
@@ -1573,7 +1499,7 @@ impl JsonManipulator {
preg_quote(&JsonFile::encode(key), None)
);
let mut matches: IndexMap<String, String> = IndexMap::new();
- if Preg::is_match_named(&regex, &self.contents, &mut matches).unwrap_or(false) {
+ if Preg::is_match_named(&regex, &self.contents, &mut matches) {
// invalid match due to un-regexable content, abort
let removal = matches.get("removal").cloned().unwrap_or_default();
if json_decode(&format!("{{{}}}", removal), false)?.is_null() {
@@ -1583,17 +1509,15 @@ impl JsonManipulator {
// check that we are not leaving a dangling comma on the previous line if the last line was removed
let mut start = matches.get("start").cloned().unwrap_or_default();
let end = matches.get("end").cloned().unwrap_or_default();
- if Preg::is_match3("#,\\s*$#", &start, None).unwrap_or(false)
- && Preg::is_match3("#^\\}$#", &end, None).unwrap_or(false)
- {
+ if Preg::is_match3("#,\\s*$#", &start, None) && Preg::is_match3("#^\\}$#", &end, None) {
start = rtrim(
- &Preg::replace("#,(\\s*)$#", "$1", &start)?,
+ &Preg::replace("#,(\\s*)$#", "$1", &start),
Some(&self.indent),
);
}
self.contents = format!("{}{}", start, end);
- if Preg::is_match3("#^\\{\\s*\\}\\s*$#", &self.contents, None).unwrap_or(false) {
+ if Preg::is_match3("#^\\{\\s*\\}\\s*$#", &self.contents, None) {
self.contents = "{\n}".to_string();
}
@@ -1617,7 +1541,7 @@ impl JsonManipulator {
preg_quote(&JsonFile::encode(key), None)
);
let mut matches: IndexMap<String, String> = IndexMap::new();
- if Preg::is_match_named(&regex, &self.contents, &mut matches).unwrap_or(false) {
+ if Preg::is_match_named(&regex, &self.contents, &mut matches) {
// invalid match due to un-regexable content, abort
let removal = matches.get("removal").cloned().unwrap_or_default();
if json_decode(&removal, false)?.as_bool() == Some(false) {
diff --git a/crates/shirabe/src/package/archiver/archivable_files_finder.rs b/crates/shirabe/src/package/archiver/archivable_files_finder.rs
index 2e9a3f2..c6a2d39 100644
--- a/crates/shirabe/src/package/archiver/archivable_files_finder.rs
+++ b/crates/shirabe/src/package/archiver/archivable_files_finder.rs
@@ -59,8 +59,7 @@ impl ArchivableFilesFinder {
&format!("^{}", preg_quote(&sources_clone, Some('#'))),
"",
&fs.normalize_path(&realpath.to_string_lossy()),
- )
- .unwrap_or_default();
+ );
let mut exclude = false;
for f in &filters {
diff --git a/crates/shirabe/src/package/archiver/archive_manager.rs b/crates/shirabe/src/package/archiver/archive_manager.rs
index a4169ef..cb15b76 100644
--- a/crates/shirabe/src/package/archiver/archive_manager.rs
+++ b/crates/shirabe/src/package/archiver/archive_manager.rs
@@ -62,7 +62,7 @@ impl ArchiveManager {
) -> anyhow::Result<IndexMap<String, String>> {
let base_name = match package.get_archive_name() {
Some(name) => name.to_string(),
- None => Preg::replace("#[^a-z0-9-_]#i", "-", &package.get_name())?,
+ None => Preg::replace("#[^a-z0-9-_]#i", "-", &package.get_name()),
};
let mut parts: IndexMap<String, String> = IndexMap::new();
@@ -70,7 +70,7 @@ impl ArchiveManager {
let dist_reference = package.get_dist_reference();
if let Some(ref dist_ref) = dist_reference {
- if Preg::is_match("{^[a-f0-9]{40}$}", dist_ref).unwrap_or(false) {
+ if Preg::is_match("{^[a-f0-9]{40}$}", dist_ref) {
parts.insert("dist_reference".to_string(), dist_ref.to_string());
if let Some(dist_type) = package.get_dist_type() {
parts.insert("dist_type".to_string(), dist_type.to_string());
diff --git a/crates/shirabe/src/package/archiver/base_exclude_filter.rs b/crates/shirabe/src/package/archiver/base_exclude_filter.rs
index 4de3cbb..1bd5b85 100644
--- a/crates/shirabe/src/package/archiver/base_exclude_filter.rs
+++ b/crates/shirabe/src/package/archiver/base_exclude_filter.rs
@@ -86,11 +86,8 @@ pub trait BaseExcludeFilter {
relative_path
};
- // suppressed RuntimeException, equivalent to PHP try-catch
- if let Ok(matched) = Preg::is_match(pattern, path) {
- if matched {
- exclude = !negate;
- }
+ if Preg::is_match(pattern, path) {
+ exclude = !negate;
}
}
diff --git a/crates/shirabe/src/package/archiver/git_exclude_filter.rs b/crates/shirabe/src/package/archiver/git_exclude_filter.rs
index ffa349c..aeaed0a 100644
--- a/crates/shirabe/src/package/archiver/git_exclude_filter.rs
+++ b/crates/shirabe/src/package/archiver/git_exclude_filter.rs
@@ -34,7 +34,7 @@ impl GitExcludeFilter {
}
fn parse_git_attributes_line_static(line: &str) -> Option<(String, bool, bool)> {
- let parts = Preg::split(r"\s+", line).unwrap_or_default();
+ let parts = Preg::split(r"\s+", line);
if parts.len() == 2 && parts[1] == "export-ignore" {
return Some(BaseExcludeFilterBase::generate_pattern(&parts[0]));
diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs
index 8e87302..222b5df 100644
--- a/crates/shirabe/src/package/loader/array_loader.rs
+++ b/crates/shirabe/src/package/loader/array_loader.rs
@@ -517,7 +517,7 @@ impl ArrayLoader {
if let Some(time_value) = config.get("time") {
if !shirabe_php_shim::empty(time_value) {
let time_str = time_value.as_string().unwrap_or("");
- let time = if Preg::is_match(r"/^\d++$/D", time_str).unwrap_or(false) {
+ let time = if Preg::is_match(r"/^\d++$/D", time_str) {
format!("@{}", time_str)
} else {
time_str.to_string()
@@ -692,7 +692,7 @@ impl ArrayLoader {
let alias_normalized = self.get_branch_alias(config)?;
if let Some(alias_normalized) = alias_normalized {
if !alias_normalized.is_empty() {
- let pretty_alias = Preg::replace(r"{(\.9{7})+}", ".x", &alias_normalized)?;
+ let pretty_alias = Preg::replace(r"{(\.9{7})+}", ".x", &alias_normalized);
return Ok(match package {
CompleteOrRootPackage::Root(root) => RootAliasPackageHandle::new(
@@ -956,7 +956,7 @@ impl ArrayLoader {
&& default_branch_is_true
&& self
.version_parser
- .parse_numeric_alias_prefix(&Preg::replace(r"{^v}", "", &version_str)?)
+ .parse_numeric_alias_prefix(&Preg::replace(r"{^v}", "", &version_str))
.is_none()
{
return Ok(Some(VersionParser::DEFAULT_BRANCH_ALIAS.to_string()));
diff --git a/crates/shirabe/src/package/loader/root_package_loader.rs b/crates/shirabe/src/package/loader/root_package_loader.rs
index 476f6bd..92f2be0 100644
--- a/crates/shirabe/src/package/loader/root_package_loader.rs
+++ b/crates/shirabe/src/package/loader/root_package_loader.rs
@@ -278,9 +278,7 @@ impl RootPackageLoader {
r"(?:^|\| *|, *)([^,\s#|]+)(?:#[^ ]+)? +as +([^,\s|]+)(?:$| *\|| *,)",
req_version,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
let m2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default();
let mut alias = IndexMap::new();
@@ -331,13 +329,12 @@ impl RootPackageLoader {
for (req_name, req_version) in requires {
let mut constraints: Vec<String> = vec![];
- let or_split = Preg::split(r"\s*\|\|?\s*", req_version.trim()).unwrap_or_default();
+ let or_split = Preg::split(r"\s*\|\|?\s*", req_version.trim());
for or_constraint in &or_split {
let and_split = Preg::split(
r"(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)",
or_constraint,
- )
- .unwrap_or_default();
+ );
for and_constraint in and_split {
constraints.push(and_constraint);
}
@@ -349,7 +346,7 @@ impl RootPackageLoader {
let mut matched = false;
for constraint in &constraints {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(&pattern, constraint, Some(&mut m)).unwrap_or(false) {
+ if Preg::is_match3(&pattern, constraint, Some(&mut m)) {
let name = strtolower(req_name);
let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
let normalized_m1 = VersionParser::normalize_stability(&m1).unwrap_or_default();
@@ -368,9 +365,8 @@ impl RootPackageLoader {
}
for constraint in &constraints {
- let req_version_stripped =
- Preg::replace(r"^([^,\s@]+) as .+$", "$1", constraint).unwrap_or_default();
- if Preg::is_match(r"^[^,\s@]+$", &req_version_stripped).unwrap_or(false) {
+ let req_version_stripped = Preg::replace(r"^([^,\s@]+) as .+$", "$1", constraint);
+ if Preg::is_match(r"^[^,\s@]+$", &req_version_stripped) {
let stability_name = VersionParser::parse_stability(&req_version_stripped);
if stability_name != "stable" {
let name = strtolower(req_name);
@@ -394,12 +390,9 @@ impl RootPackageLoader {
mut references: IndexMap<String, String>,
) -> IndexMap<String, String> {
for (req_name, req_version) in requires {
- let req_version =
- Preg::replace(r"^([^,\s@]+) as .+$", "$1", req_version).unwrap_or_default();
+ let req_version = Preg::replace(r"^([^,\s@]+) as .+$", "$1", req_version);
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"^[^,\s@]+?#([a-f0-9]+)$", &req_version, Some(&mut m))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r"^[^,\s@]+?#([a-f0-9]+)$", &req_version, Some(&mut m)) {
if VersionParser::parse_stability(&req_version) == "dev" {
let name = strtolower(req_name);
references.insert(
diff --git a/crates/shirabe/src/package/loader/validating_array_loader.rs b/crates/shirabe/src/package/loader/validating_array_loader.rs
index 4a1e2c2..dd2642e 100644
--- a/crates/shirabe/src/package/loader/validating_array_loader.rs
+++ b/crates/shirabe/src/package/loader/validating_array_loader.rs
@@ -901,7 +901,7 @@ impl ValidatingArrayLoader {
}
if let Some(err) = Self::has_package_naming_error(&package, true) {
self.warnings.push(format!("{}.{}", link_type, err));
- } else if !Preg::is_match("{^[A-Za-z0-9_./-]+$}", &package).unwrap_or(false) {
+ } else if !Preg::is_match("{^[A-Za-z0-9_./-]+$}", &package) {
self.errors.push(format!(
"{}.{} : invalid key, package names must be strings containing only [A-Za-z0-9_./-]",
link_type, package
@@ -1161,7 +1161,7 @@ impl ValidatingArrayLoader {
}
if let Some(ref_val) = section.get("reference") {
let ref_str = php_to_string(&**ref_val);
- if Preg::is_match("{^\\s*-}", &ref_str).unwrap_or(false) {
+ if Preg::is_match("{^\\s*-}", &ref_str) {
self.errors.push(format!(
"{}.reference : must not start with a \"-\", \"{}\" given",
src_type, ref_str
@@ -1170,7 +1170,7 @@ impl ValidatingArrayLoader {
}
if let Some(url_val) = section.get("url") {
let url_str = php_to_string(&**url_val);
- if Preg::is_match("{^\\s*-}", &url_str).unwrap_or(false) {
+ if Preg::is_match("{^\\s*-}", &url_str) {
self.errors.push(format!(
"{}.url : must not start with a \"-\", \"{}\" given",
src_type, url_str
@@ -1332,9 +1332,7 @@ impl ValidatingArrayLoader {
if !Preg::is_match(
"{^[a-z0-9](?:[_.-]?[a-z0-9]++)*+/[a-z0-9](?:(?:[_.]|-{1,2})?[a-z0-9]++)*+$}iD",
name,
- )
- .unwrap_or(false)
- {
+ ) {
return Some(format!(
"{} is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match \"^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{{0,2}})[a-z0-9]+)*$\".",
name
@@ -1355,14 +1353,14 @@ impl ValidatingArrayLoader {
));
}
- if Preg::is_match("{\\.json$}", name).unwrap_or(false) {
+ if Preg::is_match("{\\.json$}", name) {
return Some(format!(
"{} is invalid, package names can not end in .json, consider renaming it or perhaps using a -json suffix instead.",
name
));
}
- if Preg::is_match("{[A-Z]}", name).unwrap_or(false) {
+ if Preg::is_match("{[A-Z]}", name) {
if is_link {
return Some(format!(
"{} is invalid, it should not contain uppercase characters. Please use {} instead.",
@@ -1375,8 +1373,7 @@ impl ValidatingArrayLoader {
"{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}",
"\\1\\3-\\2\\4",
name,
- )
- .unwrap_or_else(|_| name.to_string());
+ );
let suggest_name = strtolower(&suggest_name);
return Some(format!(
@@ -1394,7 +1391,7 @@ impl ValidatingArrayLoader {
}
let value = self.config[property].as_string().unwrap_or("").to_string();
- if !Preg::is_match(&format!("{{^{}$}}u", regex), &value).unwrap_or(false) {
+ if !Preg::is_match(&format!("{{^{}$}}u", regex), &value) {
let message = format!(
"{} : invalid value ({}), must match {}",
property, value, regex
@@ -1508,7 +1505,7 @@ impl ValidatingArrayLoader {
if let Some(regex_str) = regex {
let value_str = php_to_string(&*value);
- if !Preg::is_match(&format!("{{^{}$}}u", regex_str), &value_str).unwrap_or(false) {
+ if !Preg::is_match(&format!("{{^{}$}}u", regex_str), &value_str) {
self.warnings.push(format!(
"{}.{} : invalid value ({}), must match {}",
property, key, value_str, regex_str
diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs
index 8c84b4e..1a16c27 100644
--- a/crates/shirabe/src/package/locker.rs
+++ b/crates/shirabe/src/package/locker.rs
@@ -874,7 +874,7 @@ impl Locker {
),
None,
);
- if Preg::is_match(r"{^\s*\d+\s*$}", &output_str).unwrap_or(false) {
+ if Preg::is_match(r"{^\s*\d+\s*$}", &output_str) {
let ts = trim(&output_str, None).parse::<i64>().unwrap_or(0);
datetime = chrono::DateTime::from_timestamp(ts, 0);
}
@@ -899,9 +899,7 @@ impl Locker {
r"{^\s*(\d+)\s*}",
output.as_string().unwrap_or(""),
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
let ts = m
.get(&CaptureKey::ByIndex(1))
.cloned()
diff --git a/crates/shirabe/src/package/package.rs b/crates/shirabe/src/package/package.rs
index f1c8cc9..8ef93be 100644
--- a/crates/shirabe/src/package/package.rs
+++ b/crates/shirabe/src/package/package.rs
@@ -145,8 +145,7 @@ impl Package {
"{ (?:^|[\\\\/]+) \\.\\.? (?:[\\\\/]+|$) (?:\\.\\.? (?:[\\\\/]+|$) )*}x",
"/",
target_dir,
- )
- .unwrap_or_else(|_| target_dir.clone());
+ );
Some(replaced.trim_start_matches('/').to_string())
}
@@ -423,17 +422,13 @@ impl Package {
"{^https?://(?:(?:www\\.)?bitbucket\\.org|(api\\.)?github\\.com|(?:www\\.)?gitlab\\.com)/}i",
self.get_dist_url().unwrap_or(""),
)
- .unwrap_or(false)
{
self.set_dist_reference(Some(reference.clone()));
- self.set_dist_url(Some(
- Preg::replace(
- "{(?<=/|sha=)[a-f0-9]{40}(?=/|$)}i",
- &reference,
- self.get_dist_url().unwrap_or(""),
- )
- .unwrap_or_default(),
- ));
+ self.set_dist_url(Some(Preg::replace(
+ "{(?<=/|sha=)[a-f0-9]{40}(?=/|$)}i",
+ &reference,
+ self.get_dist_url().unwrap_or(""),
+ )));
} else if self.get_dist_reference().is_some() {
// update the dist reference if there was one, but if none was provided ignore it
self.set_dist_reference(Some(reference));
diff --git a/crates/shirabe/src/package/version/version_bumper.rs b/crates/shirabe/src/package/version/version_bumper.rs
index 627a0fb..2f4e513 100644
--- a/crates/shirabe/src/package/version/version_bumper.rs
+++ b/crates/shirabe/src/package/version/version_bumper.rs
@@ -46,12 +46,11 @@ impl VersionBumper {
return Ok(pretty_constraint);
}
- let major = Preg::replace(r"{^([1-9][0-9]*|0\.\d+).*}", "$1", &version)?;
- let version_without_suffix =
- Preg::replace(r"{(?:\.(?:0|9999999))+(-dev)?$}", "", &version)?;
+ let major = Preg::replace(r"{^([1-9][0-9]*|0\.\d+).*}", "$1", &version);
+ let version_without_suffix = Preg::replace(r"{(?:\.(?:0|9999999))+(-dev)?$}", "", &version);
let new_pretty_constraint = format!("^{}", version_without_suffix);
- if !Preg::is_match(r"{^\^\d+(\.\d+)*$}", &new_pretty_constraint)? {
+ if !Preg::is_match(r"{^\^\d+(\.\d+)*$}", &new_pretty_constraint) {
return Ok(pretty_constraint);
}
@@ -71,7 +70,7 @@ impl VersionBumper {
);
let mut matches: IndexMap<CaptureKey, Vec<(String, usize)>> = IndexMap::new();
- if Preg::is_match_all_with_offsets3(&pattern, &pretty_constraint, Some(&mut matches))? {
+ if Preg::is_match_all_with_offsets3(&pattern, &pretty_constraint, Some(&mut matches)) {
let mut modified = pretty_constraint.clone();
let constraint_matches = matches
.get(&CaptureKey::ByName("constraint".to_string()))
diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs
index 562d141..4eb3864 100644
--- a/crates/shirabe/src/package/version/version_guesser.rs
+++ b/crates/shirabe/src/package/version/version_guesser.rs
@@ -130,16 +130,12 @@ impl VersionGuesser {
if "-dev" == substr(version_data.version.as_deref().unwrap_or(""), -4, None)
&& Preg::is_match(r"{\.9{7}}", version_data.version.as_deref().unwrap_or(""))
- .unwrap_or(false)
{
- version_data.pretty_version = Some(
- Preg::replace(
- r"{(\.9{7})+}",
- ".x",
- version_data.version.as_deref().unwrap_or(""),
- )
- .unwrap_or_default(),
- );
+ version_data.pretty_version = Some(Preg::replace(
+ r"{(\.9{7})+}",
+ ".x",
+ version_data.version.as_deref().unwrap_or(""),
+ ));
}
let feature_non_empty = version_data
@@ -158,16 +154,12 @@ impl VersionGuesser {
r"{\.9{7}}",
version_data.feature_version.as_deref().unwrap_or(""),
)
- .unwrap_or(false)
{
- version_data.feature_pretty_version = Some(
- Preg::replace(
- r"{(\.9{7})+}",
- ".x",
- version_data.feature_version.as_deref().unwrap_or(""),
- )
- .unwrap_or_default(),
- );
+ version_data.feature_pretty_version = Some(Preg::replace(
+ r"{(\.9{7})+}",
+ ".x",
+ version_data.feature_version.as_deref().unwrap_or(""),
+ ));
}
version_data
@@ -210,19 +202,13 @@ impl VersionGuesser {
for branch in self.process.borrow().split_lines(&output) {
if !branch.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^(?:\* ) *(\(no branch\)|\(detached from \S+\)|\(HEAD detached at \S+\)|\S+) *([a-f0-9]+) .*$}",
- &branch,
- Some(&mut m),)
- .unwrap_or(false)
- {
- let g1 = m
- .get(&CaptureKey::ByIndex(1))
- .cloned()
- .unwrap_or_default();
- let g2 = m
- .get(&CaptureKey::ByIndex(2))
- .cloned()
- .unwrap_or_default();
+ if Preg::is_match3(
+ r"{^(?:\* ) *(\(no branch\)|\(detached from \S+\)|\(HEAD detached at \S+\)|\S+) *([a-f0-9]+) .*$}",
+ &branch,
+ Some(&mut m),
+ ) {
+ let g1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
+ let g2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default();
if g1 == "(no branch)"
|| strpos(&g1, "(detached ") == Some(0)
|| strpos(&g1, "(HEAD detached at") == Some(0)
@@ -243,16 +229,14 @@ impl VersionGuesser {
if !branch.is_empty() && {
let mut tmp: IndexMap<CaptureKey, String> = IndexMap::new();
- !Preg::is_match3(r"{^ *.+/HEAD }", &branch, Some(&mut tmp)).unwrap_or(false)
+ !Preg::is_match3(r"{^ *.+/HEAD }", &branch, Some(&mut tmp))
} {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::is_match3(
r"{^(?:\* )? *((?:remotes/(?:origin|upstream)/)?[^\s/]+) *([a-f0-9]+) .*$}",
&branch,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
branches.push(m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default());
}
}
@@ -498,8 +482,7 @@ impl VersionGuesser {
)
.is_some();
if !has_branch_alias || has_self_version {
- let branch =
- Preg::replace(r"{^dev-}", "", version.as_deref().unwrap_or("")).unwrap_or_default();
+ let branch = Preg::replace(r"{^dev-}", "", version.as_deref().unwrap_or(""));
let mut length: i64 = PHP_INT_MAX;
// return directly, if branch is configured to be non-feature branch
@@ -532,8 +515,7 @@ impl VersionGuesser {
let mut last_index: i64 = -1;
for (index, candidate) in branches.iter().enumerate() {
let index = index as i64;
- let candidate_version =
- Preg::replace(r"{^remotes/\S+/}", "", candidate).unwrap_or_default();
+ let candidate_version = Preg::replace(r"{^remotes/\S+/}", "", candidate);
// do not compare against itself or other feature branches
if candidate == &branch
@@ -613,7 +595,6 @@ impl VersionGuesser {
),
branch_name.unwrap_or(""),
)
- .unwrap_or(false)
}
/// @return array{version: string|null, commit: '', pretty_version: string|null}
@@ -700,7 +681,7 @@ impl VersionGuesser {
trunk_path, branches_path, tags_path,
);
- if let Some(matches) = Preg::is_match_with_indexed_captures(&url_pattern, &output)? {
+ if let Some(matches) = Preg::is_match_with_indexed_captures(&url_pattern, &output) {
let m1 = matches.get(1).cloned().unwrap_or_default();
let m2 = matches.get(2).cloned();
let m3 = matches.get(3).cloned();
@@ -758,7 +739,7 @@ impl VersionGuesser {
}
};
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^(\d+(?:\.\d+)*)-dev$}i", &version, Some(&mut m)).unwrap_or(false) {
+ if Preg::is_match3(r"{^(\d+(?:\.\d+)*)-dev$}i", &version, Some(&mut m)) {
return Ok(format!(
"{}.x-dev",
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default()
diff --git a/crates/shirabe/src/package/version/version_parser.rs b/crates/shirabe/src/package/version/version_parser.rs
index 1b588bc..e600c37 100644
--- a/crates/shirabe/src/package/version/version_parser.rs
+++ b/crates/shirabe/src/package/version/version_parser.rs
@@ -45,11 +45,11 @@ impl VersionParser {
let count = pairs.len();
let mut i = 0_usize;
while i < count {
- let mut pair = Preg::replace(r"{^([^=: ]+)[=: ](.*)$}", "$1 $2", &pairs[i].trim())?;
+ let mut pair = Preg::replace(r"{^([^=: ]+)[=: ](.*)$}", "$1 $2", &pairs[i].trim());
if !pair.contains(' ')
&& i + 1 < count
&& !pairs[i + 1].contains('/')
- && !Preg::is_match(r"{(?<=[a-z0-9_/-])\*|\*(?=[a-z0-9_/-])}i", &pairs[i + 1])?
+ && !Preg::is_match(r"{(?<=[a-z0-9_/-])\*|\*(?=[a-z0-9_/-])}i", &pairs[i + 1])
&& !PlatformRepository::is_platform_package(&pairs[i + 1])
{
pair += &format!(" {}", pairs[i + 1]);
diff --git a/crates/shirabe/src/package/version/version_selector.rs b/crates/shirabe/src/package/version/version_selector.rs
index d4ce4c1..872ca93 100644
--- a/crates/shirabe/src/package/version/version_selector.rs
+++ b/crates/shirabe/src/package/version/version_selector.rs
@@ -282,7 +282,7 @@ impl VersionSelector {
if let Some(extra) = extra {
if extra != VersionParser::DEFAULT_BRANCH_ALIAS {
let new_extra =
- Preg::replace(r"{^(\d+\.\d+\.\d+)(\.9999999)-dev$}", "$1.0", &extra)?;
+ Preg::replace(r"{^(\d+\.\d+\.\d+)(\.9999999)-dev$}", "$1.0", &extra);
if new_extra != extra {
let new_extra = new_extra.replace(".9999999", ".0");
return self.transform_version(&new_extra, &new_extra, "dev");
@@ -302,7 +302,7 @@ impl VersionSelector {
let semantic_version_parts: Vec<&str> = version.split('.').collect();
if semantic_version_parts.len() == 4
- && Preg::is_match(r"{^\d+\D?}", semantic_version_parts[3]).unwrap_or(false)
+ && Preg::is_match(r"{^\d+\D?}", semantic_version_parts[3])
{
let mut parts: Vec<String> = semantic_version_parts
.iter()
diff --git a/crates/shirabe/src/platform/version.rs b/crates/shirabe/src/platform/version.rs
index f1d2b87..b78baad 100644
--- a/crates/shirabe/src/platform/version.rs
+++ b/crates/shirabe/src/platform/version.rs
@@ -11,11 +11,11 @@ impl Version {
*is_fips = false;
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if !Preg::match3(r"^(?P<version>[0-9.]+)(?P<patch>[a-z]{0,2})(?P<suffix>(?:-?(?:dev|pre|alpha|beta|rc|fips)[\d]*)*)(?:-\w+)?(?: \(.+?\))?$",
- openssl_version,
- Some(&mut matches),)
- .unwrap_or(false)
- {
+ if !Preg::match3(
+ r"^(?P<version>[0-9.]+)(?P<patch>[a-z]{0,2})(?P<suffix>(?:-?(?:dev|pre|alpha|beta|rc|fips)[\d]*)*)(?:-\w+)?(?: \(.+?\))?$",
+ openssl_version,
+ Some(&mut matches),
+ ) {
return None;
}
@@ -59,9 +59,7 @@ impl Version {
r"^(?P<major>\d+)(?P<minor>[a-z]*)$",
libjpeg_version,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
return None;
}
@@ -86,9 +84,7 @@ impl Version {
r"^(?P<year>\d{4})(?P<revision>[a-z]*)$",
zoneinfo_version,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
return None;
}
diff --git a/crates/shirabe/src/plugin/plugin_manager.rs b/crates/shirabe/src/plugin/plugin_manager.rs
index 24899cd..25953ab 100644
--- a/crates/shirabe/src/plugin/plugin_manager.rs
+++ b/crates/shirabe/src/plugin/plugin_manager.rs
@@ -257,7 +257,7 @@ impl PluginManager {
}
if package.get_name() == "symfony/flex"
- && Preg::is_match3("{^[0-9.]+$}", &package.get_version(), None).unwrap_or(false)
+ && Preg::is_match3("{^[0-9.]+$}", &package.get_version(), None)
&& version_compare(&package.get_version(), "1.9.8", "<")
{
self.io.write_error(&format!("<warning>The \"{}\" plugin {}was skipped because it is not compatible with Composer 2+. Make sure to update it to version 1.9.8 or greater.</warning>",
@@ -846,7 +846,7 @@ impl PluginManager {
.map(|(k, v)| (k.clone(), *v))
.collect();
for (pattern, allow) in &rules_snapshot {
- if Preg::is_match3(pattern, package, None).unwrap_or(false) {
+ if Preg::is_match3(pattern, package, None) {
return Ok(*allow);
}
}
diff --git a/crates/shirabe/src/question/strict_confirmation_question.rs b/crates/shirabe/src/question/strict_confirmation_question.rs
index 725005a..87290ac 100644
--- a/crates/shirabe/src/question/strict_confirmation_question.rs
+++ b/crates/shirabe/src/question/strict_confirmation_question.rs
@@ -48,10 +48,10 @@ impl StrictConfirmationQuestion {
return default.clone();
}
if let PhpMixed::String(s) = &answer {
- if Preg::is_match(&true_regex, s).unwrap_or(false) {
+ if Preg::is_match(&true_regex, s) {
return PhpMixed::Bool(true);
}
- if Preg::is_match(&false_regex, s).unwrap_or(false) {
+ if Preg::is_match(&false_regex, s) {
return PhpMixed::Bool(false);
}
}
diff --git a/crates/shirabe/src/repository/array_repository.rs b/crates/shirabe/src/repository/array_repository.rs
index b7d862d..cfc804f 100644
--- a/crates/shirabe/src/repository/array_repository.rs
+++ b/crates/shirabe/src/repository/array_repository.rs
@@ -321,11 +321,11 @@ impl RepositoryInterface for ArrayRepository {
r#type: Option<String>,
) -> anyhow::Result<Vec<SearchResult>> {
let regex = if mode == crate::repository::SEARCH_FULLTEXT {
- let parts = Preg::split("{\\s+}", &preg_quote(&query, None)).unwrap_or_default();
+ let parts = Preg::split("{\\s+}", &preg_quote(&query, None));
format!("{{(?:{})}}i", implode("|", &parts))
} else {
// vendor/name searches expect the caller to have preg_quoted the query
- let parts = Preg::split("{\\s+}", &query).unwrap_or_default();
+ let parts = Preg::split("{\\s+}", &query);
format!("{{(?:{})}}i", implode("|", &parts))
};
@@ -361,10 +361,9 @@ impl RepositoryInterface for ArrayRepository {
.get_description()
.unwrap_or_default()
),
- )
- .unwrap_or(false);
+ );
- if Preg::is_match(&regex, &name).unwrap_or(false) || fulltext_match {
+ if Preg::is_match(&regex, &name) || fulltext_match {
if mode == crate::repository::SEARCH_VENDOR {
matches.insert(
name.clone(),
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs
index 5994968..c1e2379 100644
--- a/crates/shirabe/src/repository/composer_repository.rs
+++ b/crates/shirabe/src/repository/composer_repository.rs
@@ -160,7 +160,7 @@ impl ComposerRepository {
.and_then(|v| v.as_string())
.unwrap_or("")
.to_string();
- if !Preg::is_match(r"{^[\w.]+\??://}", &url_str)? {
+ if !Preg::is_match(r"{^[\w.]+\??://}", &url_str) {
if let Some(local_file_path) = realpath(&url_str) {
// it is a local path, add file scheme
repo_config.insert(
@@ -252,7 +252,7 @@ impl ComposerRepository {
r"{^(?P<proto>https?)://packagist\.org/?$}i",
&url,
Some(&mut match_packagist),
- )? {
+ ) {
let proto = match_packagist
.get(&CaptureKey::ByName("proto".to_string()))
.cloned()
@@ -260,14 +260,14 @@ impl ComposerRepository {
url = format!("{}://repo.packagist.org", proto);
}
- let base_url_trimmed = Preg::replace(r"{(?:/[^/\\]+\.json)?(?:[?#].*)?$}", "", &url)?;
+ let base_url_trimmed = Preg::replace(r"{(?:/[^/\\]+\.json)?(?:[?#].*)?$}", "", &url);
let base_url = base_url_trimmed.trim_end_matches('/').to_string();
assert!(!base_url.is_empty());
let cache_dir = format!(
"{}/{}",
config.get("cache-repo-dir").as_string().unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.clone()))?,
+ Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.clone())),
);
let cache = Cache::new(io.clone(), &cache_dir, Some("a-z0-9.$~"), None, false);
let version_parser = VersionParser::new();
@@ -436,7 +436,7 @@ impl ComposerRepository {
match &package_filter_regex {
Some(regex) => {
let results_refs: Vec<&str> = results.iter().map(|s| s.as_str()).collect();
- Ok(Preg::grep(regex, &results_refs)?)
+ Ok(Preg::grep(regex, &results_refs))
}
None => Ok(results),
}
@@ -774,12 +774,12 @@ impl ComposerRepository {
if mode == SEARCH_VENDOR {
let mut results: Vec<IndexMap<String, PhpMixed>> = Vec::new();
- let parts = Preg::split(r"{\s+}", &query)?;
+ let parts = Preg::split(r"{\s+}", &query);
let regex = format!("{{(?:{})}}i", parts.join("|"));
let vendor_names = self.get_vendor_names()?;
let vendor_names_refs: Vec<&str> = vendor_names.iter().map(|s| s.as_str()).collect();
- for name in Preg::grep(&regex, &vendor_names_refs)? {
+ for name in Preg::grep(&regex, &vendor_names_refs) {
let mut entry = IndexMap::new();
entry.insert("name".to_string(), PhpMixed::String(name));
entry.insert("description".to_string(), PhpMixed::String(String::new()));
@@ -796,7 +796,7 @@ impl ComposerRepository {
r"{^\^(?P<query>(?P<vendor>[a-z0-9_.-]+)/[a-z0-9_.-]*)\*?$}i",
&query,
Some(&mut match_groups),
- )? && self.list_url.is_some()
+ ) && self.list_url.is_some()
{
let q = match_groups
.get(&CaptureKey::ByName("query".to_string()))
@@ -839,12 +839,12 @@ impl ComposerRepository {
}
let mut results: Vec<IndexMap<String, PhpMixed>> = Vec::new();
- let parts = Preg::split(r"{\s+}", &query)?;
+ let parts = Preg::split(r"{\s+}", &query);
let regex = format!("{{(?:{})}}i", parts.join("|"));
let package_names = self.get_package_names(None)?;
let package_names_refs: Vec<&str> = package_names.iter().map(|s| s.as_str()).collect();
- for name in Preg::grep(&regex, &package_names_refs)? {
+ for name in Preg::grep(&regex, &package_names_refs) {
let mut entry = IndexMap::new();
entry.insert("name".to_string(), PhpMixed::String(name));
entry.insert("description".to_string(), PhpMixed::String(String::new()));
@@ -1737,7 +1737,7 @@ impl ComposerRepository {
for (name, constraint) in names_iter {
let name = strtolower(&name);
- let real_name = Preg::replace(r"{~dev$}", "", &name)?;
+ let real_name = Preg::replace(r"{~dev$}", "", &name);
// skip platform packages, root package and composer-plugin-api
if PlatformRepository::is_platform_package(&real_name) || real_name == "__root__" {
continue;
@@ -2410,7 +2410,7 @@ impl ComposerRepository {
if url.starts_with('/') {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^[^:]++://[^/]*+}", &self.url, Some(&mut matches))? {
+ if Preg::is_match3(r"{^[^:]++://[^/]*+}", &self.url, Some(&mut matches)) {
return Ok(format!(
"{}{}",
matches
@@ -2722,7 +2722,7 @@ impl ComposerRepository {
// url-encode $ signs in URLs as bad proxies choke on them
if let Some(pos) = filename.find('$') {
- if pos > 0 && Preg::is_match(r"{^https?://}i", &filename)? {
+ if pos > 0 && Preg::is_match(r"{^https?://}i", &filename) {
filename = format!("{}%24{}", &filename[..pos], &filename[pos + 1..]);
}
}
@@ -3367,7 +3367,7 @@ impl ComposerRepository {
if let Some(ref patterns) = self.available_package_patterns {
for provider_regex in patterns.iter() {
- if Preg::is_match(provider_regex, name)? {
+ if Preg::is_match(provider_regex, name) {
return Ok(true);
}
}
diff --git a/crates/shirabe/src/repository/filesystem_repository.rs b/crates/shirabe/src/repository/filesystem_repository.rs
index 57f3c87..38d5836 100644
--- a/crates/shirabe/src/repository/filesystem_repository.rs
+++ b/crates/shirabe/src/repository/filesystem_repository.rs
@@ -390,7 +390,7 @@ impl FilesystemRepository {
let pattern = "{(?(DEFINE)\n (?<number> -? \\s*+ \\d++ (?:\\.\\d++)? )\n (?<boolean> true | false | null )\n (?<strings> (?&string) (?: \\s*+ \\. \\s*+ (?&string))*+ )\n (?<string> (?: \" (?:[^\"\\\\$]*+ | \\\\ [\"\\\\0] )* \" | ' (?:[^'\\\\]*+ | \\\\ ['\\\\] )* ' ) )\n (?<array> array\\( \\s*+ (?: (?:(?&number)|(?&strings)) \\s*+ => \\s*+ (?: (?:__DIR__ \\s*+ \\. \\s*+)? (?&strings) | (?&value) ) \\s*+, \\s*+ )*+ \\s*+ \\) )\n (?<value> (?: (?&number) | (?&boolean) | (?&strings) | (?&array) ) )\n)\n^<\\?php\\s++return\\s++(?&array)\\s*+;$}ix";
if let Some(data) = installed_versions_data {
let mixed = PhpMixed::String(data.clone());
- if is_string(&mixed) && Preg::is_match(pattern, &trim(&data, None)).unwrap_or(false) {
+ if is_string(&mixed) && Preg::is_match(pattern, &trim(&data, None)) {
let replaced = Preg::replace(
r#"{=>\s*+__DIR__\s*+\.\s*+(['\"])}"#,
&format!(
@@ -399,10 +399,6 @@ impl FilesystemRepository {
),
&data,
);
- let replaced = match replaced {
- Ok(s) => s,
- Err(_) => return false,
- };
let evaluated = r#eval(&format!("?>{}", replaced));
InstalledVersions::reload(
evaluated
diff --git a/crates/shirabe/src/repository/filter_repository.rs b/crates/shirabe/src/repository/filter_repository.rs
index 0e05c25..90e211f 100644
--- a/crates/shirabe/src/repository/filter_repository.rs
+++ b/crates/shirabe/src/repository/filter_repository.rs
@@ -137,14 +137,14 @@ impl FilterRepository {
}
if let Some(only) = &self.only {
- return Preg::is_match(only, name).unwrap_or(false);
+ return Preg::is_match(only, name);
}
if self.exclude.is_none() {
return true;
}
- !Preg::is_match(self.exclude.as_ref().unwrap(), name).unwrap_or(false)
+ !Preg::is_match(self.exclude.as_ref().unwrap(), name)
}
}
diff --git a/crates/shirabe/src/repository/package_repository.rs b/crates/shirabe/src/repository/package_repository.rs
index 273cde0..5ba4840 100644
--- a/crates/shirabe/src/repository/package_repository.rs
+++ b/crates/shirabe/src/repository/package_repository.rs
@@ -77,7 +77,6 @@ impl PackageRepository {
pub fn get_repo_name(&self) -> String {
use crate::repository::RepositoryInterface;
Preg::replace(r"^array ", "package ", &self.inner.get_repo_name())
- .unwrap_or_else(|_| self.inner.get_repo_name())
}
}
diff --git a/crates/shirabe/src/repository/path_repository.rs b/crates/shirabe/src/repository/path_repository.rs
index 51acff0..cfd42e5 100644
--- a/crates/shirabe/src/repository/path_repository.rs
+++ b/crates/shirabe/src/repository/path_repository.rs
@@ -120,9 +120,9 @@ impl PathRepository {
let url_matches = self.get_url_matches()?;
if url_matches.is_empty() {
- if Preg::is_match(r"{[*{}]}", &self.url).unwrap_or(false) {
+ if Preg::is_match(r"{[*{}]}", &self.url) {
let mut url = self.url.clone();
- while Preg::is_match(r"{[*{}]}", &url).unwrap_or(false) {
+ while Preg::is_match(r"{[*{}]}", &url) {
url = shirabe_php_shim::dirname(&url);
}
// the parent directory before any wildcard exists, so we assume it is correctly configured but simply empty
diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs
index 39e29fb..3136065 100644
--- a/crates/shirabe/src/repository/platform_repository.rs
+++ b/crates/shirabe/src/repository/platform_repository.rs
@@ -218,8 +218,7 @@ impl PlatformRepository {
version = v;
}
Err(_) => {
- pretty_version = Preg::replace("#^([^~+-]+).*$#", "$1", &php_version_str)
- .unwrap_or(php_version_str);
+ pretty_version = Preg::replace("#^([^~+-]+).*$#", "$1", &php_version_str);
version = self
.version_parser
.as_ref()
@@ -352,9 +351,7 @@ impl PlatformRepository {
"/^librabbitmq version => (?<version>.+)$/im",
&info,
Some(&mut librabbitmq_matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-librabbitmq", name),
@@ -373,9 +370,7 @@ impl PlatformRepository {
"/^AMQP protocol version => (?<version>.+)$/im",
&info,
Some(&mut protocol_matches),
- )
- .unwrap_or(false)
- {
+ ) {
let version_str = protocol_matches
.get(&CaptureKey::ByName("version".to_string()))
.cloned()
@@ -400,9 +395,7 @@ impl PlatformRepository {
"/^BZip2 Version => (?<version>.*),/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
name,
@@ -438,9 +431,7 @@ impl PlatformRepository {
"{^SSL Version => (?<library>[^/]+)/(?<version>.+)$}im",
&info,
Some(&mut ssl_matches),
- )
- .unwrap_or(false)
- {
+ ) {
let ssl_library_raw = ssl_matches
.get(&CaptureKey::ByName("library".to_string()))
.cloned()
@@ -476,9 +467,7 @@ impl PlatformRepository {
"{^\\(securetransport\\) ([a-z0-9]+)}",
&library,
Some(&mut securetransport_matches),
- )
- .unwrap_or(false)
- {
+ ) {
shortlib = "securetransport".to_string();
let m1 = securetransport_matches
.get(&CaptureKey::ByIndex(1))
@@ -510,9 +499,7 @@ impl PlatformRepository {
"{^libSSH Version => (?<library>[^/]+)/(?<version>.+?)(?:/.*)?$}im",
&info,
Some(&mut ssh_matches),
- )
- .unwrap_or(false)
- {
+ ) {
let ssh_library = ssh_matches
.get(&CaptureKey::ByName("library".to_string()))
.cloned()
@@ -537,9 +524,7 @@ impl PlatformRepository {
"{^ZLib Version => (?<version>.+)$}im",
&info,
Some(&mut zlib_matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-zlib", name),
@@ -562,9 +547,7 @@ impl PlatformRepository {
"/^timelib version => (?<version>.+)$/im",
&info,
Some(&mut timelib_matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-timelib", name),
@@ -583,19 +566,17 @@ impl PlatformRepository {
"/^Timezone Database => (?<source>internal|external)$/im",
&info,
Some(&mut zoneinfo_source_matches),
- )
- .unwrap_or(false)
- {
+ ) {
let external = zoneinfo_source_matches
.get(&CaptureKey::ByName("source".to_string()))
.map(|s| s == "external")
.unwrap_or(false);
let mut zoneinfo_matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3("/^\"Olson\" Timezone Database Version => (?<version>.+?)(?:\\.system)?$/im",
- &info,
- Some(&mut zoneinfo_matches),)
- .unwrap_or(false)
- {
+ if Preg::is_match3(
+ "/^\"Olson\" Timezone Database Version => (?<version>.+?)(?:\\.system)?$/im",
+ &info,
+ Some(&mut zoneinfo_matches),
+ ) {
let zoneinfo_version = zoneinfo_matches
.get(&CaptureKey::ByName("version".to_string()))
.cloned()
@@ -635,9 +616,7 @@ impl PlatformRepository {
"/^libmagic => (?<version>.+)$/im",
&info,
Some(&mut magic_matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libmagic", name),
@@ -673,9 +652,7 @@ impl PlatformRepository {
"/^libJPEG Version => (?<version>.+?)(?: compatible)?$/im",
&info,
Some(&mut libjpeg_matches),
- )
- .unwrap_or(false)
- {
+ ) {
let libjpeg_version = libjpeg_matches
.get(&CaptureKey::ByName("version".to_string()))
.cloned()
@@ -696,9 +673,7 @@ impl PlatformRepository {
"/^libPNG Version => (?<version>.+)$/im",
&info,
Some(&mut libpng_matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libpng", name),
@@ -716,9 +691,7 @@ impl PlatformRepository {
"/^FreeType Version => (?<version>.+)$/im",
&info,
Some(&mut freetype_matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-freetype", name),
@@ -736,9 +709,7 @@ impl PlatformRepository {
"/^libXpm Version => (?<versionId>\\d+)$/im",
&info,
Some(&mut libxpm_matches),
- )
- .unwrap_or(false)
- {
+ ) {
let version_id: i64 = libxpm_matches
.get(&CaptureKey::ByName("versionId".to_string()))
.and_then(|s| s.parse().ok())
@@ -812,9 +783,7 @@ impl PlatformRepository {
"/^ICU version => (?<version>.+)$/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
"icu",
@@ -834,9 +803,7 @@ impl PlatformRepository {
"/^ICU TZData version => (?<version>.*)$/im",
&info,
Some(&mut zoneinfo_matches),
- )
- .unwrap_or(false)
- {
+ ) {
let zi_version = zoneinfo_matches
.get(&CaptureKey::ByName("version".to_string()))
.cloned()
@@ -922,9 +889,7 @@ impl PlatformRepository {
"/^ImageMagick (?<version>[\\d.]+)(?:-(?<patch>\\d+))?/",
&image_magick_version_str,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
let mut version_built = matches
.get(&CaptureKey::ByName("version".to_string()))
.cloned()
@@ -953,15 +918,11 @@ impl PlatformRepository {
"/^Vendor Version => (?<versionId>\\d+)$/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- && Preg::is_match3(
- "/^Vendor Name => (?<vendor>.+)$/im",
- &info,
- Some(&mut vendor_matches),
- )
- .unwrap_or(false)
- {
+ ) && Preg::is_match3(
+ "/^Vendor Name => (?<vendor>.+)$/im",
+ &info,
+ Some(&mut vendor_matches),
+ ) {
let version_id: i64 = matches
.get(&CaptureKey::ByName("versionId".to_string()))
.and_then(|s| s.parse().ok())
@@ -1016,9 +977,7 @@ impl PlatformRepository {
"/^libmbfl version => (?<version>.+)$/im",
&info,
Some(&mut libmbfl_matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libmbfl", name),
@@ -1054,9 +1013,7 @@ impl PlatformRepository {
"/^(?:oniguruma|Multibyte regex \\(oniguruma\\)) version => (?<version>.+)$/im",
&info,
Some(&mut oniguruma_matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-oniguruma", name),
@@ -1080,9 +1037,7 @@ impl PlatformRepository {
"/^libmemcached version => (?<version>.+)$/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libmemcached", name),
@@ -1108,9 +1063,7 @@ impl PlatformRepository {
"{^(?:OpenSSL|LibreSSL)?\\s*(?<version>\\S+)}i",
&openssl_text_str,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
let version = matches
.get(&CaptureKey::ByName("version".to_string()))
.cloned()
@@ -1139,8 +1092,7 @@ impl PlatformRepository {
PhpMixed::String(s) => s.clone(),
_ => "".to_string(),
};
- let stripped = Preg::replace("{^(\\S+).*}", "$1", &pcre_version_str)
- .unwrap_or(pcre_version_str);
+ let stripped = Preg::replace("{^(\\S+).*}", "$1", &pcre_version_str);
self.add_library(&mut libraries, name, Some(&stripped), None, &[], &[])?;
let info = self.runtime.get_extension_info(name)?;
@@ -1151,9 +1103,7 @@ impl PlatformRepository {
"/^PCRE Unicode Version => (?<version>.+)$/im",
&info,
Some(&mut pcre_unicode_matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-unicode", name),
@@ -1175,9 +1125,7 @@ impl PlatformRepository {
"/^(?:Client API version|Version) => mysqlnd (?<version>.+?) /mi",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-mysqlnd", name),
@@ -1199,9 +1147,7 @@ impl PlatformRepository {
"/^libmongoc bundled version => (?<version>.+)$/im",
&info,
Some(&mut libmongoc_matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libmongoc", name),
@@ -1219,9 +1165,7 @@ impl PlatformRepository {
"/^libbson bundled version => (?<version>.+)$/im",
&info,
Some(&mut libbson_matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libbson", name),
@@ -1259,9 +1203,7 @@ impl PlatformRepository {
"/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libpq", name),
@@ -1284,9 +1226,7 @@ impl PlatformRepository {
"/^PostgreSQL\\(libpq\\) Version => (?<version>.*)$/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libpq", name),
@@ -1310,9 +1250,7 @@ impl PlatformRepository {
"/^libpq => (?<compiled>.+) => (?<linked>.+)$/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libpq", name),
@@ -1391,9 +1329,7 @@ impl PlatformRepository {
"/^SQLite Library => (?<version>.+)$/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-sqlite", name),
@@ -1415,9 +1351,7 @@ impl PlatformRepository {
"/^libssh2 version => (?<version>.+)$/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libssh2", name),
@@ -1452,9 +1386,7 @@ impl PlatformRepository {
"/^libxslt compiled against libxml Version => (?<version>.+)$/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
"libxslt-libxml",
@@ -1476,9 +1408,7 @@ impl PlatformRepository {
"/^LibYAML Version => (?<version>.+)$/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
&format!("{}-libyaml", name),
@@ -1539,9 +1469,7 @@ impl PlatformRepository {
"/^Linked Version => (?<version>.+)$/im",
&info,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
self.add_library(
&mut libraries,
name,
@@ -1574,8 +1502,7 @@ impl PlatformRepository {
version = v;
}
Err(_) => {
- pretty_version = Preg::replace("#^([^~+-]+).*$#", "$1", &hhvm_version)
- .unwrap_or(hhvm_version);
+ pretty_version = Preg::replace("#^([^~+-]+).*$#", "$1", &hhvm_version);
version = self
.version_parser
.as_ref()
@@ -1739,9 +1666,7 @@ impl PlatformRepository {
"{^(\\d+\\.\\d+\\.\\d+(?:\\.\\d+)?)}",
&pretty_version,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
pretty_version = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
} else {
pretty_version = "0".to_string();
@@ -1869,7 +1794,7 @@ impl PlatformRepository {
return cached;
}
- let result = Preg::is_match(Self::PLATFORM_PACKAGE_REGEX, name).unwrap_or(false);
+ let result = Preg::is_match(Self::PLATFORM_PACKAGE_REGEX, name);
cache.insert(name.to_string(), result);
result
}
diff --git a/crates/shirabe/src/repository/repository_factory.rs b/crates/shirabe/src/repository/repository_factory.rs
index 5543a9e..71b1471 100644
--- a/crates/shirabe/src/repository/repository_factory.rs
+++ b/crates/shirabe/src/repository/repository_factory.rs
@@ -332,7 +332,7 @@ impl RepositoryFactory {
let mut name = match index {
PhpMixed::Int(_) => {
if let Some(url) = repo.get("url").and_then(|v| v.as_string()) {
- Preg::replace("{^https?://}i", "", url).unwrap_or_else(|_| url.to_string())
+ Preg::replace("{^https?://}i", "", url)
} else {
index.as_string().unwrap_or("").to_string()
}
@@ -351,7 +351,7 @@ impl RepositoryFactory {
existing_repos: &IndexMap<String, RepositoryInterfaceHandle>,
) -> String {
let mut name = if let Some(url) = repo.get("url").and_then(|v| v.as_string()) {
- Preg::replace("{^https?://}i", "", url).unwrap_or_else(|_| url.to_string())
+ Preg::replace("{^https?://}i", "", url)
} else {
index.to_string()
};
diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
index 82794a4..df52820 100644
--- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs
+++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
@@ -605,7 +605,7 @@ impl ForgejoDriver {
let links = explode(",", &header);
for link in links {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r#"{<(.+?)>; *rel="next"}"#, &link, Some(&mut m)).unwrap_or(false) {
+ if Preg::match3(r#"{<(.+?)>; *rel="next"}"#, &link, Some(&mut m)) {
if let Some(url) = m.get(&CaptureKey::ByIndex(1)) {
return Some(url.clone());
}
diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs
index 15328c0..c205379 100644
--- a/crates/shirabe/src/repository/vcs/fossil_driver.rs
+++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs
@@ -85,7 +85,7 @@ impl FossilDriver {
.into());
}
- let local_name = Preg::replace(r"{[^a-z0-9]}i", "-", &self.inner.url)?;
+ let local_name = Preg::replace(r"{[^a-z0-9]}i", "-", &self.inner.url);
self.repo_file = Some(format!("{}/{}.fossil", cache_repo_dir, local_name));
self.checkout_dir = format!("{}/{}/", cache_vcs_dir, local_name);
@@ -304,7 +304,7 @@ impl FossilDriver {
Some(self.checkout_dir.clone()),
);
for branch in self.inner.process.borrow().split_lines(&output) {
- let branch = Preg::replace(r"/^\*/", "", &branch.trim())?;
+ let branch = Preg::replace(r"/^\*/", "", &branch.trim());
let branch = branch.trim().to_string();
branches.insert(branch.clone(), branch);
}
@@ -322,13 +322,11 @@ impl FossilDriver {
if Preg::is_match(
r"#(^(?:https?|ssh)://(?:[^@]@)?(?:chiselapp\.com|fossil\.))#i",
url,
- )
- .unwrap_or(false)
- {
+ ) {
return Ok(true);
}
- if Preg::is_match(r"!/fossil/|\.fossil!", url).unwrap_or(false) {
+ if Preg::is_match(r"!/fossil/|\.fossil!", url) {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
index 674f849..b0985e5 100644
--- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
@@ -91,9 +91,7 @@ impl GitBitbucketDriver {
r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(?:\.git|/?)?$#i",
&self.inner.url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
return Err(InvalidArgumentException {
message: format!(
"The Bitbucket repository URL {} is invalid. It must be the HTTPS URL of a Bitbucket repository.",
@@ -799,8 +797,7 @@ impl GitBitbucketDriver {
r"/https:\/\/([^@]+@)?/",
"https://",
m.get("href").and_then(|v| v.as_string()).unwrap_or(""),
- )
- .unwrap_or_default();
+ );
}
}
}
@@ -862,9 +859,7 @@ impl GitBitbucketDriver {
if !Preg::is_match(
r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i",
url,
- )
- .unwrap_or(false)
- {
+ ) {
return Ok(false);
}
diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs
index 10353f3..3c950bb 100644
--- a/crates/shirabe/src/repository/vcs/git_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_driver.rs
@@ -51,7 +51,7 @@ impl GitDriver {
pub fn initialize(&mut self) -> anyhow::Result<()> {
let cache_url;
if Filesystem::is_local_path(&self.inner.url) {
- self.inner.url = Preg::replace(r"{[\\/]\.git/?$}", "", &self.inner.url)?;
+ self.inner.url = Preg::replace(r"{[\\/]\.git/?$}", "", &self.inner.url);
if !is_dir(&self.inner.url) {
return Err(RuntimeException {
message: format!(
@@ -88,7 +88,7 @@ impl GitDriver {
r"{[^a-z0-9.]}i",
"-",
&Url::sanitize(self.inner.url.clone())
- )?
+ )
);
GitUtil::clean_env(&self.inner.process);
@@ -108,7 +108,7 @@ impl GitDriver {
.into());
}
- if Preg::is_match(r"{^ssh://[^@]+@[^:]+:[^0-9]+}", &self.inner.url).unwrap_or(false) {
+ if Preg::is_match(r"{^ssh://[^@]+@[^:]+:[^0-9]+}", &self.inner.url) {
return Err(InvalidArgumentException {
message: format!(
"The source URL {} is invalid, ssh URLs should have a port number after \":\".\nUse ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.",
@@ -161,7 +161,7 @@ impl GitDriver {
&format!(
"{}/{}",
cache_repo_dir,
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(cache_url))?
+ Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(cache_url))
),
None,
None,
@@ -215,7 +215,7 @@ impl GitDriver {
for branch in &branches {
if !branch.is_empty() {
let mut caps: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"{^\* +(\S+)}", branch, Some(&mut caps)).unwrap_or(false) {
+ if Preg::match3(r"{^\* +(\S+)}", branch, Some(&mut caps)) {
if let Some(name) = caps.get(&CaptureKey::ByIndex(1)) {
self.root_identifier = Some(name.clone());
break;
@@ -338,9 +338,7 @@ impl GitDriver {
r"{^([a-f0-9]{40}) refs/tags/(\S+?)(\^\{\})?$}",
&tag,
Some(&mut caps),
- )
- .unwrap_or(false)
- {
+ ) {
if let (Some(hash), Some(name)) = (
caps.get(&CaptureKey::ByIndex(1)),
caps.get(&CaptureKey::ByIndex(2)),
@@ -375,17 +373,13 @@ impl GitDriver {
Some(self.repo_dir.clone()),
);
for branch in self.inner.process.borrow().split_lines(&output) {
- if !branch.is_empty()
- && !Preg::is_match(r"{^ *[^/]+/HEAD }", &branch).unwrap_or(false)
- {
+ if !branch.is_empty() && !Preg::is_match(r"{^ *[^/]+/HEAD }", &branch) {
let mut caps: IndexMap<CaptureKey, String> = IndexMap::new();
if Preg::match3(
r"{^(?:\* )? *(\S+) *([a-f0-9]+)(?: .*)?$}",
&branch,
Some(&mut caps),
- )
- .unwrap_or(false)
- {
+ ) {
if let (Some(name), Some(hash)) = (
caps.get(&CaptureKey::ByIndex(1)),
caps.get(&CaptureKey::ByIndex(2)),
@@ -413,9 +407,7 @@ impl GitDriver {
if Preg::is_match(
r"#(^git://|\.git/?$|git(?:olite)?@|//git\.|//github.com/)#i",
url,
- )
- .unwrap_or(false)
- {
+ ) {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs
index 64ed4d3..864b4f3 100644
--- a/crates/shirabe/src/repository/vcs/github_driver.rs
+++ b/crates/shirabe/src/repository/vcs/github_driver.rs
@@ -78,9 +78,7 @@ impl GitHubDriver {
r"#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#",
&self.inner.url,
Some(&mut match_),
- )
- .unwrap_or(false)
- {
+ ) {
return Err(InvalidArgumentException {
message: format!(
"The GitHub repository URL {} is invalid.",
@@ -501,10 +499,10 @@ impl GitHubDriver {
let mut result: Vec<IndexMap<String, PhpMixed>> = vec![];
let mut key: Option<String> = None;
- for line in Preg::split(r"{\r?\n}", &funding).unwrap_or_default() {
+ for line in Preg::split(r"{\r?\n}", &funding) {
let line = trim(&line, None);
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^(\w+)\s*:\s*(.+)$}", &line, Some(&mut m)).unwrap_or(false) {
+ if Preg::is_match3(r"{^(\w+)\s*:\s*(.+)$}", &line, Some(&mut m)) {
let g1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
let g2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default();
if g2 == "[" {
@@ -512,12 +510,11 @@ impl GitHubDriver {
continue;
}
let mut m2: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^\[(.*?)\](?:\s*#.*)?$}", &g2, Some(&mut m2)).unwrap_or(false)
- {
+ if Preg::is_match3(r"{^\[(.*?)\](?:\s*#.*)?$}", &g2, Some(&mut m2)) {
let inner = m2.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
for item in array_map(
|s: &String| trim(s, None),
- &Preg::split(r#"{[\'\"]?\s*,\s*[\'\"]?}"#, &inner).unwrap_or_default(),
+ &Preg::split(r#"{[\'\"]?\s*,\s*[\'\"]?}"#, &inner),
) {
let mut entry = IndexMap::new();
entry.insert("type".to_string(), PhpMixed::String(g1.clone()));
@@ -527,9 +524,7 @@ impl GitHubDriver {
);
result.push(entry);
}
- } else if Preg::is_match3(r"{^([^#].*?)(?:\s+#.*)?$}", &g2, Some(&mut m2))
- .unwrap_or(false)
- {
+ } else if Preg::is_match3(r"{^([^#].*?)(?:\s+#.*)?$}", &g2, Some(&mut m2)) {
let mut entry = IndexMap::new();
entry.insert("type".to_string(), PhpMixed::String(g1.clone()));
entry.insert(
@@ -542,18 +537,15 @@ impl GitHubDriver {
result.push(entry);
}
key = None;
- } else if Preg::is_match3(r"{^(\w+)\s*:\s*#\s*$}", &line, Some(&mut m)).unwrap_or(false)
- {
+ } else if Preg::is_match3(r"{^(\w+)\s*:\s*#\s*$}", &line, Some(&mut m)) {
key = Some(m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default());
} else if key.is_some() && {
let mut tmp: IndexMap<CaptureKey, String> = IndexMap::new();
- Preg::is_match3(r"{^-\s*(.+)(?:\s+#.*)?$}", &line, Some(&mut m)).unwrap_or(false)
- || Preg::is_match3(r"{^(.+),(?:\s*#.*)?$}", &line, Some(&mut tmp))
- .unwrap_or(false)
- && {
- m = tmp;
- true
- }
+ Preg::is_match3(r"{^-\s*(.+)(?:\s+#.*)?$}", &line, Some(&mut m))
+ || Preg::is_match3(r"{^(.+),(?:\s*#.*)?$}", &line, Some(&mut tmp)) && {
+ m = tmp;
+ true
+ }
} {
let mut entry = IndexMap::new();
entry.insert(
@@ -688,9 +680,7 @@ impl GitHubDriver {
if !array_key_exists("scheme", &bits_map)
&& !array_key_exists("host", &bits_map)
{
- if Preg::is_match(r"{^[a-z0-9-]++\.[a-z]{2,3}$}", &item_url)
- .unwrap_or(false)
- {
+ if Preg::is_match(r"{^[a-z0-9-]++\.[a-z]{2,3}$}", &item_url) {
result[key_idx].insert(
"url".to_string(),
PhpMixed::String(format!("https://{}", item_url)),
@@ -956,9 +946,7 @@ impl GitHubDriver {
r"#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#",
url,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
return Ok(false);
}
@@ -973,9 +961,7 @@ impl GitHubDriver {
.unwrap_or_default()
});
if !in_array(
- PhpMixed::String(strtolower(
- &Preg::replace(r"{^www\.}i", "", &origin_url).unwrap_or_default(),
- )),
+ PhpMixed::String(strtolower(&Preg::replace(r"{^www\.}i", "", &origin_url))),
&config.borrow().get("github-domains"),
false,
) {
@@ -1320,7 +1306,7 @@ impl GitHubDriver {
let links = explode(",", &header);
for link in &links {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r#"{<(.+?)>; *rel="next"}"#, link, Some(&mut m)).unwrap_or(false) {
+ if Preg::is_match3(r#"{<(.+?)>; *rel="next"}"#, link, Some(&mut m)) {
return Some(m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default());
}
}
diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
index a123a24..fc09108 100644
--- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs
+++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
@@ -84,7 +84,7 @@ impl GitLabDriver {
/// SSH urls use https by default. Set "secure-http": false on the repository config to use http instead.
pub fn initialize(&mut self) -> Result<()> {
let mut match_: IndexMap<CaptureKey, String> = IndexMap::new();
- if !Preg::is_match3(Self::URL_REGEX, &self.inner.url, Some(&mut match_)).unwrap_or(false) {
+ if !Preg::is_match3(Self::URL_REGEX, &self.inner.url, Some(&mut match_)) {
return Err(InvalidArgumentException {
message: format!(
"The GitLab repository URL {} is invalid. It must be the HTTP URL of a GitLab project.",
@@ -202,8 +202,7 @@ impl GitLabDriver {
.get(&CaptureKey::ByName("repo".to_string()))
.cloned()
.unwrap_or_default(),
- )
- .unwrap_or_default();
+ );
self.inner.cache = Some(Cache::new(
self.inner.io.clone(),
@@ -429,7 +428,7 @@ impl GitLabDriver {
// Convert the root identifier to a cacheable commit id
let mut identifier = identifier.to_string();
- if !Preg::is_match(r"{[a-f0-9]{40}}i", &identifier).unwrap_or(false) {
+ if !Preg::is_match(r"{[a-f0-9]{40}}i", &identifier) {
let branches = self.get_branches()?;
if let Some(sha) = branches.get(&identifier) {
identifier = sha.clone();
@@ -987,7 +986,7 @@ impl GitLabDriver {
_deep: bool,
) -> anyhow::Result<bool> {
let mut match_: IndexMap<CaptureKey, String> = IndexMap::new();
- if !Preg::is_match3(Self::URL_REGEX, url, Some(&mut match_)).unwrap_or(false) {
+ if !Preg::is_match3(Self::URL_REGEX, url, Some(&mut match_)) {
return Ok(false);
}
@@ -1055,9 +1054,7 @@ impl GitLabDriver {
let links = explode(",", &header);
for link in &links {
let mut match_: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r#"{<(.+?)>; *rel="next"}"#, link, Some(&mut match_))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r#"{<(.+?)>; *rel="next"}"#, link, Some(&mut match_)) {
return Some(
match_
.get(&CaptureKey::ByIndex(1))
@@ -1117,9 +1114,7 @@ impl GitLabDriver {
false,
) || (port_number.is_some()
&& in_array(
- PhpMixed::String(
- Preg::replace(r"{:\d+}", "", &guessed_domain).unwrap_or_default(),
- ),
+ PhpMixed::String(Preg::replace(r"{:\d+}", "", &guessed_domain)),
configured_domains,
false,
))
diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs
index c76f496..63a400c 100644
--- a/crates/shirabe/src/repository/vcs/hg_driver.rs
+++ b/crates/shirabe/src/repository/vcs/hg_driver.rs
@@ -61,7 +61,7 @@ impl HgDriver {
}
let sanitized =
- Preg::replace(r"{[^a-z0-9]}i", "-", &Url::sanitize(self.inner.url.clone()))?;
+ Preg::replace(r"{[^a-z0-9]}i", "-", &Url::sanitize(self.inner.url.clone()));
self.repo_dir = format!("{}/{}/", cache_vcs_dir, sanitized);
let mut fs = Filesystem::new(None);
@@ -244,7 +244,7 @@ impl HgDriver {
for tag in self.inner.process.borrow().split_lines(&output) {
if !tag.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"^([^\s]+)\s+\d+:(.*)$", &tag, Some(&mut m)).unwrap_or(false) {
+ if Preg::match3(r"^([^\s]+)\s+\d+:(.*)$", &tag, Some(&mut m)) {
tags.insert(
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default(),
@@ -274,9 +274,7 @@ impl HgDriver {
for branch in self.inner.process.borrow().split_lines(&output) {
if !branch.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"^([^\s]+)\s+\d+:([a-f0-9]+)", &branch, Some(&mut m))
- .unwrap_or(false)
- {
+ if Preg::match3(r"^([^\s]+)\s+\d+:([a-f0-9]+)", &branch, Some(&mut m)) {
let name = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
if !name.starts_with('-') {
branches.insert(
@@ -297,9 +295,7 @@ impl HgDriver {
for branch in self.inner.process.borrow().split_lines(&output) {
if !branch.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$", &branch, Some(&mut m))
- .unwrap_or(false)
- {
+ if Preg::match3(r"^(?:[\s*]*)([^\s]+)\s+\d+:(.*)$", &branch, Some(&mut m)) {
let name = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
if !name.starts_with('-') {
bookmarks.insert(
@@ -328,9 +324,7 @@ impl HgDriver {
if Preg::is_match(
r"#(^(?:https?|ssh)://(?:[^@]+@)?bitbucket.org|https://(?:.*?)\.kilnhg.com)#i",
url,
- )
- .unwrap_or(false)
- {
+ ) {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/perforce_driver.rs b/crates/shirabe/src/repository/vcs/perforce_driver.rs
index 65f2856..10cf913 100644
--- a/crates/shirabe/src/repository/vcs/perforce_driver.rs
+++ b/crates/shirabe/src/repository/vcs/perforce_driver.rs
@@ -188,7 +188,7 @@ impl PerforceDriver {
url: &str,
deep: bool,
) -> anyhow::Result<bool> {
- if deep || Preg::is_match(r"#\b(perforce|p4)\b#i", url).unwrap_or(false) {
+ if deep || Preg::is_match(r"#\b(perforce|p4)\b#i", url) {
return Ok(Perforce::check_server_exists(
url,
&mut ProcessExecutor::new(Some(io)),
diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs
index 71d8499..b48ce99 100644
--- a/crates/shirabe/src/repository/vcs/svn_driver.rs
+++ b/crates/shirabe/src/repository/vcs/svn_driver.rs
@@ -117,7 +117,7 @@ impl SvnDriver {
.get("cache-repo-dir")
.as_string()
.unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(self.base_url.clone()))?,
+ Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(self.base_url.clone())),
),
None,
None,
@@ -160,7 +160,7 @@ impl SvnDriver {
}
pub(crate) fn should_cache(&self, identifier: &str) -> bool {
- self.inner.cache.is_some() && Preg::is_match(r"{@\d+$}", identifier).unwrap_or(false)
+ self.inner.cache.is_some() && Preg::is_match(r"{@\d+$}", identifier)
}
pub fn get_composer_information(
@@ -263,7 +263,7 @@ impl SvnDriver {
pub fn get_file_content(&mut self, file: &str, identifier: &str) -> Result<Option<String>> {
let identifier = format!("/{}/", trim(identifier, Some("/")));
- let (path, rev) = if let Ok(Some(m)) =
+ let (path, rev) = if let Some(m) =
Preg::is_match_with_indexed_captures(r"{^(.+?)(@\d+)?/$}", &identifier)
{
if m.get(2).is_some() {
@@ -300,7 +300,7 @@ impl SvnDriver {
pub fn get_change_date(&mut self, identifier: &str) -> Result<Option<DateTime<FixedOffset>>> {
let identifier = format!("/{}/", trim(identifier, Some("/")));
- let (path, rev) = if let Ok(Some(m)) =
+ let (path, rev) = if let Some(m) =
Preg::is_match_with_indexed_captures(r"{^(.+?)(@\d+)?/$}", &identifier)
{
if m.get(2).is_some() {
@@ -322,9 +322,7 @@ impl SvnDriver {
for line in self.inner.process.borrow().split_lines(&output) {
if !line.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^Last Changed Date: ([^(]+)}", &line, Some(&mut m))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r"{^Last Changed Date: ([^(]+)}", &line, Some(&mut m)) {
let date_str = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
return Ok(shirabe_php_shim::date_create::<Utc>(date_str.trim())
.ok()
@@ -354,9 +352,7 @@ impl SvnDriver {
let line = trim(&line, None);
if !line.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^\s*(\S+).*?(\S+)\s*$}", &line, Some(&mut m))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r"{^\s*(\S+).*?(\S+)\s*$}", &line, Some(&mut m)) {
let rev: i64 = m
.get(&CaptureKey::ByIndex(1))
.and_then(|s| s.parse().ok())
@@ -405,9 +401,7 @@ impl SvnDriver {
let line = trim(&line, None);
if !line.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^\s*(\S+).*?(\S+)\s*$}", &line, Some(&mut m))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r"{^\s*(\S+).*?(\S+)\s*$}", &line, Some(&mut m)) {
let rev: i64 = m
.get(&CaptureKey::ByIndex(1))
.and_then(|s| s.parse().ok())
@@ -447,9 +441,7 @@ impl SvnDriver {
let line = trim(&line, None);
if !line.is_empty() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^\s*(\S+).*?(\S+)\s*$}", &line, Some(&mut m))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r"{^\s*(\S+).*?(\S+)\s*$}", &line, Some(&mut m)) {
let rev: i64 = m
.get(&CaptureKey::ByIndex(1))
.and_then(|s| s.parse().ok())
@@ -485,7 +477,7 @@ impl SvnDriver {
deep: bool,
) -> Result<bool> {
let url = Self::normalize_url(url);
- if Preg::is_match(r"#(^svn://|^svn\+ssh://|svn\.)#i", &url).unwrap_or(false) {
+ if Preg::is_match(r"#(^svn://|^svn\+ssh://|svn\.)#i", &url) {
return Ok(true);
}
diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs
index b197676..d1bb3cc 100644
--- a/crates/shirabe/src/repository/vcs/vcs_driver.rs
+++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs
@@ -58,7 +58,7 @@ impl VcsDriverBase {
}
pub fn should_cache(&self, identifier: &str) -> bool {
- self.cache.is_some() && Preg::is_match("{^[a-f0-9]{40}$}iD", identifier).unwrap_or(false)
+ self.cache.is_some() && Preg::is_match("{^[a-f0-9]{40}$}iD", identifier)
}
pub fn get_scheme(&self) -> &str {
@@ -207,7 +207,7 @@ pub trait VcsDriver: VcsDriverInterface {
fn cache_mut(&mut self) -> Option<&mut Cache>;
fn should_cache(&self, identifier: &str) -> bool {
- self.cache().is_some() && Preg::is_match("{^[a-f0-9]{40}$}iD", identifier).unwrap_or(false)
+ self.cache().is_some() && Preg::is_match("{^[a-f0-9]{40}$}iD", identifier)
}
fn get_composer_information(
diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs
index ef58fe2..ebab76f 100644
--- a/crates/shirabe/src/repository/vcs_repository.rs
+++ b/crates/shirabe/src/repository/vcs_repository.rs
@@ -443,7 +443,7 @@ impl VcsRepository {
data.get("version")
.and_then(|v| v.as_string())
.unwrap_or(""),
- )?),
+ )),
);
data.insert(
"version_normalized".to_string(),
@@ -453,7 +453,7 @@ impl VcsRepository {
data.get("version_normalized")
.and_then(|v| v.as_string())
.unwrap_or(""),
- )?),
+ )),
);
// make sure tag do not contain the default-branch marker
@@ -468,7 +468,7 @@ impl VcsRepository {
// broken package, version doesn't match tag
if version_normalized != parsed_tag {
if is_very_verbose {
- if Preg::is_match(r"{(^dev-|[.-]?dev$)}i", &parsed_tag).unwrap_or(false) {
+ if Preg::is_match(r"{(^dev-|[.-]?dev$)}i", &parsed_tag) {
self.io.write_error(&format!(
"<warning>Skipped tag {}, invalid tag name, tags can not use dev prefixes or suffixes</warning>",
tag
@@ -620,7 +620,7 @@ impl VcsRepository {
version = format!(
"{}{}",
prefix,
- Preg::replace(r"{(\.9{7})+}", ".x", &parsed_branch)?
+ Preg::replace(r"{(\.9{7})+}", ".x", &parsed_branch)
);
}
diff --git a/crates/shirabe/src/self_update/versions.rs b/crates/shirabe/src/self_update/versions.rs
index c8c3f54..d854050 100644
--- a/crates/shirabe/src/self_update/versions.rs
+++ b/crates/shirabe/src/self_update/versions.rs
@@ -94,7 +94,7 @@ impl Versions {
self.channel = Some(channel.clone());
// rewrite '2' and '1' channels to stable for future self-updates, but LTS ones like '2.2' remain pinned
- let stored_channel = if Preg::is_match(r"^\d+$", &channel)? {
+ let stored_channel = if Preg::is_match(r"^\d+$", &channel) {
"stable".to_string()
} else {
channel.clone()
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 8505081..d520270 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -529,7 +529,7 @@ impl AuthHelper {
}
} else if origin == "github.com" && password == "x-oauth-basic" {
// only add the access_token if it is actually a github API URL
- if Preg::is_match(r"{^https?://api\.github\.com/}", url)? {
+ if Preg::is_match(r"{^https?://api\.github\.com/}", url) {
headers.push(PhpMixed::String(format!(
"Authorization: token {}",
username,
diff --git a/crates/shirabe/src/util/composer_mirror.rs b/crates/shirabe/src/util/composer_mirror.rs
index 6f15a13..c0ff8d8 100644
--- a/crates/shirabe/src/util/composer_mirror.rs
+++ b/crates/shirabe/src/util/composer_mirror.rs
@@ -15,7 +15,7 @@ impl ComposerMirror {
pretty_version: Option<&str>,
) -> String {
let reference = reference.map(|r| {
- if Preg::is_match(r"^([a-f0-9]*|%reference%)$", r).unwrap_or(false) {
+ if Preg::is_match(r"^([a-f0-9]*|%reference%)$", r) {
r.to_string()
} else {
hash("md5", r)
@@ -59,9 +59,7 @@ impl ComposerMirror {
r"^(?:(?:https?|git)://github\.com/|git@github\.com:)([^/]+)/(.+?)(?:\.git)?$",
url,
Some(&mut gh_matches),
- )
- .unwrap_or(false)
- {
+ ) {
format!(
"gh-{}/{}",
gh_matches
@@ -77,9 +75,7 @@ impl ComposerMirror {
r"^https://bitbucket\.org/([^/]+)/(.+?)(?:\.git)?/?$",
url,
Some(&mut bb_matches),
- )
- .unwrap_or(false)
- {
+ ) {
format!(
"bb-{}/{}",
bb_matches
@@ -92,7 +88,7 @@ impl ComposerMirror {
.unwrap_or_default(),
)
} else {
- Preg::replace(r"[^a-z0-9_.-]", "-", url.trim_matches('/')).unwrap_or_default()
+ Preg::replace(r"[^a-z0-9_.-]", "-", url.trim_matches('/'))
};
["%package%", "%normalizedUrl%", "%type%"]
diff --git a/crates/shirabe/src/util/config_validator.rs b/crates/shirabe/src/util/config_validator.rs
index 5621841..90195e7 100644
--- a/crates/shirabe/src/util/config_validator.rs
+++ b/crates/shirabe/src/util/config_validator.rs
@@ -134,17 +134,13 @@ impl ConfigValidator {
_ => false,
};
if is_deprecated {
- if Preg::is_match(r"{^[AL]?GPL-[123](\.[01])?\+$}i", license)
- .unwrap_or(false)
- {
+ if Preg::is_match(r"{^[AL]?GPL-[123](\.[01])?\+$}i", license) {
warnings.push(format!(
"License \"{}\" is a deprecated SPDX license identifier, use \"{}-or-later\" instead",
license,
license.replace('+', "")
));
- } else if Preg::is_match(r"{^[AL]?GPL-[123](\.[01])?$}i", license)
- .unwrap_or(false)
- {
+ } else if Preg::is_match(r"{^[AL]?GPL-[123](\.[01])?$}i", license) {
warnings.push(format!(
"License \"{}\" is a deprecated SPDX license identifier, use \"{}-only\" or \"{}-or-later\" instead",
license, license, license
@@ -165,13 +161,12 @@ impl ConfigValidator {
}
if let Some(PhpMixed::String(name)) = manifest.get("name") {
- if !name.is_empty() && Preg::is_match(r"{[A-Z]}", name).unwrap_or(false) {
+ if !name.is_empty() && Preg::is_match(r"{[A-Z]}", name) {
let suggest_name = Preg::replace(
r"{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}",
r"\1\3-\2\4",
name,
- )
- .unwrap_or_else(|_| name.clone());
+ );
let suggest_name = suggest_name.to_lowercase();
publish_errors.push(format!(
@@ -242,7 +237,7 @@ impl ConfigValidator {
packages.extend(require_dev);
for (package, version) in &packages {
if let PhpMixed::String(version_str) = version.as_ref() {
- if Preg::is_match(r"{#}", version_str).unwrap_or(false) {
+ if Preg::is_match(r"{#}", version_str) {
warnings.push(format!(
"The package \"{}\" is pointing to a commit-ref, this is bad practice and can cause unforeseen issues.",
package
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index 15f970d..cb0e4a5 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -193,7 +193,7 @@ impl Filesystem {
return Ok(Some(true));
}
- if Preg::is_match3("{^(?:[a-z]:)?[/\\\\]+$}i", directory, None).unwrap_or(false) {
+ if Preg::is_match3("{^(?:[a-z]:)?[/\\\\]+$}i", directory, None) {
return Err(RuntimeException {
message: format!("Aborting an attempted deletion of {}, this was probably not intended, if it is a real use case please report it.", directory),
code: 0,
@@ -541,7 +541,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None).unwrap_or(false)
+ && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None)
{
common_path = strtr(&dirname(&common_path), "\\", "/");
}
@@ -602,7 +602,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None).unwrap_or(false)
+ && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None)
&& "." != common_path
{
common_path = strtr(&dirname(&common_path), "\\", "/");
@@ -705,9 +705,7 @@ impl Filesystem {
"{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix",
&path,
Some(&mut prefix_match),
- )
- .unwrap_or(false)
- {
+ ) {
prefix = prefix_match
.get(&shirabe_external_packages::composer::pcre::CaptureKey::ByIndex(1))
.cloned()
@@ -746,8 +744,7 @@ impl Filesystem {
strtoupper(&s)
},
&prefix,
- )
- .unwrap_or_default();
+ );
format!("{}{}{}", prefix, absolute, implode("/", &parts))
}
@@ -757,7 +754,7 @@ impl Filesystem {
/// And other possible unforeseen disasters, see https://github.com/composer/composer/pull/9422
pub fn trim_trailing_slash(path: &str) -> String {
let mut path = path.to_string();
- if !Preg::is_match3("{^[/\\\\]+$}", &path, None).unwrap_or(false) {
+ if !Preg::is_match3("{^[/\\\\]+$}", &path, None) {
path = rtrim(&path, Some("/\\"));
}
@@ -773,8 +770,7 @@ impl Filesystem {
"{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i",
path,
None,
- )
- .unwrap_or(false);
+ );
}
Preg::is_match3(
@@ -782,17 +778,15 @@ impl Filesystem {
path,
None,
)
- .unwrap_or(false)
}
pub fn get_platform_path(path: &str) -> String {
let mut path = path.to_string();
if Platform::is_windows() {
- path = Preg::replace("{^(?:file:///([a-z]):?/)}i", "file://$1:/", &path)
- .unwrap_or_default();
+ path = Preg::replace("{^(?:file:///([a-z]):?/)}i", "file://$1:/", &path);
}
- Preg::replace("{^file://}i", "", &path).unwrap_or_default()
+ Preg::replace("{^file://}i", "", &path)
}
/// Cross-platform safe version of is_readable()
diff --git a/crates/shirabe/src/util/forgejo_url.rs b/crates/shirabe/src/util/forgejo_url.rs
index 90a1424..85f2238 100644
--- a/crates/shirabe/src/util/forgejo_url.rs
+++ b/crates/shirabe/src/util/forgejo_url.rs
@@ -42,7 +42,7 @@ impl ForgejoUrl {
shirabe_external_packages::composer::pcre::CaptureKey,
String,
> = indexmap::IndexMap::new();
- if !Preg::match3(Self::URL_REGEX, repo_url, Some(&mut matches)).unwrap_or(false) {
+ if !Preg::match3(Self::URL_REGEX, repo_url, Some(&mut matches)) {
return None;
}
use shirabe_external_packages::composer::pcre::CaptureKey;
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index 35f4940..5916f9b 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -118,7 +118,7 @@ impl Git {
map.insert("%url%".to_string(), url.to_string());
map.insert(
"%sanitizedUrl%".to_string(),
- Preg::replace(r"{://([^@]+?):(.+?)@}", "://", &url).unwrap_or_default(),
+ Preg::replace(r"{://([^@]+?):(.+?)@}", "://", &url),
);
array_map(
@@ -207,7 +207,7 @@ impl Git {
status
};
- if Preg::is_match(r"{^ssh://[^@]+@[^:]+:[^0-9]+}", url).unwrap_or(false) {
+ if Preg::is_match(r"{^ssh://[^@]+@[^:]+:[^0-9]+}", url) {
return Err(InvalidArgumentException {
message: format!(
"The source URL {} is invalid, ssh URLs should have a port number after \":\".\nUse ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.",
@@ -231,9 +231,7 @@ impl Git {
r"{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)}im",
&output,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
let m3 = m.get(&CaptureKey::ByIndex(3)).cloned().unwrap_or_default();
if !self.io.has_authentication(&m3) {
self.io.borrow_mut().set_authentication(
@@ -258,9 +256,7 @@ impl Git {
),
url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
let mut messages: Vec<String> = vec![];
let protocols_list: Vec<String> = match &protocols {
PhpMixed::List(l) => l
@@ -295,7 +291,6 @@ impl Git {
" ",
&self.process.borrow().get_error_output().to_string()
)
- .unwrap_or_default()
));
if initial_clone {
@@ -334,18 +329,16 @@ impl Git {
Self::get_github_domains_regex(&*self.config.borrow())
),
url,
- )
- .unwrap_or(false)
- && !in_array(
- PhpMixed::String("ssh".to_string()),
- &PhpMixed::List(
- protocols_list
- .iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- ),
- true,
- );
+ ) && !in_array(
+ PhpMixed::String("ssh".to_string()),
+ &PhpMixed::List(
+ protocols_list
+ .iter()
+ .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .collect(),
+ ),
+ true,
+ );
let mut auth: Option<IndexMap<String, Option<String>>> = None;
let mut credentials: Vec<String> = vec![];
@@ -368,17 +361,14 @@ impl Git {
),
url,
Some(&mut m),
- )
- .unwrap_or(false)
- || Preg::is_match3(
- &format!(
- "{{^https?://{}/(.*?)(?:\\.git)?$}}i",
- Self::get_github_domains_regex(&*self.config.borrow())
- ),
- url,
- Some(&mut m),
- )
- .unwrap_or(false);
+ ) || Preg::is_match3(
+ &format!(
+ "{{^https?://{}/(.*?)(?:\\.git)?$}}i",
+ Self::get_github_domains_regex(&*self.config.borrow())
+ ),
+ url,
+ Some(&mut m),
+ );
if github_matched {
let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
let m2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default();
@@ -434,14 +424,11 @@ impl Git {
r"{^(https?)://(bitbucket\.org)/(.*?)(?:\.git)?$}i",
url,
Some(&mut m),
- )
- .unwrap_or(false)
- || Preg::is_match3(
- r"{^(git)@(bitbucket\.org):(.+?\.git)$}i",
- url,
- Some(&mut m),
- )
- .unwrap_or(false);
+ ) || Preg::is_match3(
+ r"{^(git)@(bitbucket\.org):(.+?\.git)$}i",
+ url,
+ Some(&mut m),
+ );
bb_matched
} {
// bitbucket either through oauth or app password, with fallback to ssh.
@@ -589,17 +576,14 @@ impl Git {
),
url,
Some(&mut m),
- )
- .unwrap_or(false)
- || Preg::is_match3(
- &format!(
- "{{^(https?)://{}/(.*)}}i",
- Self::get_gitlab_domains_regex(&*self.config.borrow())
- ),
- url,
- Some(&mut m),
- )
- .unwrap_or(false);
+ ) || Preg::is_match3(
+ &format!(
+ "{{^(https?)://{}/(.*)}}i",
+ Self::get_gitlab_domains_regex(&*self.config.borrow())
+ ),
+ url,
+ Some(&mut m),
+ );
gl_matched
} {
let mut m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
@@ -947,11 +931,9 @@ impl Git {
pretty_version: Option<&str>,
) -> Result<bool> {
if self.check_ref_is_in_mirror(dir, r#ref)? {
- if Preg::is_match(r"{^[a-f0-9]{40}$}", r#ref).unwrap_or(false)
- && pretty_version.is_some()
- {
+ if Preg::is_match(r"{^[a-f0-9]{40}$}", r#ref) && pretty_version.is_some() {
let branch =
- Preg::replace(r"{(?:^dev-|(?:\.x)?-dev$)}i", "", &pretty_version.unwrap())?;
+ Preg::replace(r"{(?:^dev-|(?:\.x)?-dev$)}i", "", &pretty_version.unwrap());
let mut branches: Option<String> = None;
let mut tags: Option<String> = None;
let mut output = String::new();
@@ -982,13 +964,11 @@ impl Git {
&format!(r"{{^[\s*]*v?{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
)
- .unwrap_or(false)
&& tags.is_some()
&& !Preg::is_match(
&format!(r"{{^[\s*]*{}$}}m", preg_quote(&branch, None)),
tags.as_deref().unwrap_or(""),
)
- .unwrap_or(false)
{
self.sync_mirror(url, dir)?;
}
@@ -1076,7 +1056,7 @@ impl Git {
}
// Filter out "commit <hash>" lines for older git versions
- Preg::replace(r"{^commit [a-f0-9]{40}\n?}m", "", output).unwrap_or_default()
+ 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> {
@@ -1117,7 +1097,7 @@ impl Git {
/// @return array<int, string>|null
fn get_authentication_failure(&self, url: &str) -> Option<IndexMap<CaptureKey, String>> {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if !Preg::is_match3(r"{^(https?://)([^/]+)(.*)$}i", url, Some(&mut m)).unwrap_or(false) {
+ if !Preg::is_match3(r"{^(https?://)([^/]+)(.*)$}i", url, Some(&mut m)) {
return None;
}
@@ -1202,9 +1182,7 @@ impl Git {
.split_lines(output_mixed.as_string().unwrap_or(""));
for line in lines {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^\s*HEAD branch:\s(.+)\s*$}m", &line, Some(&mut matches))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r"{^\s*HEAD branch:\s(.+)\s*$}m", &line, Some(&mut matches)) {
return Ok(Some(
matches
.get(&CaptureKey::ByIndex(1))
@@ -1345,9 +1323,7 @@ impl Git {
r"/^git version (\d+(?:\.\d+)+)/m",
&output,
Some(&mut matches),
- )
- .unwrap_or(false)
- {
+ ) {
*version = Some(matches.get(&CaptureKey::ByIndex(1)).cloned());
}
}
diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs
index 1cd78c1..766d75b 100644
--- a/crates/shirabe/src/util/github.rs
+++ b/crates/shirabe/src/util/github.rs
@@ -333,7 +333,7 @@ impl GitHub {
continue;
}
let mut caps: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::match3(r"{\burl=(?P<url>[^\s;]+)}", header, Some(&mut caps)).unwrap_or(false) {
+ if Preg::match3(r"{\burl=(?P<url>[^\s;]+)}", header, Some(&mut caps)) {
return caps.get(&CaptureKey::ByName("url".to_string())).cloned();
}
}
@@ -343,7 +343,7 @@ impl GitHub {
pub fn is_rate_limited(&self, headers: &[String]) -> bool {
for header in headers {
- if Preg::is_match(r"{^x-ratelimit-remaining: *0$}i", header.trim()).unwrap_or(false) {
+ if Preg::is_match(r"{^x-ratelimit-remaining: *0$}i", header.trim()) {
return true;
}
}
@@ -353,7 +353,7 @@ impl GitHub {
pub fn requires_sso(&self, headers: &[String]) -> bool {
for header in headers {
- if Preg::is_match(r"{^x-github-sso: required}i", header.trim()).unwrap_or(false) {
+ if Preg::is_match(r"{^x-github-sso: required}i", header.trim()) {
return true;
}
}
diff --git a/crates/shirabe/src/util/gitlab.rs b/crates/shirabe/src/util/gitlab.rs
index d42f1cf..3938a07 100644
--- a/crates/shirabe/src/util/gitlab.rs
+++ b/crates/shirabe/src/util/gitlab.rs
@@ -51,8 +51,7 @@ impl GitLab {
pub fn authorize_oauth(&mut self, origin_url: &str) -> bool {
// before composer 1.9, origin URLs had no port number in them
- let bc_origin_url =
- Preg::replace("{:\\d+}", "", origin_url).unwrap_or_else(|_| origin_url.to_string());
+ let bc_origin_url = Preg::replace("{:\\d+}", "", origin_url);
let gitlab_domains = self.config.borrow_mut().get("gitlab-domains");
let domains = match gitlab_domains.as_array() {
diff --git a/crates/shirabe/src/util/hg.rs b/crates/shirabe/src/util/hg.rs
index f5ee256..c8f5489 100644
--- a/crates/shirabe/src/util/hg.rs
+++ b/crates/shirabe/src/util/hg.rs
@@ -58,7 +58,7 @@ impl Hg {
r"(?i)^(?P<proto>ssh|https?)://(?:(?P<user>[^:@]+)(?::(?P<pass>[^:@]+))?@)?(?P<host>[^/]+)(?P<path>/.*)?",
&url,
&mut matches,
- )?;
+ );
if matched {
if self
@@ -151,7 +151,7 @@ impl Hg {
(),
) == 0
{
- if let Ok(Some(matches)) = Preg::is_match_with_indexed_captures(
+ if let Some(matches) = Preg::is_match_with_indexed_captures(
r"/^.+? (\d+(?:\.\d+)+)(?:\+.*?)?\)?\r?\n/",
&output,
) {
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index 37993f9..98f874a 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -333,7 +333,7 @@ impl CurlDownloader {
let original_options = options.clone();
// check URL can be accessed (i.e. is not insecure), but allow insecure Packagist calls to $hashed providers as file integrity is verified with sha256
- if !Preg::is_match(r"{^http://(repo\.)?packagist\.org/p/}", url).unwrap_or(false)
+ if !Preg::is_match(r"{^http://(repo\.)?packagist\.org/p/}", url)
|| (strpos(url, "$").is_none() && strpos(url, "%24").is_none())
{
self.config.borrow_mut().prohibit_url_by_config(
@@ -1582,7 +1582,7 @@ impl CurlDownloader {
),
&format!("\\1{}", location_header),
job_url,
- )?;
+ );
} else {
// Relative path; e.g. foo
// This actually differs from PHP which seems to add duplicate slashes.
@@ -1591,7 +1591,7 @@ impl CurlDownloader {
r"{^(.+/)[^/?]*(?:\?.*)?$}",
&format!("\\1{}", location_header),
job_url,
- )?;
+ );
}
}
}
@@ -1690,7 +1690,7 @@ impl CurlDownloader {
.inner
.get_header("content-type")
.unwrap_or_default(),
- )?
+ )
{
needs_auth_retry = Some("Bitbucket requires authentication and it was not provided");
}
diff --git a/crates/shirabe/src/util/http/response.rs b/crates/shirabe/src/util/http/response.rs
index 4810397..ad55fa2 100644
--- a/crates/shirabe/src/util/http/response.rs
+++ b/crates/shirabe/src/util/http/response.rs
@@ -29,7 +29,7 @@ impl Response {
pub fn get_status_message(&self) -> Option<String> {
let mut value = None;
for header in &self.headers {
- if Preg::is_match(r"(?i)^HTTP/\S+ \d+", header).unwrap_or(false) {
+ if Preg::is_match(r"(?i)^HTTP/\S+ \d+", header) {
// In case of redirects, headers contain the headers of all responses
// so we can not return directly and need to keep iterating
value = Some(header.clone());
@@ -69,7 +69,7 @@ impl Response {
shirabe_external_packages::composer::pcre::CaptureKey,
String,
> = indexmap::IndexMap::new();
- if Preg::match3(&pattern, header, Some(&mut matches)).unwrap_or(false) {
+ if Preg::match3(&pattern, header, Some(&mut matches)) {
if let Some(s) =
matches.get(&shirabe_external_packages::composer::pcre::CaptureKey::ByIndex(1))
{
diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs
index b1da08f..9279518 100644
--- a/crates/shirabe/src/util/http_downloader.rs
+++ b/crates/shirabe/src/util/http_downloader.rs
@@ -314,9 +314,7 @@ impl HttpDownloader {
r"{^https?://([^:/]+):([^@/]+)@([^/]+)}i",
&request.url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
self.io.borrow_mut().set_authentication(
origin.clone(),
rawurldecode(
@@ -664,7 +662,11 @@ impl HttpDownloader {
) -> Result<()> {
let clean_message = |msg: &str| -> anyhow::Result<String> {
if !io.is_decorated() {
- return Preg::replace(&format!("{{{}{}}}u", chr(27), "\\[[;\\d]*m"), "", msg);
+ return Ok(Preg::replace(
+ &format!("{{{}{}}}u", chr(27), "\\[[;\\d]*m"),
+ "",
+ msg,
+ ));
}
Ok(msg.to_string())
@@ -804,7 +806,7 @@ impl HttpDownloader {
return false;
}
- if !Preg::is_match(r"{^https?://}i", &job.request.url).unwrap_or(false) {
+ if !Preg::is_match(r"{^https?://}i", &job.request.url) {
return false;
}
diff --git a/crates/shirabe/src/util/no_proxy_pattern.rs b/crates/shirabe/src/util/no_proxy_pattern.rs
index dbca5d7..512b881 100644
--- a/crates/shirabe/src/util/no_proxy_pattern.rs
+++ b/crates/shirabe/src/util/no_proxy_pattern.rs
@@ -40,7 +40,7 @@ impl NoProxyPattern {
/// @param string $pattern NO_PROXY pattern
pub fn new(pattern: &str) -> Self {
// PHP: Preg::split('{[\s,]+}', $pattern, -1, PREG_SPLIT_NO_EMPTY)
- let host_names = Preg::split(r"{[\s,]+}", pattern).unwrap_or_default();
+ let host_names = Preg::split(r"{[\s,]+}", pattern);
let noproxy = host_names.is_empty() || host_names[0] == "*";
Self {
host_names,
diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs
index 2a17fa9..1f64dcc 100644
--- a/crates/shirabe/src/util/perforce.rs
+++ b/crates/shirabe/src/util/perforce.rs
@@ -693,8 +693,7 @@ impl Perforce {
r"/[^A-Za-z0-9 ]/",
"",
&res_bits.get(4).cloned().unwrap_or_default(),
- )
- .unwrap_or_default();
+ );
possible_branches.insert(branch, res_bits.get(1).cloned().unwrap_or_default());
}
}
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs
index 5155e8f..797bac2 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -93,7 +93,7 @@ impl Platform {
/// Parses tildes and environment variables in paths.
pub fn expand_path(path: &str) -> String {
use shirabe_external_packages::composer::pcre::CaptureKey;
- if Preg::is_match(r"#^~[\\/]#", path).unwrap_or(false) {
+ if Preg::is_match(r"#^~[\\/]#", path) {
return format!(
"{}{}",
Self::get_user_directory().unwrap(),
@@ -137,7 +137,6 @@ impl Platform {
},
path,
)
- .unwrap_or_default()
}
/// @throws \RuntimeException If the user home could not reliably be determined
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index a681f2c..42bd0c8 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -206,8 +206,7 @@ impl ProcessExecutor {
let mut command_str = command.as_string().unwrap_or("").to_string();
if Platform::is_windows() {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{^([^:/\\]++) }", &command_str, Some(&mut m)).unwrap_or(false)
- {
+ if Preg::is_match3(r"{^([^:/\\]++) }", &command_str, Some(&mut m)) {
let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
command_str = substr_replace(
&command_str,
@@ -647,7 +646,7 @@ impl ProcessExecutor {
if output.is_empty() {
vec![]
} else {
- Preg::split(r"{\r?\n}", &output).unwrap_or_default()
+ Preg::split(r"{\r?\n}", &output)
}
}
@@ -696,31 +695,25 @@ impl ProcessExecutor {
if Preg::is_match(
GitHub::GITHUB_TOKEN_REGEX,
m.get(&user_key).cloned().unwrap_or_default().as_str(),
- )
- .unwrap_or(false)
- {
+ ) {
return "://***:***@".to_string();
}
if Preg::is_match(
r"{^[a-f0-9]{12,}$}",
m.get(&user_key).cloned().unwrap_or_default().as_str(),
- )
- .unwrap_or(false)
- {
+ ) {
return "://***:***@".to_string();
}
format!("://{}:***@", m.get(&user_key).cloned().unwrap_or_default())
},
&command_string,
- )
- .unwrap_or_default();
+ );
let safe_command = Preg::replace(
r"{--password (.*[^\\]') }",
"--password '***' ",
&safe_command,
- )
- .unwrap_or_default();
+ );
self.io.as_ref().unwrap().write_error(&format!(
"Executing{} command ({}): {}",
if r#async { " async" } else { "" },
@@ -763,24 +756,20 @@ impl ProcessExecutor {
let mut quote = strpbrk(&argument, " \t,").is_some();
let mut dquotes: usize = 0;
// PHP: Preg::replace('/(\\\\*)"/', '$1$1\\"', $argument, -1, $dquotes)
- argument = Preg::replace5(r#"/(\\*)"/"#, r#"$1$1\""#, &argument, -1, &mut dquotes)
- .unwrap_or_default();
- let meta = dquotes > 0 || Preg::is_match(r"/%[^%]+%|![^!]+!/", &argument).unwrap_or(false);
+ argument = Preg::replace5(r#"/(\\*)"/"#, r#"$1$1\""#, &argument, -1, &mut dquotes);
+ let meta = dquotes > 0 || Preg::is_match(r"/%[^%]+%|![^!]+!/", &argument);
if !meta && !quote {
quote = strpbrk(&argument, "^&|<>()").is_some();
}
if quote {
- argument = format!(
- "\"{}\"",
- Preg::replace(r"/(\\*)$/", "$1$1", &argument).unwrap_or_default()
- );
+ argument = format!("\"{}\"", Preg::replace(r"/(\\*)$/", "$1$1", &argument));
}
if meta {
- argument = Preg::replace(r#"/(["^&|<>()%])/"#, "^$1", &argument).unwrap_or_default();
- argument = Preg::replace(r"/(!)/", "^^$1", &argument).unwrap_or_default();
+ argument = Preg::replace(r#"/(["^&|<>()%])/"#, "^$1", &argument);
+ argument = Preg::replace(r"/(!)/", "^^$1", &argument);
}
argument
diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs
index a75f947..80b2617 100644
--- a/crates/shirabe/src/util/remote_filesystem.rs
+++ b/crates/shirabe/src/util/remote_filesystem.rs
@@ -145,7 +145,7 @@ impl RemoteFilesystem {
let mut value: Option<i64> = None;
for header in headers {
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3("{^HTTP/\\S+ (\\d+)}i", header, Some(&mut m)).unwrap_or(false) {
+ if Preg::is_match3("{^HTTP/\\S+ (\\d+)}i", header, Some(&mut m)) {
value = m
.get(&CaptureKey::ByIndex(1))
.and_then(|s| s.parse().ok())
@@ -159,7 +159,7 @@ impl RemoteFilesystem {
pub fn find_status_message(&self, headers: &[String]) -> Option<String> {
let mut value: Option<String> = None;
for header in headers {
- if Preg::is_match("{^HTTP/\\S+ \\d+}i", header).unwrap_or(false) {
+ if Preg::is_match("{^HTTP/\\S+ \\d+}i", header) {
value = Some(header.clone());
}
}
@@ -283,7 +283,7 @@ impl RemoteFilesystem {
crate::io::DEBUG,
);
- if (!Preg::is_match("{^http://(repo\\.)?packagist\\.org/p/}", &file_url).unwrap_or(false)
+ if (!Preg::is_match("{^http://(repo\\.)?packagist\\.org/p/}", &file_url)
|| (strpos(&file_url, "$").is_none() && strpos(&file_url, "%24").is_none()))
&& !degraded_packagist
{
@@ -473,8 +473,7 @@ impl RemoteFilesystem {
None,
) != ".zip")
&& content_type.is_some()
- && Preg::is_match("{^text/html\\b}i", content_type.as_deref().unwrap_or(""))
- .unwrap_or(false);
+ && Preg::is_match("{^text/html\\b}i", content_type.as_deref().unwrap_or(""));
if bitbucket_login_match {
result = None;
if retry_auth_failure {
@@ -941,26 +940,20 @@ impl RemoteFilesystem {
.unwrap_or("")
.to_string();
- target_url = Some(
- Preg::replace(
- &format!(
- "{{^(.+(?://|@){}(?::\\d+)?)(?:[/\\?].*)?$}}",
- preg_quote(&url_host, None)
- ),
- &format!("\\1{}", location_header),
- &self.file_url,
- )
- .unwrap_or_else(|_| self.file_url.clone()),
- );
+ target_url = Some(Preg::replace(
+ &format!(
+ "{{^(.+(?://|@){}(?::\\d+)?)(?:[/\\?].*)?$}}",
+ preg_quote(&url_host, None)
+ ),
+ &format!("\\1{}", location_header),
+ &self.file_url,
+ ));
} else {
- target_url = Some(
- Preg::replace(
- "{^(.+/)[^/?]*(?:\\?.*)?$}",
- &format!("\\1{}", location_header),
- &self.file_url,
- )
- .unwrap_or_else(|_| self.file_url.clone()),
- );
+ target_url = Some(Preg::replace(
+ "{^(.+/)[^/?]*(?:\\?.*)?$}",
+ &format!("\\1{}", location_header),
+ &self.file_url,
+ ));
}
}
diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs
index 8453a43..181fccf 100644
--- a/crates/shirabe/src/util/svn.rs
+++ b/crates/shirabe/src/util/svn.rs
@@ -443,9 +443,7 @@ impl Svn {
(),
) {
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"{(\d+(?:\.\d+)+)}", &output, Some(&mut matches))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r"{(\d+(?:\.\d+)+)}", &output, Some(&mut matches)) {
*cached = Some(
matches
.get(&CaptureKey::ByIndex(1))
diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs
index 8bcd73e..064c850 100644
--- a/crates/shirabe/src/util/url.rs
+++ b/crates/shirabe/src/util/url.rs
@@ -21,9 +21,7 @@ impl Url {
r"(?i)^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$",
&url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
url = format!(
"https://api.github.com/repos/{}/{}/{}ball/{}",
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
@@ -35,9 +33,7 @@ impl Url {
r"(?i)^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/archive/.+\.(zip|tar)(?:\.gz)?$",
&url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
url = format!(
"https://api.github.com/repos/{}/{}/{}ball/{}",
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
@@ -49,9 +45,7 @@ impl Url {
r"(?i)^https?://api\.github\.com/repos/([^/]+)/([^/]+)/(zip|tar)ball(?:/.+)?$",
&url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
url = format!(
"https://api.github.com/repos/{}/{}/{}ball/{}",
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
@@ -66,9 +60,7 @@ impl Url {
r"(?i)^https?://(?:www\.)?bitbucket\.org/([^/]+)/([^/]+)/get/(.+)\.(zip|tar\.gz|tar\.bz2)$",
&url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
url = format!(
"https://bitbucket.org/{}/{}/get/{}.{}",
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
@@ -83,9 +75,7 @@ impl Url {
r"(?i)^https?://(?:www\.)?gitlab\.com/api/v[34]/projects/([^/]+)/repository/archive\.(zip|tar\.gz|tar\.bz2|tar)\?sha=.+$",
&url,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
url = format!(
"https://gitlab.com/api/v4/projects/{}/repository/archive.{}?sha={}",
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
@@ -102,8 +92,7 @@ impl Url {
r"(?i)(/repos/[^/]+/[^/]+/(zip|tar)ball)(?:/.+)?$",
&format!("$1/{}", r#ref),
&url,
- )
- .unwrap_or(url);
+ );
} else if in_array(
PhpMixed::String(host.clone()),
&config.get("gitlab-domains"),
@@ -113,8 +102,7 @@ impl Url {
r"(?i)(/api/v[34]/projects/[^/]+/repository/archive\.(?:zip|tar\.gz|tar\.bz2|tar)\?sha=).+$",
&format!("${{1}}{}", r#ref),
&url,
- )
- .unwrap_or(url);
+ );
}
assert!(!url.is_empty());
@@ -176,7 +164,7 @@ impl Url {
pub fn sanitize(url: String) -> String {
// GitHub repository rename result in redirect locations containing the access_token as GET parameter
// e.g. https://api.github.com/repositories/9999999999?access_token=github_token
- let url = Preg::replace(r"([&?]access_token=)[^&]+", "$1***", &url).unwrap_or(url);
+ let url = Preg::replace(r"([&?]access_token=)[^&]+", "$1***", &url);
let url = Preg::replace_callback(
r"(?i)^(?P<prefix>[a-z0-9]+://)?(?P<user>[^:/\s@]+):(?P<password>[^@\s/]+)@",
@@ -190,15 +178,14 @@ impl Url {
.cloned()
.unwrap_or_default();
// if the username looks like a long (12char+) hex string, or a modern github token (e.g. ghp_xxx, github_pat_xxx) we obfuscate that
- if Preg::is_match(GitHub::GITHUB_TOKEN_REGEX, &user).unwrap_or(false) {
+ if Preg::is_match(GitHub::GITHUB_TOKEN_REGEX, &user) {
format!("{}***:***@", prefix)
} else {
format!("{}{}:***@", prefix, user)
}
},
&url,
- )
- .unwrap_or(url);
+ );
url
}