1#[derive(Debug)]
2pub struct Args {
3 pub no_build: bool,
4 #[cfg(feature = "dracut")]
5 pub no_initramfs: bool,
6 pub no_modules: bool,
7 pub menuconfig: bool,
8 pub replace: bool,
9}
10
11impl Args {
12 const VERSION: &'static str = env!("CARGO_PKG_VERSION");
13 const HELP: &'static str = r"
14Kernel Builder
15USAGE:
16 kernel-builder [OPTIONS]
17FLAGS:
18 -h, --help Prints help information
19 -v, --version Print version
20OPTIONS:
21 --no-build skip build
22 --no-initramfs skip generating initramfs (only if compiled with dracut feature)
23 --no-modules skip installing kernel modules
24 --menuconfig open menuconfig for kernel configuration
25 --replace replace the current installed kerne (useful if you have configured to keep the last kernel)
26";
27
28 #[must_use]
29 pub fn parse_args() -> Self {
30 let mut pargs = pico_args::Arguments::from_env();
31
32 if pargs.contains(["-h", "--help"]) {
34 print!("{}", Self::HELP);
35 std::process::exit(0);
36 }
37
38 if pargs.contains(["-v", "--version"]) {
39 println!("kernel-builder v{}", Self::VERSION);
40 std::process::exit(0);
41 }
42
43 Self {
44 no_build: pargs.contains("--no-build"),
45 #[cfg(feature = "dracut")]
46 no_initramfs: pargs.contains("--no-initramfs"),
47 no_modules: pargs.contains("--no-modules"),
48 menuconfig: pargs.contains("--menuconfig"),
49 replace: pargs.contains("--replace"),
50 }
51 }
52}