xref: /DragonOS/user/apps/test_ebpf/syscall_ebpf/xtask/src/main.rs (revision fae6e9ade46a52976ad5d099643d51cc20876448)
1*fae6e9adSlinfeng mod build_ebpf;
2*fae6e9adSlinfeng mod build;
3*fae6e9adSlinfeng mod run;
4*fae6e9adSlinfeng 
5*fae6e9adSlinfeng use std::process::exit;
6*fae6e9adSlinfeng 
7*fae6e9adSlinfeng use clap::Parser;
8*fae6e9adSlinfeng 
9*fae6e9adSlinfeng #[derive(Debug, Parser)]
10*fae6e9adSlinfeng pub struct Options {
11*fae6e9adSlinfeng     #[clap(subcommand)]
12*fae6e9adSlinfeng     command: Command,
13*fae6e9adSlinfeng }
14*fae6e9adSlinfeng 
15*fae6e9adSlinfeng #[derive(Debug, Parser)]
16*fae6e9adSlinfeng enum Command {
17*fae6e9adSlinfeng     BuildEbpf(build_ebpf::Options),
18*fae6e9adSlinfeng     Build(build::Options),
19*fae6e9adSlinfeng     Run(run::Options),
20*fae6e9adSlinfeng }
21*fae6e9adSlinfeng 
main()22*fae6e9adSlinfeng fn main() {
23*fae6e9adSlinfeng     let opts = Options::parse();
24*fae6e9adSlinfeng 
25*fae6e9adSlinfeng     use Command::*;
26*fae6e9adSlinfeng     let ret = match opts.command {
27*fae6e9adSlinfeng         BuildEbpf(opts) => build_ebpf::build_ebpf(opts),
28*fae6e9adSlinfeng         Run(opts) => run::run(opts),
29*fae6e9adSlinfeng         Build(opts) => build::build(opts),
30*fae6e9adSlinfeng     };
31*fae6e9adSlinfeng 
32*fae6e9adSlinfeng     if let Err(e) = ret {
33*fae6e9adSlinfeng         eprintln!("{e:#}");
34*fae6e9adSlinfeng         exit(1);
35*fae6e9adSlinfeng     }
36*fae6e9adSlinfeng }
37