lab4
This commit is contained in:
23
src/cli.rs
23
src/cli.rs
@@ -23,6 +23,10 @@ pub enum Command {
|
||||
input: PathBuf,
|
||||
output_tree: PathBuf,
|
||||
},
|
||||
Sem {
|
||||
input: PathBuf,
|
||||
output_tree: PathBuf,
|
||||
},
|
||||
}
|
||||
|
||||
impl Args {
|
||||
@@ -55,6 +59,7 @@ fn validate_inner(args: ArgsInner) -> Result<ArgsInner, clap::Error> {
|
||||
output_symbols,
|
||||
} => validate_lex(input, output_tokens, output_symbols)?,
|
||||
Command::Syn { input, output_tree } => validate_syn(input, output_tree)?,
|
||||
Command::Sem { input, output_tree } => validate_sem(input, output_tree)?,
|
||||
};
|
||||
|
||||
Ok(args)
|
||||
@@ -106,3 +111,21 @@ fn validate_syn(input: &PathBuf, output_tree: &PathBuf) -> Result<(), clap::Erro
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_sem(input: &PathBuf, output_tree: &PathBuf) -> Result<(), clap::Error> {
|
||||
if !input.is_file() {
|
||||
return Err(clap::Error::raw(
|
||||
clap::error::ErrorKind::InvalidValue,
|
||||
format!("Input file '{}' does not exist", input.display()),
|
||||
));
|
||||
}
|
||||
|
||||
if output_tree == input {
|
||||
return Err(clap::Error::raw(
|
||||
clap::error::ErrorKind::InvalidValue,
|
||||
"Input and output files cannot be the same",
|
||||
));
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user