Skip to main content

read_encoded_json_input

Function read_encoded_json_input 

Source
fn read_encoded_json_input(
    positional: Option<String>,
    stdin_eligible: bool,
) -> Result<Option<String>>
Expand description

Resolve the raw full-object JSON input for create/edit.

Precedence mirrors the legacy CLI: an explicit positional argument wins; otherwise, when stdin_eligible (the caller supplied no other flag that already fully specifies the command) and stdin is piped (not an interactive terminal), read it. When stdin is a TTY, no positional was given, or stdin_eligible is false, there is no JSON input and the flag-only path runs.

stdin_eligible exists so a fully flag-specified create/edit never touches stdin: an unconditional read would block (or silently swallow bytes) when stdin is a non-TTY pipe that stays open, e.g. ssh host 'bw send edit --itemid <id> --deleteInDays 3' or docker run -i. The is_terminal guard separately keeps an interactive shell (and the test harness, which doesn’t pipe stdin) from blocking on a read.