initial commit

Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
Alex Chi
2022-12-23 14:29:32 -05:00
commit 68303e99b8
17 changed files with 849 additions and 0 deletions

16
xtask/Cargo.toml Normal file
View File

@@ -0,0 +1,16 @@
[package]
name = "mini-lsm-xtask"
version = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
keywords = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1"
console = "0.15"
clap = { version = "4", features = ["derive"] }
duct = "0.13"

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

@@ -0,0 +1,65 @@
use std::path::PathBuf;
use anyhow::{anyhow, Result};
use clap::Parser;
use console::style;
use duct::cmd;
#[derive(clap::Subcommand, Debug)]
enum Action {
/// Check.
Check,
/// Install necessary tools for development.
InstallTools,
/// Show environment variables.
Show,
}
/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[command(subcommand)]
action: Action,
}
fn switch_to_workspace_root() -> Result<()> {
std::env::set_current_dir(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.ok_or_else(|| anyhow!("failed to find the workspace root"))?,
)?;
Ok(())
}
fn main() -> Result<()> {
let args = Args::parse();
match args.action {
Action::InstallTools => {
println!("{}", style("cargo install cargo-nextest").bold());
cmd!("cargo", "install", "cargo-nextest", "--locked").run()?;
println!("{}", style("cargo install mdbook mdbook-toc").bold());
cmd!("cargo", "install", "mdbook", "mdbook-toc", "--locked").run()?;
}
Action::Check => {
switch_to_workspace_root()?;
println!("{}", style("cargo fmt").bold());
cmd!("cargo", "fmt").run()?;
println!("{}", style("cargo check").bold());
cmd!("cargo", "check", "--all-targets").run()?;
println!("{}", style("cargo nextest run").bold());
cmd!("cargo", "nextest", "run").run()?;
println!("{}", style("cargo clippy").bold());
cmd!("cargo", "clippy", "--all-targets").run()?;
println!("{}", style("mdbook build").bold());
cmd!("mdbook", "build").dir("mini-lsm-book").run()?;
}
Action::Show => {
println!("CARGO_MANIFEST_DIR={}", env!("CARGO_MANIFEST_DIR"));
println!("PWD={:?}", std::env::current_dir()?);
}
}
Ok(())
}