aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-17 14:33:13 +0900
committernsfisis <nsfisis@gmail.com>2026-05-17 14:38:16 +0900
commit3e21569688cf0c8a1918c73ff96cb1b3aeffe0b3 (patch)
tree712ae7832124da20739f5b389cebe4f44abd7225 /crates/shirabe/src/util
parentac59538140a93d9a023da2115148bc9779223978 (diff)
downloadphp-shirabe-3e21569688cf0c8a1918c73ff96cb1b3aeffe0b3.tar.gz
php-shirabe-3e21569688cf0c8a1918c73ff96cb1b3aeffe0b3.tar.zst
php-shirabe-3e21569688cf0c8a1918c73ff96cb1b3aeffe0b3.zip
fix(compile): extract constants from traits to make them dyn-compatible
Diffstat (limited to 'crates/shirabe/src/util')
-rw-r--r--crates/shirabe/src/util/auth_helper.rs7
-rw-r--r--crates/shirabe/src/util/bitbucket.rs45
-rw-r--r--crates/shirabe/src/util/forgejo.rs21
-rw-r--r--crates/shirabe/src/util/git.rs15
-rw-r--r--crates/shirabe/src/util/github.rs28
-rw-r--r--crates/shirabe/src/util/gitlab.rs44
-rw-r--r--crates/shirabe/src/util/process_executor.rs5
-rw-r--r--crates/shirabe/src/util/svn.rs5
8 files changed, 95 insertions, 75 deletions
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 98c2471..33d0b54 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -1,5 +1,6 @@
//! ref: composer/src/Composer/Util/AuthHelper.php
+use crate::io::io_interface;
use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::preg::Preg;
@@ -157,7 +158,7 @@ impl AuthHelper {
sso_url,
);
self.io
- .write_error(PhpMixed::String(message), true, IOInterface::NORMAL);
+ .write_error(PhpMixed::String(message), true, io_interface::NORMAL);
if !self.io.is_interactive() {
return Err(TransportException::new(
format!("Could not authenticate against {}", origin),
@@ -448,7 +449,7 @@ impl AuthHelper {
origin,
)),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
let username = self.io.ask(" Username: ".to_string(), PhpMixed::Null);
let password = self.io.ask_and_hide_answer(" Password: ".to_string());
@@ -671,7 +672,7 @@ impl AuthHelper {
self.io.write_error(
PhpMixed::String(display_message.clone()),
true,
- IOInterface::DEBUG,
+ io_interface::DEBUG,
);
self.displayed_origin_authentications
.insert(origin.to_string(), display_message.clone());
diff --git a/crates/shirabe/src/util/bitbucket.rs b/crates/shirabe/src/util/bitbucket.rs
index fd7aafc..c6aa874 100644
--- a/crates/shirabe/src/util/bitbucket.rs
+++ b/crates/shirabe/src/util/bitbucket.rs
@@ -1,5 +1,6 @@
//! ref: composer/src/Composer/Util/Bitbucket.php
+use crate::io::io_interface;
use indexmap::IndexMap;
use shirabe_php_shim::{LogicException, PhpMixed, time};
@@ -117,33 +118,33 @@ impl Bitbucket {
"<error>Invalid OAuth consumer provided.</error>".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String("This can have three reasons:".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(
"1. You are authenticating with a bitbucket username/password combination".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(
"2. You are using an OAuth consumer, but didn't configure a (dummy) callback url".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(
"3. You are using an OAuth consumer, but didn't configure it as private consumer".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
return Ok(false);
}
@@ -153,14 +154,14 @@ impl Bitbucket {
"<error>Invalid OAuth consumer provided.</error>".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(
"You can also add it manually later by using \"composer config --global --auth bitbucket-oauth.bitbucket.org <consumer-key> <consumer-secret>\"".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
return Ok(false);
}
@@ -203,8 +204,11 @@ impl Bitbucket {
message: Option<&str>,
) -> anyhow::Result<bool> {
if let Some(msg) = message {
- self.io
- .write_error(PhpMixed::String(msg.to_string()), true, IOInterface::NORMAL);
+ self.io.write_error(
+ PhpMixed::String(msg.to_string()),
+ true,
+ io_interface::NORMAL,
+ );
}
let local_auth_config = self.config.get_local_auth_config_source();
@@ -213,10 +217,13 @@ impl Bitbucket {
self.io.write_error(
PhpMixed::String("Follow the instructions here:".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
+ );
+ self.io.write_error(
+ PhpMixed::String(url.to_string()),
+ true,
+ io_interface::NORMAL,
);
- self.io
- .write_error(PhpMixed::String(url.to_string()), true, IOInterface::NORMAL);
let auth_config_source_name = self.config.get_auth_config_source().get_name();
let local_name_prefix = local_auth_config
.as_ref()
@@ -228,14 +235,14 @@ impl Bitbucket {
local_name_prefix + &auth_config_source_name
)),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(
"Ensure you enter a \"Callback URL\" (http://example.com is fine) or it will not be possible to create an Access Token (this callback url will not be used by composer)".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
let mut store_in_local_auth_config = false;
@@ -258,14 +265,14 @@ impl Bitbucket {
self.io.write_error(
PhpMixed::String("<warning>No consumer key given, aborting.</warning>".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(
"You can also add it manually later by using \"composer config --global --auth bitbucket-oauth.bitbucket.org <consumer-key> <consumer-secret>\"".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
return Ok(false);
}
@@ -283,14 +290,14 @@ impl Bitbucket {
"<warning>No consumer secret given, aborting.</warning>".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(
"You can also add it manually later by using \"composer config --global --auth bitbucket-oauth.bitbucket.org <consumer-key> <consumer-secret>\"".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
return Ok(false);
}
@@ -332,7 +339,7 @@ impl Bitbucket {
self.io.write_error(
PhpMixed::String("<info>Consumer stored successfully.</info>".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
Ok(true)
diff --git a/crates/shirabe/src/util/forgejo.rs b/crates/shirabe/src/util/forgejo.rs
index 7f62fb9..15081fc 100644
--- a/crates/shirabe/src/util/forgejo.rs
+++ b/crates/shirabe/src/util/forgejo.rs
@@ -2,6 +2,7 @@
use crate::config::Config;
use crate::downloader::transport_exception::TransportException;
+use crate::io::io_interface;
use crate::io::io_interface::IOInterface;
use crate::util::http_downloader::HttpDownloader;
@@ -28,16 +29,16 @@ impl Forgejo {
message: Option<&str>,
) -> anyhow::Result<Result<bool, TransportException>> {
if let Some(message) = message {
- self.io.write_error(message, true, IOInterface::NORMAL);
+ self.io.write_error(message, true, io_interface::NORMAL);
}
let url = format!("https://{}/user/settings/applications", origin_url);
self.io.write_error(
"Setup a personal access token with repository:read permissions on:",
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
- self.io.write_error(&url, true, IOInterface::NORMAL);
+ self.io.write_error(&url, true, io_interface::NORMAL);
let local_auth_config = self.config.get_local_auth_config_source();
self.io.write_error(
&format!(
@@ -49,12 +50,12 @@ impl Forgejo {
+ self.config.get_auth_config_source().get_name()
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
"For additional information, check https://getcomposer.org/doc/articles/authentication-for-private-packages.md#forgejo-token",
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
let mut store_in_local_auth_config = false;
@@ -80,10 +81,10 @@ impl Forgejo {
self.io.write_error(
"<warning>No username/token given, aborting.</warning>",
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io
- .write_error(&add_token_manually, true, IOInterface::NORMAL);
+ .write_error(&add_token_manually, true, io_interface::NORMAL);
return Ok(Ok(false));
}
@@ -103,10 +104,10 @@ impl Forgejo {
self.io.write_error(
"<error>Invalid access token provided.</error>",
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io
- .write_error(&add_token_manually, true, IOInterface::NORMAL);
+ .write_error(&add_token_manually, true, io_interface::NORMAL);
return Ok(Ok(false));
}
@@ -138,7 +139,7 @@ impl Forgejo {
self.io.write_error(
"<info>Token stored successfully.</info>",
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
Ok(Ok(true))
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index 62d1e0e..8fe66a4 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -1,5 +1,6 @@
//! ref: composer/src/Composer/Util/Git.php
+use crate::io::io_interface;
use anyhow::Result;
use indexmap::IndexMap;
use std::sync::Mutex;
@@ -75,7 +76,7 @@ impl Git {
io.write_error(
PhpMixed::String(format!("<warning>{}</warning>", msg)),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
}
}
@@ -540,7 +541,7 @@ impl Git {
.to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
if run_commands_inline(
&ssh_url,
@@ -679,12 +680,12 @@ impl Git {
m2
)),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(format!("<warning>{}</warning>", trim(&error_msg, None))),
true,
- IOInterface::VERBOSE,
+ io_interface::VERBOSE,
);
let mut auth_map: IndexMap<String, Option<String>> = IndexMap::new();
auth_map.insert(
@@ -792,7 +793,7 @@ impl Git {
url
)),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
return Ok(false);
@@ -857,7 +858,7 @@ impl Git {
self.io.write_error(
PhpMixed::String(format!("<error>Sync mirror failed: {}</error>", e)),
true,
- IOInterface::DEBUG,
+ io_interface::DEBUG,
);
return Ok(false);
@@ -1173,7 +1174,7 @@ impl Git {
e
)),
true,
- IOInterface::DEBUG,
+ io_interface::DEBUG,
);
None
}
diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs
index 9911084..c04873f 100644
--- a/crates/shirabe/src/util/github.rs
+++ b/crates/shirabe/src/util/github.rs
@@ -1,5 +1,6 @@
//! ref: composer/src/Composer/Util/GitHub.php
+use crate::io::io_interface;
use shirabe_external_packages::composer::pcre::preg::Preg;
use shirabe_php_shim::{PhpMixed, date, stripos, strtolower};
@@ -80,8 +81,11 @@ impl GitHub {
message: Option<&str>,
) -> anyhow::Result<bool> {
if let Some(msg) = message {
- self.io
- .write_error(PhpMixed::String(msg.to_string()), true, IOInterface::NORMAL);
+ self.io.write_error(
+ PhpMixed::String(msg.to_string()),
+ true,
+ io_interface::NORMAL,
+ );
}
let mut note = "Composer".to_string();
@@ -127,7 +131,7 @@ impl GitHub {
Box::new(PhpMixed::String(String::new())),
]),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
let encoded_note = shirabe_php_shim::rawurlencode(&note).replace("%20", "+");
@@ -149,7 +153,7 @@ impl GitHub {
Box::new(PhpMixed::String(String::new())),
]),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
@@ -170,7 +174,7 @@ impl GitHub {
Box::new(PhpMixed::String(String::new())),
]),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
@@ -194,7 +198,7 @@ impl GitHub {
Box::new(PhpMixed::String(String::new())),
]),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
@@ -202,7 +206,7 @@ impl GitHub {
"For additional information, check https://getcomposer.org/doc/articles/authentication-for-private-packages.md#github-oauth".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
let mut store_in_local_auth_config = false;
@@ -225,14 +229,14 @@ impl GitHub {
self.io.write_error(
PhpMixed::String("<warning>No token given, aborting.</warning>".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(
"You can also add it manually later by using \"composer config --global --auth github-oauth.github.com <token>\"".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
return Ok(false);
}
@@ -266,14 +270,14 @@ impl GitHub {
self.io.write_error(
PhpMixed::String("<error>Invalid token provided.</error>".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(
"You can also add it manually later by using \"composer config --global --auth github-oauth.github.com <token>\"".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
return Ok(false);
}
@@ -307,7 +311,7 @@ impl GitHub {
self.io.write_error(
PhpMixed::String("<info>Token stored successfully.</info>".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
Ok(true)
diff --git a/crates/shirabe/src/util/gitlab.rs b/crates/shirabe/src/util/gitlab.rs
index 054dc9a..7788ed8 100644
--- a/crates/shirabe/src/util/gitlab.rs
+++ b/crates/shirabe/src/util/gitlab.rs
@@ -1,5 +1,6 @@
//! ref: composer/src/Composer/Util/GitLab.php
+use crate::io::io_interface;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::preg::Preg;
use shirabe_php_shim::{PhpMixed, RuntimeException, http_build_query, json_decode, time};
@@ -167,8 +168,11 @@ impl GitLab {
message: Option<&str>,
) -> anyhow::Result<bool> {
if let Some(msg) = message {
- self.io
- .write_error(PhpMixed::String(msg.to_string()), true, IOInterface::NORMAL);
+ self.io.write_error(
+ PhpMixed::String(msg.to_string()),
+ true,
+ io_interface::NORMAL,
+ );
}
let local_auth_config = self.config.get_local_auth_config_source();
@@ -187,44 +191,44 @@ impl GitLab {
+ &self.config.get_auth_config_source().get_name()
)),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String("To revoke access to this token you can visit:".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(revoke_link.clone()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(
"Alternatively you can setup an personal access token on:".to_string(),
),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(personal_access_token_link.clone()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String("and store it under \"gitlab-token\" see https://getcomposer.org/doc/articles/authentication-for-private-packages.md#gitlab-token for more details.".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String("https://getcomposer.org/doc/articles/authentication-for-private-packages.md#gitlab-token".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String("for more details.".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
let mut store_in_local_auth_config = false;
@@ -260,32 +264,32 @@ impl GitLab {
self.io.write_error(
PhpMixed::String("Bad credentials. If you have two factor authentication enabled you will have to manually create a personal access token".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
} else {
self.io.write_error(
PhpMixed::String("Bad credentials.".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
}
} else {
self.io.write_error(
PhpMixed::String("Maximum number of login attempts exceeded. Please try again later.".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
}
self.io.write_error(
PhpMixed::String("You can also manually create a personal access token enabling the \"read_api\" scope at:".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(personal_access_token_link.clone()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.io.write_error(
PhpMixed::String(format!(
@@ -293,7 +297,7 @@ impl GitLab {
origin_url
)),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
continue;
@@ -374,7 +378,7 @@ impl GitLab {
self.io.write_error(
PhpMixed::String(format!("Couldn't refresh access token: {}", te.message)),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
return Ok(false);
}
@@ -459,7 +463,7 @@ impl GitLab {
self.io.write_error(
PhpMixed::String("Token successfully created".to_string()),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
Ok(token)
@@ -548,7 +552,7 @@ impl GitLab {
self.io.write_error(
PhpMixed::String("GitLab token successfully refreshed".to_string()),
true,
- IOInterface::VERY_VERBOSE,
+ io_interface::VERY_VERBOSE,
);
self.io.write_error(
PhpMixed::String(format!(
@@ -556,7 +560,7 @@ impl GitLab {
scheme, origin_url
)),
true,
- IOInterface::VERY_VERBOSE,
+ io_interface::VERY_VERBOSE,
);
Ok(token)
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index 2d97322..6351a73 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -1,5 +1,6 @@
//! ref: composer/src/Composer/Util/ProcessExecutor.php
+use crate::io::io_interface;
use anyhow::Result;
use indexmap::IndexMap;
use std::sync::{LazyLock, Mutex};
@@ -361,13 +362,13 @@ impl ProcessExecutor {
self.io.as_ref().unwrap().write_error_raw(
PhpMixed::String(buffer.to_string()),
false,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
} else {
self.io.as_ref().unwrap().write_raw(
PhpMixed::String(buffer.to_string()),
false,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
}
}
diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs
index f1a900c..b312ec3 100644
--- a/crates/shirabe/src/util/svn.rs
+++ b/crates/shirabe/src/util/svn.rs
@@ -1,5 +1,6 @@
//! ref: composer/src/Composer/Util/Svn.php
+use crate::io::io_interface;
use std::sync::Mutex;
use anyhow::Result;
@@ -142,7 +143,7 @@ impl Svn {
// PHP: $output .= $buffer;
output.get_or_insert_with(String::new).push_str(buffer);
if verbose {
- // self.io.write_error(PhpMixed::String(buffer.to_string()), false, IOInterface::NORMAL);
+ // self.io.write_error(PhpMixed::String(buffer.to_string()), false, io_interface::NORMAL);
}
None
};
@@ -216,7 +217,7 @@ impl Svn {
self.url,
)),
true,
- IOInterface::NORMAL,
+ io_interface::NORMAL,
);
self.has_auth = Some(true);