|
|
@ -19,8 +19,14 @@ pub struct VersionError {
|
|
|
|
|
|
|
|
|
|
|
|
impl VersionError {
|
|
|
|
impl VersionError {
|
|
|
|
pub fn new<S1: ToString, S2: ToString>(src: S1, detail: S2) -> Self {
|
|
|
|
pub fn new<S1: ToString, S2: ToString>(src: S1, detail: S2) -> Self {
|
|
|
|
let src = src.to_string();
|
|
|
|
let mut src = src.to_string();
|
|
|
|
let pos = (0, src.len()).into();
|
|
|
|
let mut pos = (0, src.len()).into();
|
|
|
|
|
|
|
|
let clean_src = src.trim_start_matches('^');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let Some((arg_str, arg_pos)) = find_in_args(&clean_src) {
|
|
|
|
|
|
|
|
pos = arg_pos;
|
|
|
|
|
|
|
|
src = arg_str;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
src,
|
|
|
|
src,
|
|
|
@ -40,6 +46,13 @@ impl VersionError {
|
|
|
|
pub fn not_installed<S: ToString>(src: S) -> Self {
|
|
|
|
pub fn not_installed<S: ToString>(src: S) -> Self {
|
|
|
|
Self::new(src, "The version is not installed.")
|
|
|
|
Self::new(src, "The version is not installed.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn unsupported<S: ToString>(src: S) -> Self {
|
|
|
|
|
|
|
|
Self::new(
|
|
|
|
|
|
|
|
src,
|
|
|
|
|
|
|
|
"This type of version string is not supported with this operation.",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Error, Diagnostic)]
|
|
|
|
#[derive(Debug, Error, Diagnostic)]
|
|
|
@ -132,6 +145,7 @@ pub struct CommandNotFoundError {
|
|
|
|
|
|
|
|
|
|
|
|
impl CommandNotFoundError {
|
|
|
|
impl CommandNotFoundError {
|
|
|
|
pub fn new(command: String, args: Vec<OsString>, path: PathBuf) -> Self {
|
|
|
|
pub fn new(command: String, args: Vec<OsString>, path: PathBuf) -> Self {
|
|
|
|
|
|
|
|
let (full_command, pos) = find_in_args(&command).unwrap_or_else(|| {
|
|
|
|
let pos = (0, command.len()).into();
|
|
|
|
let pos = (0, command.len()).into();
|
|
|
|
let full_command = format!(
|
|
|
|
let full_command = format!(
|
|
|
|
"{command} {}",
|
|
|
|
"{command} {}",
|
|
|
@ -140,6 +154,9 @@ impl CommandNotFoundError {
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(" ")
|
|
|
|
.join(" ")
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
(full_command, pos)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
command,
|
|
|
|
command,
|
|
|
|
full_command,
|
|
|
|
full_command,
|
|
|
@ -161,3 +178,11 @@ pub struct MapDirError {
|
|
|
|
#[source]
|
|
|
|
#[source]
|
|
|
|
pub caused_by: std::io::Error,
|
|
|
|
pub caused_by: std::io::Error,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn find_in_args(query: &str) -> Option<(String, SourceSpan)> {
|
|
|
|
|
|
|
|
let args_string = std::env::args().fold(String::new(), |s, acc| format!("{s} {acc}"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
args_string
|
|
|
|
|
|
|
|
.find(&query)
|
|
|
|
|
|
|
|
.map(|index| (args_string, (index, query.len()).into()))
|
|
|
|
|
|
|
|
}
|
|
|
|