kanit

Toy init system
Log | Files | Refs | README | LICENSE

main.rs (922B)


      1 // me when the binary is plural
      2 
      3 use std::env::args;
      4 use std::path::Path;
      5 use std::process::ExitCode;
      6 
      7 fn main() -> ExitCode {
      8     let name = args().next().expect("first arg");
      9     let name_as_path = Path::new(&name);
     10     let bin_name = name_as_path.file_name().expect("file name").to_str();
     11 
     12     match bin_name {
     13         Some("init") => kanit_init::handle_cli(),
     14         #[cfg(feature = "cli")]
     15         Some("kanit") => kanit_cli::handle_cli(true),
     16         #[cfg(feature = "cli")]
     17         Some("poweroff") => kanit_cli::handle_cli(false),
     18         #[cfg(feature = "cli")]
     19         Some("reboot") => kanit_cli::handle_cli(false),
     20         #[cfg(feature = "cli")]
     21         Some("halt") => kanit_cli::handle_cli(false),
     22 
     23         Some("kanit-supervisor") => kanit_supervisor::handle_cli(),
     24         _ => {
     25             eprintln!("was unable to locate `{}`", bin_name.unwrap_or(""));
     26             ExitCode::FAILURE
     27         }
     28     }
     29 }