mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 13:38:43 +00:00
Refactor and add new enum PkgFmtDecomposed
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
c33f195d5f
commit
bd68613448
3 changed files with 78 additions and 29 deletions
74
src/fmt.rs
Normal file
74
src/fmt.rs
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use strum_macros::{Display, EnumString, EnumVariantNames};
|
||||||
|
|
||||||
|
/// Binary format enumeration
|
||||||
|
#[derive(
|
||||||
|
Debug, Copy, Clone, PartialEq, Serialize, Deserialize, Display, EnumString, EnumVariantNames,
|
||||||
|
)]
|
||||||
|
#[strum(serialize_all = "snake_case")]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum PkgFmt {
|
||||||
|
/// Download format is TAR (uncompressed)
|
||||||
|
Tar,
|
||||||
|
/// Download format is TGZ (TAR + GZip)
|
||||||
|
Tgz,
|
||||||
|
/// Download format is TAR + XZ
|
||||||
|
Txz,
|
||||||
|
/// Download format is TAR + Zstd
|
||||||
|
Tzstd,
|
||||||
|
/// Download format is Zip
|
||||||
|
Zip,
|
||||||
|
/// Download format is raw / binary
|
||||||
|
Bin,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PkgFmt {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Tgz
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PkgFmt {
|
||||||
|
/// If self is one of the tar based formats,
|
||||||
|
/// return Some.
|
||||||
|
pub fn decompose(self) -> PkgFmtDecomposed {
|
||||||
|
match self {
|
||||||
|
PkgFmt::Tar => PkgFmtDecomposed::Tar(TarBasedFmt::Tar),
|
||||||
|
PkgFmt::Tgz => PkgFmtDecomposed::Tar(TarBasedFmt::Tgz),
|
||||||
|
PkgFmt::Txz => PkgFmtDecomposed::Tar(TarBasedFmt::Txz),
|
||||||
|
PkgFmt::Tzstd => PkgFmtDecomposed::Tar(TarBasedFmt::Tzstd),
|
||||||
|
PkgFmt::Bin => PkgFmtDecomposed::Bin,
|
||||||
|
PkgFmt::Zip => PkgFmtDecomposed::Zip,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
|
pub enum PkgFmtDecomposed {
|
||||||
|
Tar(TarBasedFmt),
|
||||||
|
Bin,
|
||||||
|
Zip,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
|
pub enum TarBasedFmt {
|
||||||
|
/// Download format is TAR (uncompressed)
|
||||||
|
Tar,
|
||||||
|
/// Download format is TGZ (TAR + GZip)
|
||||||
|
Tgz,
|
||||||
|
/// Download format is TAR + XZ
|
||||||
|
Txz,
|
||||||
|
/// Download format is TAR + Zstd
|
||||||
|
Tzstd,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TarBasedFmt> for PkgFmt {
|
||||||
|
fn from(fmt: TarBasedFmt) -> Self {
|
||||||
|
match fmt {
|
||||||
|
TarBasedFmt::Tar => PkgFmt::Tar,
|
||||||
|
TarBasedFmt::Tgz => PkgFmt::Tgz,
|
||||||
|
TarBasedFmt::Txz => PkgFmt::Txz,
|
||||||
|
TarBasedFmt::Tzstd => PkgFmt::Tzstd,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,7 +12,7 @@ use tokio::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{extracter::*, readable_rx::*};
|
use super::{extracter::*, readable_rx::*};
|
||||||
use crate::{BinstallError, PkgFmt};
|
use crate::{BinstallError, PkgFmt, TarBasedFmt};
|
||||||
|
|
||||||
pub(crate) enum Content {
|
pub(crate) enum Content {
|
||||||
/// Data to write to file
|
/// Data to write to file
|
||||||
|
|
31
src/lib.rs
31
src/lib.rs
|
@ -1,7 +1,6 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum_macros::{Display, EnumString, EnumVariantNames};
|
|
||||||
|
|
||||||
pub mod drivers;
|
pub mod drivers;
|
||||||
pub use drivers::*;
|
pub use drivers::*;
|
||||||
|
@ -18,6 +17,9 @@ pub mod fetchers;
|
||||||
mod target;
|
mod target;
|
||||||
pub use target::*;
|
pub use target::*;
|
||||||
|
|
||||||
|
mod fmt;
|
||||||
|
pub use fmt::*;
|
||||||
|
|
||||||
/// Default package path template (may be overridden in package Cargo.toml)
|
/// Default package path template (may be overridden in package Cargo.toml)
|
||||||
pub const DEFAULT_PKG_URL: &str =
|
pub const DEFAULT_PKG_URL: &str =
|
||||||
"{ repo }/releases/download/v{ version }/{ name }-{ target }-v{ version }.{ archive-format }";
|
"{ repo }/releases/download/v{ version }/{ name }-{ target }-v{ version }.{ archive-format }";
|
||||||
|
@ -25,33 +27,6 @@ pub const DEFAULT_PKG_URL: &str =
|
||||||
/// Default binary name template (may be overridden in package Cargo.toml)
|
/// Default binary name template (may be overridden in package Cargo.toml)
|
||||||
pub const DEFAULT_BIN_DIR: &str = "{ name }-{ target }-v{ version }/{ bin }{ binary-ext }";
|
pub const DEFAULT_BIN_DIR: &str = "{ name }-{ target }-v{ version }/{ bin }{ binary-ext }";
|
||||||
|
|
||||||
/// Binary format enumeration
|
|
||||||
#[derive(
|
|
||||||
Debug, Copy, Clone, PartialEq, Serialize, Deserialize, Display, EnumString, EnumVariantNames,
|
|
||||||
)]
|
|
||||||
#[strum(serialize_all = "snake_case")]
|
|
||||||
#[serde(rename_all = "snake_case")]
|
|
||||||
pub enum PkgFmt {
|
|
||||||
/// Download format is TAR (uncompressed)
|
|
||||||
Tar,
|
|
||||||
/// Download format is TGZ (TAR + GZip)
|
|
||||||
Tgz,
|
|
||||||
/// Download format is TAR + XZ
|
|
||||||
Txz,
|
|
||||||
/// Download format is TAR + Zstd
|
|
||||||
Tzstd,
|
|
||||||
/// Download format is Zip
|
|
||||||
Zip,
|
|
||||||
/// Download format is raw / binary
|
|
||||||
Bin,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for PkgFmt {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Tgz
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `binstall` metadata container
|
/// `binstall` metadata container
|
||||||
///
|
///
|
||||||
/// Required to nest metadata under `package.metadata.binstall`
|
/// Required to nest metadata under `package.metadata.binstall`
|
||||||
|
|
Loading…
Add table
Reference in a new issue