Remove fallback to reading stdin if no message body is given

To read a message from stdin, use the `--message-from-stdin` flag
This commit is contained in:
AsamK 2022-06-21 13:55:01 +02:00
parent 1ea4309a2a
commit 4120630309
3 changed files with 5 additions and 4 deletions

View file

@ -224,7 +224,6 @@ Specify the recipient group ID in base64 encoding.
*-m* MESSAGE, *--message* MESSAGE::
Specify the message.
Currently, signal-cli reads the message from stdin if `-m` is missing, but this will change in a future version and the explicit flag `--message-from-stdin` should be used instead.
*--message-from-stdin*::
Read the message from standard input.

View file

@ -200,7 +200,7 @@ for OUTPUT in "plain-text" "json"; do
run_main -a "$NUMBER_1" --output="$OUTPUT" send "$NUMBER_2" -m hi
run_main -a "$NUMBER_2" --output="$OUTPUT" send "$NUMBER_1" -m hi
run_main -a "$NUMBER_1" --output="$OUTPUT" send -g "$GROUP_ID" -m hi -a LICENSE --mention "1:1:$NUMBER_2"
TIMESTAMP=$(uname -a | run_main -a "$NUMBER_1" --output=json send "$NUMBER_2" | jq '.timestamp')
TIMESTAMP=$(uname -a | run_main -a "$NUMBER_1" --output=json send --message-from-stdin "$NUMBER_2" | jq '.timestamp')
run_main -a "$NUMBER_2" --output="$OUTPUT" sendReaction "$NUMBER_1" -e 🍀 -a "$NUMBER_1" -t "$TIMESTAMP"
run_main -a "$NUMBER_1" --output="$OUTPUT" remoteDelete "$NUMBER_2" -t "$TIMESTAMP"
run_main -a "$NUMBER_2" --output="$OUTPUT" receive

View file

@ -120,13 +120,15 @@ public class SendCommand implements JsonRpcLocalCommand {
var messageText = ns.getString("message");
final var readMessageFromStdin = ns.getBoolean("message-from-stdin") == Boolean.TRUE;
if (readMessageFromStdin || (messageText == null && sticker == null)) {
if (readMessageFromStdin) {
logger.debug("Reading message from stdin...");
try {
messageText = IOUtils.readAll(System.in, IOUtils.getConsoleCharset());
} catch (IOException e) {
throw new UserErrorException("Failed to read message from stdin: " + e.getMessage());
}
} else if (messageText == null) {
messageText = "";
}
List<String> attachments = ns.getList("attachment");
@ -169,7 +171,7 @@ public class SendCommand implements JsonRpcLocalCommand {
}
try {
var results = m.sendMessage(new Message(messageText == null ? "" : messageText,
var results = m.sendMessage(new Message(messageText,
attachments,
mentions,
Optional.ofNullable(quote),