Skip to content
Snippets Groups Projects
Commit 9f31a428 authored by AdminXVII's avatar AdminXVII Committed by Michael Aaron Murphy
Browse files

feat: Add a fake interactive mode, where stdin is not a terminal

IDEs like IntelliJ run "interactive" scripts without a tty. To make it
possible to use Ion without needing to restart it at eache error, add
the '-f' flag, which will use the stdin like a file, but won't exit on
error. This should NOT be used for being lazy with scripts
parent ebed18aa
No related branches found
No related tags found
No related merge requests found
...@@ -34,11 +34,12 @@ USAGE: ...@@ -34,11 +34,12 @@ USAGE:
ion [FLAGS] [OPTIONS] [args]... ion [FLAGS] [OPTIONS] [args]...
FLAGS: FLAGS:
-h, --help Prints help information -f, --fake-interactive Use a fake interactive mode, where errors don't exit the shell
-i, --interactive Force interactive mode -h, --help Prints help information
-n, --no-execute Do not execute any commands, perform only syntax checking -i, --interactive Force interactive mode
-x Print commands before execution -n, --no-execute Do not execute any commands, perform only syntax checking
-v, --version Print the version, platform and revision of Ion then exit -x Print commands before execution
-v, --version Print the version, platform and revision of Ion then exit
OPTIONS: OPTIONS:
-c <command> Evaluate given commands instead of reading from the commandline -c <command> Evaluate given commands instead of reading from the commandline
......
...@@ -57,6 +57,12 @@ struct CommandLineArgs { ...@@ -57,6 +57,12 @@ struct CommandLineArgs {
/// Print commands before execution /// Print commands before execution
#[cfg_attr(feature = "advanced_arg_parsing", structopt(short = "-x"))] #[cfg_attr(feature = "advanced_arg_parsing", structopt(short = "-x"))]
print_commands: bool, 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 /// Force interactive mode
#[cfg_attr(feature = "advanced_arg_parsing", structopt(short = "-i", long = "--interactive"))] #[cfg_attr(feature = "advanced_arg_parsing", structopt(short = "-i", long = "--interactive"))]
interactive: bool, interactive: bool,
...@@ -88,8 +94,10 @@ fn parse_args() -> CommandLineArgs { ...@@ -88,8 +94,10 @@ fn parse_args() -> CommandLineArgs {
let mut no_execute = false; let mut no_execute = false;
let mut print_commands = false; let mut print_commands = false;
let mut interactive = false; let mut interactive = false;
let mut fake_interactive = false;
let mut version = false; let mut version = false;
let mut additional_arguments = Vec::new(); let mut additional_arguments = Vec::new();
while let Some(arg) = args.next() { while let Some(arg) = args.next() {
match arg.as_str() { match arg.as_str() {
"-o" => { "-o" => {
...@@ -115,6 +123,7 @@ fn parse_args() -> CommandLineArgs { ...@@ -115,6 +123,7 @@ fn parse_args() -> CommandLineArgs {
process::exit(0); process::exit(0);
} }
"-i" | "--interactive" => interactive = true, "-i" | "--interactive" => interactive = true,
"-f" | "--fake-interactive" => fake_interactive = true,
_ => { _ => {
additional_arguments.push(arg); additional_arguments.push(arg);
} }
...@@ -124,6 +133,7 @@ fn parse_args() -> CommandLineArgs { ...@@ -124,6 +133,7 @@ fn parse_args() -> CommandLineArgs {
key_bindings, key_bindings,
print_commands, print_commands,
interactive, interactive,
fake_interactive,
no_execute, no_execute,
command, command,
version, version,
...@@ -213,6 +223,13 @@ fn main() { ...@@ -213,6 +223,13 @@ fn main() {
} }
interactive.add_callbacks(); interactive.add_callbacks();
interactive.execute_interactive(); 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 { } else {
shell.execute_command(BufReader::new(stdin())) shell.execute_command(BufReader::new(stdin()))
} }
......
...@@ -6,11 +6,12 @@ USAGE: ...@@ -6,11 +6,12 @@ USAGE:
ion [FLAGS] [OPTIONS] [args]... ion [FLAGS] [OPTIONS] [args]...
FLAGS: FLAGS:
-h, --help Prints help information -f, --fake-interactive Use a fake interactive mode, where errors don't exit the shell
-i, --interactive Force interactive mode -h, --help Prints help information
-n, --no-execute Do not execute any commands, perform only syntax checking -i, --interactive Force interactive mode
-x Print commands before execution -n, --no-execute Do not execute any commands, perform only syntax checking
-v, --version Print the version, platform and revision of Ion then exit -x Print commands before execution
-v, --version Print the version, platform and revision of Ion then exit
OPTIONS: OPTIONS:
-c <command> Evaluate given commands instead of reading from the commandline -c <command> Evaluate given commands instead of reading from the commandline
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment