Aparently I haven't commited all those changes. I really should/want to do a lot

more and smaller commits.
This commit is contained in:
Sebastian Moser
2022-09-12 08:44:20 +02:00
parent aac4700243
commit a92cd8c22c
11 changed files with 1119 additions and 185 deletions

View File

@@ -1,86 +0,0 @@
pub mod server;
static HELP_MESSAGE: &str = "\
Usage:
mize-server [options] [command] [options for command]
Available Commands:
run starts the server
help prints this help message
version prints the version
Available options
-h --help prints this help message
-v --version prints the version
";
//some flags e.g: "--file /tmp" can require that the next argument belongs to them instead of being
//the command
static FLAGS_WITH_ARGUMENTS: [&str; 0] = [];
static AVAILABLE_COMMANDS: [&str; 3] = ["run", "help", "version"];
static AVAILABLE_FLAGS: [&str; 3] = ["--version", "--help"];
static AVAILABLE_ONE_LETTER_FLAGS: [&str; 3] = ["v", "h"];
static VERSION_MESSAGE: &str = "\
Version: 0
";
fn main() {
/*
* WHAT IT DOES
* - get the arguments passed to the programm
*
* - sort out the flags for the main programm and the args for the comand
* - in "mize -h -u --lol server --file=/tmp --folder /home" the flags for the main programm would be ["-h","-u","--lol"]
* - and the args for the command would be ["server", "--file=/tmp --folder /home"]
*
* - get the command to "run"
* - in "mize -h -u --lol server --file=/tmp" it would be "server"
*
* - "run" the command and pass the options and subcommands to it
*
*/
//### get the arguments passed to the programm
let args: Vec<String> = std::env::args().collect();
//### sort out the flags for the main program and the args for the command
let mut main_flags:Vec<String> = Vec::new();
let mut command= String::from("");
let mut command_args = Vec::new();
for i in 1..args.len() {
if args[i].chars().next().unwrap() == '-' {
main_flags.push(args[i].clone());
// i != 0 bcs what if the programm name is in FLAGS_WITH_ARGUMENTS for some reason?
} else if i != 0 && FLAGS_WITH_ARGUMENTS.contains(&&args[i -1][..]) {
main_flags.push(args[i].clone());
//#### get the command to "run"
} else if AVAILABLE_COMMANDS.contains(&&args[i][..]){
command = args[i].clone();
for a in i..args.len(){
command_args.push(args[a].clone());
}
break;
} else {
println!("Command \"{}\" not found!!\n", args[i]);
println!("{}", HELP_MESSAGE);
std::process::exit(1);
}
}
//#### "run" the command and pass the options and subcommands to it
match &command[..] {
"run" => crate::server::run_server(command_args),
"help" => println!("{}", HELP_MESSAGE),
"version" => println!("{}", VERSION_MESSAGE),
_ => {println!("Command not found!!\n"); println!("{}", HELP_MESSAGE);},
}
}