xtask: add cargo backed runner

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2021-04-16 23:55:06 +05:30
parent 88c2703cc7
commit 36228b05e5
No known key found for this signature in database
GPG Key ID: 366D7BBAD1031E80
5 changed files with 68 additions and 0 deletions

2
.cargo/config Normal file
View File

@ -0,0 +1,2 @@
[alias]
xtask = "run --package xtask --"

14
.gitignore vendored
View File

@ -1,2 +1,16 @@
result
result-*
# Created by https://www.toptal.com/developers/gitignore/api/rust
# Edit at https://www.toptal.com/developers/gitignore?templates=rust
### Rust ###
# Generated by Cargo
# will have compiled files and executables
/target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# End of https://www.toptal.com/developers/gitignore/api/rust

4
Cargo.toml Normal file
View File

@ -0,0 +1,4 @@
[workspace]
members = [
"xtask",
]

11
xtask/Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "xtask"
version = "0.1.0"
authors = ["Harsh Shandilya <me@msfjarvis.dev>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
walkdir = "2.3.2"
xshell = "0.1.9"

37
xtask/src/main.rs Normal file
View File

@ -0,0 +1,37 @@
use std::error::Error;
use std::process::Command;
use walkdir::WalkDir;
fn main() -> Result<(), Box<dyn Error + 'static>> {
let args = std::env::args();
if args.len() == 0 {
println!("Provide a command");
return Ok(());
}
match std::env::args().nth(1) {
None => {}
Some(arg) => match arg.as_str() {
"clean" => {
for entry in WalkDir::new(".").into_iter().filter_map(|e| e.ok()) {
if entry.path().to_str().unwrap().contains("./result") {
std::fs::remove_file(entry.path().to_str().unwrap())?;
}
}
}
"hash" => {
let repo = std::env::args().nth(2).unwrap();
let tag = std::env::args().nth(3).unwrap();
let url = format!(
"https://github.com/{}/archive/{}.tar.gz",
repo, tag
);
let output = Command::new("nix-prefetch-url")
.args(&["--type", "sha256", "--unpack", url.as_str()])
.output()?;
println!("{}", std::str::from_utf8(&output.stdout).unwrap());
}
_ => {}
},
};
return Ok(());
}