mirror of
https://github.com/fosskers/cargo-aur.git
synced 2026-04-30 15:57:36 -05:00
Remove anyhow
This commit is contained in:
@@ -12,7 +12,6 @@ keywords = ["cargo", "subcommand", "archlinux", "aur"]
|
|||||||
categories = ["command-line-utilities"]
|
categories = ["command-line-utilities"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
|
||||||
gumdrop = "0.8"
|
gumdrop = "0.8"
|
||||||
hmac-sha256 = "0.1"
|
hmac-sha256 = "0.1"
|
||||||
itertools = "0.10"
|
itertools = "0.10"
|
||||||
|
|||||||
42
src/error.rs
Normal file
42
src/error.rs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
//! Errors that can occur in this application.
|
||||||
|
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
pub(crate) enum Error {
|
||||||
|
IO(std::io::Error),
|
||||||
|
Toml(toml::de::Error),
|
||||||
|
Utf8(std::str::Utf8Error),
|
||||||
|
MissingTarget,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Error {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Error::IO(e) => write!(f, "{}", e),
|
||||||
|
Error::Toml(e) => write!(f, "{}", e),
|
||||||
|
Error::Utf8(e) => write!(f, "{}", e),
|
||||||
|
Error::MissingTarget => write!(
|
||||||
|
f,
|
||||||
|
"Missing target! Try: rustup target add x86_64-unknown-linux-musl"
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<std::str::Utf8Error> for Error {
|
||||||
|
fn from(v: std::str::Utf8Error) -> Self {
|
||||||
|
Self::Utf8(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<toml::de::Error> for Error {
|
||||||
|
fn from(v: toml::de::Error) -> Self {
|
||||||
|
Self::Toml(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<std::io::Error> for Error {
|
||||||
|
fn from(v: std::io::Error) -> Self {
|
||||||
|
Self::IO(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/main.rs
22
src/main.rs
@@ -1,4 +1,6 @@
|
|||||||
use anyhow::anyhow;
|
pub(crate) mod error;
|
||||||
|
|
||||||
|
use crate::error::Error;
|
||||||
use gumdrop::{Options, ParsingStyle};
|
use gumdrop::{Options, ParsingStyle};
|
||||||
use hmac_sha256::Hash;
|
use hmac_sha256::Hash;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
@@ -88,7 +90,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn work(args: Args) -> anyhow::Result<()> {
|
fn work(args: Args) -> Result<(), Error> {
|
||||||
// We can't proceed if the user has specified `--musl` but doesn't have the
|
// We can't proceed if the user has specified `--musl` but doesn't have the
|
||||||
// target installed.
|
// target installed.
|
||||||
if args.musl {
|
if args.musl {
|
||||||
@@ -105,7 +107,7 @@ fn work(args: Args) -> anyhow::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cargo_config() -> anyhow::Result<Config> {
|
fn cargo_config() -> Result<Config, Error> {
|
||||||
let content = fs::read_to_string("Cargo.toml")?;
|
let content = fs::read_to_string("Cargo.toml")?;
|
||||||
let proj = toml::from_str(&content)?;
|
let proj = toml::from_str(&content)?;
|
||||||
Ok(proj) // TODO Would like to do this in one line with the above.
|
Ok(proj) // TODO Would like to do this in one line with the above.
|
||||||
@@ -151,7 +153,7 @@ package() {{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Run `cargo build --release`, potentially building statically.
|
/// Run `cargo build --release`, potentially building statically.
|
||||||
fn release_build(musl: bool) -> anyhow::Result<()> {
|
fn release_build(musl: bool) -> Result<(), Error> {
|
||||||
let mut args = vec!["build", "--release"];
|
let mut args = vec!["build", "--release"];
|
||||||
|
|
||||||
if musl {
|
if musl {
|
||||||
@@ -162,7 +164,7 @@ fn release_build(musl: bool) -> anyhow::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tarball(musl: bool, package: &Package) -> anyhow::Result<()> {
|
fn tarball(musl: bool, package: &Package) -> Result<(), Error> {
|
||||||
let binary = if musl {
|
let binary = if musl {
|
||||||
format!("target/x86_64-unknown-linux-musl/release/{}", package.name)
|
format!("target/x86_64-unknown-linux-musl/release/{}", package.name)
|
||||||
} else {
|
} else {
|
||||||
@@ -183,12 +185,12 @@ fn tarball(musl: bool, package: &Package) -> anyhow::Result<()> {
|
|||||||
|
|
||||||
/// Strip the release binary, so that we aren't compressing more bytes than we
|
/// Strip the release binary, so that we aren't compressing more bytes than we
|
||||||
/// need to.
|
/// need to.
|
||||||
fn strip(path: &str) -> anyhow::Result<()> {
|
fn strip(path: &str) -> Result<(), Error> {
|
||||||
Command::new("strip").arg(path).status()?;
|
Command::new("strip").arg(path).status()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sha256sum(package: &Package) -> anyhow::Result<String> {
|
fn sha256sum(package: &Package) -> Result<String, Error> {
|
||||||
let bytes = fs::read(package.tarball())?;
|
let bytes = fs::read(package.tarball())?;
|
||||||
let digest = Hash::hash(&bytes);
|
let digest = Hash::hash(&bytes);
|
||||||
let hex = digest.iter().map(|u| format!("{:02x}", u)).collect();
|
let hex = digest.iter().map(|u| format!("{:02x}", u)).collect();
|
||||||
@@ -196,7 +198,7 @@ fn sha256sum(package: &Package) -> anyhow::Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Does the user have the `x86_64-unknown-linux-musl` target installed?
|
/// Does the user have the `x86_64-unknown-linux-musl` target installed?
|
||||||
fn musl_check() -> anyhow::Result<()> {
|
fn musl_check() -> Result<(), Error> {
|
||||||
let args = vec!["target", "list", "--installed"];
|
let args = vec!["target", "list", "--installed"];
|
||||||
let output = Command::new("rustup").args(args).output()?.stdout;
|
let output = Command::new("rustup").args(args).output()?.stdout;
|
||||||
let installed = str::from_utf8(&output)?
|
let installed = str::from_utf8(&output)?
|
||||||
@@ -206,8 +208,6 @@ fn musl_check() -> anyhow::Result<()> {
|
|||||||
if installed {
|
if installed {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!(
|
Err(Error::MissingTarget)
|
||||||
"Missing target! Try: rustup target add x86_64-unknown-linux-musl"
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user