diff --git a/src/binary/mod.rs b/src/binary/mod.rs index 64b256e451f3b6ddbcfd62a1aa1e457ea79f3472..abdef86dc8876b2b15400132c42f537db4fa58b1 100644 --- a/src/binary/mod.rs +++ b/src/binary/mod.rs @@ -34,11 +34,12 @@ USAGE: ion [FLAGS] [OPTIONS] [args]... FLAGS: - -h, --help Prints help information - -i, --interactive Force interactive mode - -n, --no-execute Do not execute any commands, perform only syntax checking - -x Print commands before execution - -v, --version Print the version, platform and revision of Ion then exit + -f, --fake-interactive Use a fake interactive mode, where errors don't exit the shell + -h, --help Prints help information + -i, --interactive Force interactive mode + -n, --no-execute Do not execute any commands, perform only syntax checking + -x Print commands before execution + -v, --version Print the version, platform and revision of Ion then exit OPTIONS: -c <command> Evaluate given commands instead of reading from the commandline diff --git a/src/main.rs b/src/main.rs index efd507a1258ee14b9a35b0b659d07ece78f3231f..d66c44a3987b709f187223d796ff783ae423ae3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,6 +57,12 @@ struct CommandLineArgs { /// Print commands before execution #[cfg_attr(feature = "advanced_arg_parsing", structopt(short = "-x"))] print_commands: bool, + /// Use a fake interactive mode, where errors don't exit the shell + #[cfg_attr( + feature = "advanced_arg_parsing", + structopt(short = "-f", long = "--fake-interactive") + )] + fake_interactive: bool, /// Force interactive mode #[cfg_attr(feature = "advanced_arg_parsing", structopt(short = "-i", long = "--interactive"))] interactive: bool, @@ -88,8 +94,10 @@ fn parse_args() -> CommandLineArgs { let mut no_execute = false; let mut print_commands = false; let mut interactive = false; + let mut fake_interactive = false; let mut version = false; let mut additional_arguments = Vec::new(); + while let Some(arg) = args.next() { match arg.as_str() { "-o" => { @@ -115,6 +123,7 @@ fn parse_args() -> CommandLineArgs { process::exit(0); } "-i" | "--interactive" => interactive = true, + "-f" | "--fake-interactive" => fake_interactive = true, _ => { additional_arguments.push(arg); } @@ -124,6 +133,7 @@ fn parse_args() -> CommandLineArgs { key_bindings, print_commands, interactive, + fake_interactive, no_execute, command, version, @@ -213,6 +223,13 @@ fn main() { } interactive.add_callbacks(); interactive.execute_interactive(); + } else if command_line_args.fake_interactive { + let mut reader = BufReader::new(stdin()); + loop { + if let Err(err) = shell.execute_command(&mut reader) { + eprintln!("ion: {}", err); + } + } } else { shell.execute_command(BufReader::new(stdin())) } diff --git a/tests/help.out b/tests/help.out index 0f702d30d236d85bac966c29ea8f73b653475215..d13d7a67be104bd0b5425ad4f4f1c4c13dccc487 100644 --- a/tests/help.out +++ b/tests/help.out @@ -6,11 +6,12 @@ USAGE: ion [FLAGS] [OPTIONS] [args]... FLAGS: - -h, --help Prints help information - -i, --interactive Force interactive mode - -n, --no-execute Do not execute any commands, perform only syntax checking - -x Print commands before execution - -v, --version Print the version, platform and revision of Ion then exit + -f, --fake-interactive Use a fake interactive mode, where errors don't exit the shell + -h, --help Prints help information + -i, --interactive Force interactive mode + -n, --no-execute Do not execute any commands, perform only syntax checking + -x Print commands before execution + -v, --version Print the version, platform and revision of Ion then exit OPTIONS: -c <command> Evaluate given commands instead of reading from the commandline