Skip to content

Commit ca842d0

Browse files
author
Daniel Watkins
committed
Add -c option to main.rs
This option takes a string which it runs as a program.
1 parent d50d920 commit ca842d0

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/main.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,20 @@ fn main() {
2929
.multiple(true)
3030
.help("Give the verbosity"),
3131
)
32+
.arg(
33+
Arg::with_name("c")
34+
.short("c")
35+
.takes_value(true)
36+
.help("run the given string as a program"),
37+
)
3238
.get_matches();
3339

40+
// Figure out if a -c option was given:
41+
if let Some(command) = matches.value_of("c") {
42+
run_command(&mut command.to_string());
43+
return;
44+
}
45+
3446
// Figure out if a script was passed:
3547
match matches.value_of("script") {
3648
None => run_shell(),
@@ -52,6 +64,14 @@ fn _run_string(source: &String) {
5264
}
5365
}
5466

67+
fn run_command(source: &mut String) {
68+
debug!("Running command {}", source);
69+
70+
// This works around https://github.com/RustPython/RustPython/issues/17
71+
source.push_str("\n");
72+
_run_string(source)
73+
}
74+
5575
fn run_script(script_file: &String) {
5676
debug!("Running file {}", script_file);
5777
// Parse an ast from it:

0 commit comments

Comments
 (0)