mirror of
https://github.com/esp-rs/espup.git
synced 2025-10-02 23:25:16 +00:00
refactor: ⚡️ Use anyhow::context to improve err message
This commit is contained in:
parent
ffc2611d41
commit
6a13fec1b9
@ -1,5 +1,5 @@
|
|||||||
use crate::emoji;
|
use crate::emoji;
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{Context, Result};
|
||||||
use guess_host_triple::guess_host_triple;
|
use guess_host_triple::guess_host_triple;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use strum::Display;
|
use strum::Display;
|
||||||
@ -29,16 +29,14 @@ pub enum HostTriple {
|
|||||||
|
|
||||||
/// Parse the host triple if specified, otherwise guess it.
|
/// Parse the host triple if specified, otherwise guess it.
|
||||||
pub fn get_host_triple(host_triple_arg: Option<String>) -> Result<HostTriple> {
|
pub fn get_host_triple(host_triple_arg: Option<String>) -> Result<HostTriple> {
|
||||||
let host_triple = match host_triple_arg {
|
if let Some(host_triple_arg) = host_triple_arg {
|
||||||
Some(host_triple_string) => match FromStr::from_str(&host_triple_string) {
|
HostTriple::from_str(&host_triple_arg).context(format!(
|
||||||
Ok(host_triple) => host_triple,
|
|
||||||
Err(_) => bail!(
|
|
||||||
"{} Host triple '{}' is not supported.",
|
"{} Host triple '{}' is not supported.",
|
||||||
emoji::ERROR,
|
emoji::ERROR,
|
||||||
host_triple_string
|
host_triple_arg,
|
||||||
),
|
))
|
||||||
},
|
} else {
|
||||||
None => HostTriple::from_str(guess_host_triple().unwrap()).unwrap(),
|
HostTriple::from_str(guess_host_triple().unwrap())
|
||||||
};
|
.context(format!("{} Unable to guess host triple.", emoji::ERROR,))
|
||||||
Ok(host_triple)
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user