1 use crate::{
2 check::check::GDelCheck,
3 error::error::{ErrorHandler, ExitStatus},
4 executor::executor::GDelExecutor,
5 parser::parser::GroupParser,
6 };
7 use libc::geteuid;
8 use std::process::exit;
9
10 #[path = "../check/mod.rs"]
11 mod check;
12 #[path = "../error/mod.rs"]
13 mod error;
14 #[path = "../executor/mod.rs"]
15 mod executor;
16 #[path = "../parser/mod.rs"]
17 mod parser;
18
19 #[allow(dead_code)]
main()20 fn main() {
21 let args = std::env::args().collect::<Vec<_>>();
22
23 if unsafe { geteuid() } != 0 {
24 ErrorHandler::error_handle(
25 "permission denied (are you root?)".to_string(),
26 ExitStatus::PermissionDenied,
27 )
28 }
29
30 if args.len() < 2 {
31 ErrorHandler::error_handle(
32 format!("usage: {} [options] groupname", args[0]),
33 ExitStatus::InvalidCmdSyntax,
34 );
35 }
36
37 let cmd = GroupParser::parse(args);
38 let info = GDelCheck::check(cmd);
39 let groupname = info.groupname.clone();
40 GDelExecutor::execute(info);
41
42 println!("Delete group [{}] successfully!", groupname);
43
44 exit(ExitStatus::Success as i32);
45 }
46