Fix clippy issues in the generated code.

Fix template so that the generated code would not have any
clippy issues (per `cargo +nightly clippy`).
Add template conditionals on the program_type to avoid
a warning about unused 'opt' variable.

Fixes #66.
pull/67/head
Dmitry Savintsev 2 years ago
parent 3ac1aa63ce
commit e86392d422

@ -1,5 +1,4 @@
use std::path::PathBuf;
use std::process::Command;
use std::{path::PathBuf, process::Command};
use clap::Parser;
@ -55,7 +54,7 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> {
args.push("--release")
}
let status = Command::new("cargo")
.current_dir(&dir)
.current_dir(dir)
.args(&args)
.status()
.expect("failed to build bpf program");

@ -27,7 +27,7 @@ fn main() {
};
if let Err(e) = ret {
eprintln!("{:#}", e);
eprintln!("{e:#}");
exit(1);
}
}

@ -47,7 +47,7 @@ pub fn run(opts: Options) -> Result<(), anyhow::Error> {
// profile we are building (release or debug)
let profile = if opts.release { "release" } else { "debug" };
let bin_path = format!("target/{}/{{project-name}}", profile);
let bin_path = format!("target/{profile}/{{project-name}}");
// arguments to pass to the application
let mut run_args: Vec<_> = opts.run_args.iter().map(String::as_str).collect();
@ -58,7 +58,7 @@ pub fn run(opts: Options) -> Result<(), anyhow::Error> {
args.append(&mut run_args);
// spawn the command
let err = Command::new(args.get(0).expect("No first argument"))
let err = Command::new(args.first().expect("No first argument"))
.args(args.iter().skip(1))
.exec();

@ -41,6 +41,9 @@ use clap::Parser;
use log::{info, warn};
use tokio::signal;
{% case program_type %}
{%- when
"xdp", "classifier", "sock_ops", "cgroup_skb", "cgroup_sysctl", "cgroup_sockopt", "uprobe", "uretprobe" -%}
#[derive(Debug, Parser)]
struct Opt {
{% if program_type == "xdp" or program_type == "classifier" -%}
@ -54,11 +57,17 @@ struct Opt {
pid: Option<i32>
{%- endif %}
}
{%- endcase %}
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
{% case program_type %}
{%- when
"xdp", "classifier", "sock_ops", "cgroup_skb", "cgroup_sysctl", "cgroup_sockopt", "uprobe", "uretprobe" -%}
let opt = Opt::parse();
{%- endcase %}
env_logger::init();
// This will include your eBPF object file as raw bytes at compile-time and load it at

Loading…
Cancel
Save