Added help.

This commit is contained in:
PaddiM8 2020-06-13 21:56:13 +02:00
parent c50534a248
commit 3a25a3d416

View File

@ -21,22 +21,37 @@ fn main() {
break; break;
}; };
if arg == "-i" { match arg.as_ref() {
let file_name = &args.next().expect("Expected input file."); // The next argument will be the file name. "-h" | "--help" => {
let mut file_content = String::new(); // The indentation... Will have to do something more scalable in the future.
File::open(&file_name) println!(
.expect("Couldn't find file.") "
.read_to_string(&mut file_content) -= kalk help =-\n
.expect("Failed to read input file."); kalk [OPTIONS] [INPUT]
-h, --help : show this
-i : load a file with predefined functions/variables
"
);
return;
}
"-i" => {
let file_name = &args.next().expect("Expected input file."); // The next argument will be the file name.
let mut file_content = String::new();
File::open(&file_name)
.expect("Couldn't find file.")
.read_to_string(&mut file_content)
.expect("Failed to read input file.");
// Parse the input file content, resulting in the symbol table being filled out. // Parse the input file content, resulting in the symbol table being filled out.
// Output is not needed here. // Output is not needed here.
parser::eval(&mut parser_context, &file_content, 53) parser::eval(&mut parser_context, &file_content, 53)
.expect("Failed to parse input file."); .expect("Failed to parse input file.");
} else { }
// Main argument. This is expected to be a maths expression. _ => {
// After the loop is finished, this will be parsed and outputted. // Main argument. This is expected to be a maths expression.
expr_input = Some(arg); // After the loop is finished, this will be parsed and outputted.
expr_input = Some(arg);
}
} }
} }