xtask: add cargo backed runner
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
88c2703cc7
commit
36228b05e5
|
@ -0,0 +1,2 @@
|
||||||
|
[alias]
|
||||||
|
xtask = "run --package xtask --"
|
|
@ -1,2 +1,16 @@
|
||||||
result
|
result
|
||||||
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
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"xtask",
|
||||||
|
]
|
|
@ -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"
|
|
@ -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(());
|
||||||
|
}
|
Loading…
Reference in New Issue