xref: /DragonOS/user/apps/user-manage/src/cmd/groupmod.rs (revision 86ee1395de7c614865236ee15071c3603b794e44)
1 use crate::{
2     check::check::GModCheck,
3     error::error::{ErrorHandler, ExitStatus},
4     executor::executor::GModExecutor,
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)]
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     if !cmd.options.is_empty() {
39         let info = GModCheck::check(cmd);
40         let groupname = info.groupname.clone();
41         GModExecutor::execute(info);
42         println!("Modify group [{}]  successfully!", groupname);
43     }
44 
45     exit(ExitStatus::Success as i32);
46 }
47