Skip to content

fix: read iCalendar from stdin when not a terminal#6

Open
cradnovich wants to merge 1 commit into
pimalaya:masterfrom
cradnovich:fix/stdin-create
Open

fix: read iCalendar from stdin when not a terminal#6
cradnovich wants to merge 1 commit into
pimalaya:masterfrom
cradnovich:fix/stdin-create

Conversation

@cradnovich

Copy link
Copy Markdown

Problem

items create and events create unconditionally call env::var("EDITOR"), which fails with "environment variable not found" when $EDITOR is not set. This makes it impossible to create items programmatically by piping iCalendar content via stdin:

cat event.ics | calendula items create <CALENDAR-ID>

Fix

Check io::stdin().is_terminal() before deciding the input method:

  • Piped (non-TTY): read iCalendar content directly from stdin
  • Interactive (TTY): open $EDITOR with a template (existing behavior), with an improved error message if $EDITOR is not set

Both src/item/command/create.rs and src/event/command/create.rs are fixed (they had identical code).

Testing

Tested against iCloud CalDAV — created, verified, and deleted an event via stdin pipe successfully.

items create and events create now detect whether stdin is a terminal.
When piped (non-TTY), they read iCalendar content directly from stdin
instead of requiring $EDITOR. This enables scripted/programmatic
calendar item creation:

    cat event.ics | calendula items create <CALENDAR-ID>

When running interactively, behavior is unchanged ($EDITOR opens
with a template). The error message for missing $EDITOR is also
improved to suggest the stdin alternative.
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