Add -c option to main.rs
This option takes a string which it runs as a program.
@@ -29,8 +29,20 @@ fn main() {
.multiple(true)
.help("Give the verbosity"),
)
+ .arg(
+ Arg::with_name("c")
+ .short("c")
+ .takes_value(true)
+ .help("run the given string as a program"),
+ )
.get_matches();
+ // Figure out if a -c option was given:
+ if let Some(command) = matches.value_of("c") {
+ run_command(&mut command.to_string());
+ return;
+ }
+
// Figure out if a script was passed:
match matches.value_of("script") {
None => run_shell(),
@@ -52,6 +64,14 @@ fn _run_string(source: &String) {
}
}
+fn run_command(source: &mut String) {
+ debug!("Running command {}", source);
+
+ // This works around https://github.com/RustPython/RustPython/issues/17
+ source.push_str("\n");
+ _run_string(source)
+}
+
fn run_script(script_file: &String) {
debug!("Running file {}", script_file);
// Parse an ast from it:
