This commit is contained in:
figsoda 2022-12-31 15:09:23 -05:00
parent bc21735656
commit 34c0ceb743
3 changed files with 63 additions and 5 deletions

48
Cargo.lock generated
View File

@ -8,6 +8,17 @@ version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi 0.1.19",
"libc",
"winapi",
]
[[package]]
name = "bitflags"
version = "1.3.2"
@ -133,6 +144,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.2.6"
@ -174,12 +194,18 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189"
dependencies = [
"hermit-abi",
"hermit-abi 0.2.6",
"io-lifetimes",
"rustix",
"windows-sys",
]
[[package]]
name = "is_ci"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb"
[[package]]
name = "itertools"
version = "0.10.5"
@ -218,6 +244,7 @@ dependencies = [
"enum_dispatch",
"indoc",
"itertools",
"owo-colors",
"serde",
"serde_json",
"url",
@ -235,6 +262,15 @@ version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "owo-colors"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
dependencies = [
"supports-color",
]
[[package]]
name = "percent-encoding"
version = "2.2.0"
@ -346,6 +382,16 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "supports-color"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ba6faf2ca7ee42fdd458f4347ae0a9bd6bcc445ad7cb57ad82b383f18870d6f"
dependencies = [
"atty",
"is_ci",
]
[[package]]
name = "syn"
version = "1.0.107"

View File

@ -16,6 +16,7 @@ anyhow = "1.0.68"
enum_dispatch = "0.3.9"
indoc = "1.0.8"
itertools = "0.10.5"
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.91"
url = "2.3.1"

View File

@ -26,13 +26,24 @@ impl GetStdout for Command {
}
}
macro_rules! info {
($($tt:tt)+) => {{
use owo_colors::{OwoColorize, Stream, Style};
eprintln!(
"{}",
format_args!($($tt)+).if_supports_color(Stream::Stderr, |text| text
.style(Style::new().blue().bold()))
);
}};
}
pub fn flake_prefetch(flake_ref: String) -> Result<String> {
#[derive(Deserialize)]
struct PrefetchOutput {
hash: String,
}
eprintln!("$ nix flake prefetch --json {flake_ref}");
info!("$ nix flake prefetch --json {flake_ref}");
Ok(serde_json::from_slice::<PrefetchOutput>(
&Command::new("nix")
.arg("flake")
@ -45,7 +56,7 @@ pub fn flake_prefetch(flake_ref: String) -> Result<String> {
}
pub fn url_prefetch(url: String) -> Result<String> {
eprintln!("nix-prefetch-url --unpack {url}");
info!("$ nix-prefetch-url --unpack {url}");
let hash = String::from_utf8(
Command::new("nix-prefetch-url")
.arg("--unpack")
@ -54,7 +65,7 @@ pub fn url_prefetch(url: String) -> Result<String> {
)?;
let hash = hash.trim_end();
eprintln!("nix hash to-sri --type sha256 {hash}");
info!("$ nix hash to-sri --type sha256 {hash}");
Ok(String::from_utf8(
Command::new("nix")
.arg("hash")
@ -69,7 +80,7 @@ pub fn url_prefetch(url: String) -> Result<String> {
}
pub fn fod_prefetch(expr: String) -> Result<String> {
eprintln!("$ nix build --impure --no-link --expr '{expr}'");
info!("$ nix build --impure --no-link --expr '{expr}'");
let Output {
stdout,