Skip to content

fix: read body from stdin when --tags or template is set - #1

Open
shichenshuo-star wants to merge 1 commit into
trtyr:masterfrom
shichenshuo-star:fix/create-stdin-tags-body
Open

fix: read body from stdin when --tags or template is set#1
shichenshuo-star wants to merge 1 commit into
trtyr:masterfrom
shichenshuo-star:fix/create-stdin-tags-body

Conversation

@shichenshuo-star

Copy link
Copy Markdown

Problem

obscli note create <name> --tags a,b silently drops the note body when the
content is piped via stdin. The -c/--content help says "(reads from stdin if
not provided)"
, but with --tags the body never appears in the created file.

Reproduction

mkdir -p /tmp/v/.obsidian
printf '# Hello\n\nbody\n' | obscli --vault /tmp/v note create "t" --tags a,b
cat /tmp/v/t.md
# Only frontmatter is written; the body is gone.

Root cause

In src/plugins/files.rs, cmd_create reads stdin only when note_content.is_empty():

} else if note_content.is_empty() {
    let mut buffer = String::new();
    if !is_terminal::is_terminal(io::stdin()) {
        io::stdin().read_to_string(&mut buffer)?;
        note_content = buffer;
    }
}

But when --tags (or -t/--template) is provided, frontmatter is written into
note_content before this block runs, so the guard is false and stdin is
never read — the body is silently dropped.

Fix

Read stdin whenever -c/--content is not provided and stdin is not a TTY,
appending the body after any existing frontmatter:

} else if !is_terminal::is_terminal(io::stdin()) {
    let mut buffer = String::new();
    io::stdin().read_to_string(&mut buffer)?;
    note_content.push_str(&buffer);
}

Verification

Tested against a local build (debug):

  • --tags a,b + stdin → frontmatter + full body ✅
  • stdin without tags → body ✅ (no regression)
  • -c + --tags → frontmatter + body ✅ (no regression)

The stdin guard used note_content.is_empty(), but --tags or a template
populate note_content with frontmatter before the body is read, so stdin
was silently skipped and the note body was dropped.

Now stdin is read whenever -c/--content is not provided and stdin is not
a TTY, appending the body after any existing frontmatter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant