From 33494c0e29cd42cf921b01917fe710522767d20d Mon Sep 17 00:00:00 2001 From: Joshua Yanovski Date: Tue, 11 May 2021 04:13:22 -0700 Subject: [PATCH] More fixes to stdin input. Adding tty makes sure docker attach won't be accidentally detached by ctrl-C (there are better ways of doing this but this one works for now) shell-words more closely emulates Bash's tokenizer rules (but without doing things like environment variable expansion) which allows us to use multiline strings as reasons, etc. Unfortunately entering newlines still won't work the way we've written things since shell-words does not right now give enough information to incrementally build up a valid string, just says there was a tokenizing error; but maybe in the future we can fix that. --- Cargo.lock | 7 +++++++ server-cli/Cargo.toml | 1 + server-cli/docker-compose.yml | 1 + server-cli/src/cli.rs | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 1ff27e939b..fd55c47fdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4595,6 +4595,12 @@ dependencies = [ "libc", ] +[[package]] +name = "shell-words" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fa3938c99da4914afedd13bf3d79bcb6c277d1b2c398d23257a304d9e1b074" + [[package]] name = "shellexpand" version = "2.1.0" @@ -5783,6 +5789,7 @@ dependencies = [ "num_cpus", "ron", "serde", + "shell-words", "signal-hook 0.3.8", "structopt", "tokio", diff --git a/server-cli/Cargo.toml b/server-cli/Cargo.toml index a2563f89c1..5efc0363c6 100644 --- a/server-cli/Cargo.toml +++ b/server-cli/Cargo.toml @@ -35,6 +35,7 @@ structopt = "0.3.13" crossterm = "0.19" lazy_static = "1" signal-hook = "0.3.6" +shell-words = "1.0.0" tracing = { version = "0.1", default-features = false } ron = {version = "0.6", default-features = false} serde = {version = "1.0", features = [ "rc", "derive" ]} diff --git a/server-cli/docker-compose.yml b/server-cli/docker-compose.yml index c9c58f2061..6faf73fb84 100644 --- a/server-cli/docker-compose.yml +++ b/server-cli/docker-compose.yml @@ -4,6 +4,7 @@ services: game-server: image: registry.gitlab.com/veloren/veloren/server-cli:nightly stdin_open: true + tty: true container_name: veloren-game-server-master ports: - "14004:14004" diff --git a/server-cli/src/cli.rs b/server-cli/src/cli.rs index 0e03158d2f..eb5eeeb0c6 100644 --- a/server-cli/src/cli.rs +++ b/server-cli/src/cli.rs @@ -120,7 +120,7 @@ pub struct ArgvApp { } pub fn parse_command(input: &str, msg_s: &mut Sender) { - match TuiApp::from_iter_safe(input.split_whitespace()) { + match TuiApp::from_iter_safe(shell_words::split(input).unwrap_or_default()) { Ok(message) => { msg_s .send(message.command)