mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-28 00:00:03 +00:00
Improve GhCrateMeta
: Detect cases where pkg-fmt is not specified (#757)
* Fix fmt of mod `<GhCrateMeta as Fetcher>::find` * Add new variant `BinstallError::InvalidPkgFmt` * Impl new fn `PkgFmt::guess_pkg_format` * Improve `GhCrateMeta`: Detect cases where `pkg-fmt` is not specified but `pkg-url` also does not contain format, archive-format or archive-suffix which is required for automatically deducing the pkg-fmt. In these cases, we would call `PkgFmt::guess_pkg_format` to try out best to figure out the pkg-fmt, otherwise we just return an error. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
5c02581569
commit
e510511487
3 changed files with 98 additions and 14 deletions
|
@ -57,6 +57,38 @@ impl PkgFmt {
|
|||
PkgFmt::Zip => &[".zip"],
|
||||
}
|
||||
}
|
||||
|
||||
/// Given the pkg-url template, guess the possible pkg-fmt.
|
||||
pub fn guess_pkg_format(pkg_url: &str) -> Option<Self> {
|
||||
let mut it = pkg_url.rsplitn(3, '.');
|
||||
|
||||
let guess = match it.next()? {
|
||||
"tar" => Some(PkgFmt::Tar),
|
||||
|
||||
"tbz2" => Some(PkgFmt::Tbz2),
|
||||
"bz2" if it.next() == Some("tar") => Some(PkgFmt::Tbz2),
|
||||
|
||||
"tgz" => Some(PkgFmt::Tgz),
|
||||
"gz" if it.next() == Some("tar") => Some(PkgFmt::Tgz),
|
||||
|
||||
"txz" => Some(PkgFmt::Txz),
|
||||
"xz" if it.next() == Some("tar") => Some(PkgFmt::Txz),
|
||||
|
||||
"tzstd" | "tzst" => Some(PkgFmt::Tzstd),
|
||||
"zst" if it.next() == Some("tar") => Some(PkgFmt::Tzstd),
|
||||
|
||||
"exe" | "bin" => Some(PkgFmt::Bin),
|
||||
"zip" => Some(PkgFmt::Zip),
|
||||
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if it.next().is_some() {
|
||||
guess
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue