feat: add clippy to xtask

pull/121/head
Edward Coristine 7 months ago
parent 44c1f66b7e
commit c7d3673064

@ -0,0 +1,37 @@
use clap::Parser;
use std::{path::PathBuf, process::Command};
#[derive(Debug, Parser)]
pub struct Options {
/// Clippy will fix as much as it can
#[clap(long)]
pub fix: bool,
/// Clippy will ignore if the directory has uncommitted changes
#[clap(long)]
pub allow_dirty: bool,
/// Clippy will fix staged files
#[clap(long)]
pub allow_staged: bool,
}
/// Run Clippy on the project
pub fn run_clippy(opts: Options) -> Result<(), anyhow::Error> {
let mut args = vec!["clippy"];
if opts.fix {
args.push("--fix")
}
if opts.allow_dirty {
args.push("--allow-dirty")
}
if opts.allow_staged {
args.push("--allow-staged")
}
let status = Command::new("cargo")
.current_dir(PathBuf::from("{{project-name}}-ebpf"))
.args(&args)
.status()
.expect("failed to build userspace");
assert!(status.success());
Ok(())
}

@ -1,5 +1,6 @@
mod build_ebpf;
mod build; mod build;
mod build_ebpf;
mod clippy;
mod run; mod run;
use std::process::exit; use std::process::exit;
@ -17,6 +18,7 @@ enum Command {
BuildEbpf(build_ebpf::Options), BuildEbpf(build_ebpf::Options),
Build(build::Options), Build(build::Options),
Run(run::Options), Run(run::Options),
Clippy(clippy::Options),
} }
fn main() { fn main() {
@ -27,6 +29,7 @@ fn main() {
BuildEbpf(opts) => build_ebpf::build_ebpf(opts), BuildEbpf(opts) => build_ebpf::build_ebpf(opts),
Run(opts) => run::run(opts), Run(opts) => run::run(opts),
Build(opts) => build::build(opts), Build(opts) => build::build(opts),
Clippy(opts) => clippy::run_clippy(opts),
}; };
if let Err(e) = ret { if let Err(e) = ret {

Loading…
Cancel
Save