knative-extensions / knative-extensions/kn-plugin-event
Read CE from stdin, or file given by `--from` option
- Dominant language
- Go
- Stars
- 7
- Forks
- 30
- Avg merge
- 4h 26m
- Merged PRs (30d)
- 12
Description
## Summary
Introduce the `--from` option for build and send commands, which a user can use to load CE from a file. The option defaults to `-`, which means the STDIN. Introduce the `--from-format` option as well, which defaults to `json`.
## Description
The send and build commands may read the STDIN by default and expect there an event in JSON format.
This creates a nice and clean Unix-friendly flow:
```
$ kn event build --field a.b.c=foo | kn event send --to event-display
```
User might change that behavior with a new `--from` option:
```
$ kn event build --field a.b.c=foo -o json > event.json
# and later
$ kn event send --from event.json --to event-display
```
By adding the new `--from` option to the `build` sub-command as well, we could remove the event building options from `send` sub-command and keep nice and easy flow even for complex things (also with detecting tty on stdin/stdout we can automatically use json format instead of human-readable format):
```
$ kn event build --field a.b.c=foo
| some-ce-modifing-command
| kn event build --field a.d=bar
| kn event send --to pod:event-sender
```
_(The above example will build a basic CE with `a.b.c=foo` data, pass it to some command in JSON format, then add `a.d=bar` fields, and finally send it to K8s pod called event-sender)_
## Original description by @rhuss:
> For users who don't know the CE spec very well, it feels strange to specify the payload of an event with `--field event.data=something` (also too long). Also we should allow to pick up the date from a file (which is not needed for other fields).
>
> So from a UX pov I propose to introduce something like a `--data` and `--data-from` option.
Contributor guide
Research direction
Inspect the build and send command entry points and their existing input/output option handling first. Done means both commands support --from and --from-format with the stated defaults, preserve the stdin pipeline, and allow reading an event from a file as shown in the examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100