reject missing init option values

This commit is contained in:
sabraman 2026-03-23 00:10:29 +03:00
parent e35d69c61f
commit 6b8a516c57
1 changed files with 22 additions and 4 deletions

View File

@ -7,11 +7,17 @@ use std::process::Command;
/// Options for the init command /// Options for the init command
pub struct InitOptions { pub struct InitOptions {
/// Listen port for the generated proxy configuration.
pub port: u16, pub port: u16,
/// TLS masking domain written into the generated configuration.
pub domain: String, pub domain: String,
/// Optional user-provided MTProxy secret in hex form.
pub secret: Option<String>, pub secret: Option<String>,
/// Username inserted into the generated access configuration.
pub username: String, pub username: String,
/// Destination directory for the generated config file.
pub config_dir: PathBuf, pub config_dir: PathBuf,
/// Skips starting the service after installation.
pub no_start: bool, pub no_start: bool,
} }
@ -49,26 +55,38 @@ pub fn parse_init_args(args: &[String]) -> Option<InitOptions> {
} }
"--domain" => { "--domain" => {
i += 1; i += 1;
if i < args.len() { if i < args.len() && !args[i].starts_with('-') {
opts.domain = args[i].clone(); opts.domain = args[i].clone();
} else {
eprintln!("[error] Missing value for --domain");
std::process::exit(1);
} }
} }
"--secret" => { "--secret" => {
i += 1; i += 1;
if i < args.len() { if i < args.len() && !args[i].starts_with('-') {
opts.secret = Some(args[i].clone()); opts.secret = Some(args[i].clone());
} else {
eprintln!("[error] Missing value for --secret");
std::process::exit(1);
} }
} }
"--user" => { "--user" => {
i += 1; i += 1;
if i < args.len() { if i < args.len() && !args[i].starts_with('-') {
opts.username = args[i].clone(); opts.username = args[i].clone();
} else {
eprintln!("[error] Missing value for --user");
std::process::exit(1);
} }
} }
"--config-dir" => { "--config-dir" => {
i += 1; i += 1;
if i < args.len() { if i < args.len() && !args[i].starts_with('-') {
opts.config_dir = PathBuf::from(&args[i]); opts.config_dir = PathBuf::from(&args[i]);
} else {
eprintln!("[error] Missing value for --config-dir");
std::process::exit(1);
} }
} }
"--no-start" => { "--no-start" => {