Draft
Conversation
This introduces an 'event' api where events can be 'emitted' by
commands, which goes through the following pipeline:
- a set of callbacks are registered with each command (similar to
script hooks) by name
- when an event is emitted, one of these names must be provided
- the data is fed to the registered callback, which returns a `Report`
which describes how to log and serialize the data
- this report is taken by the event api and depending on whether the
structured output flag is set will either
- serialize the data to json (with a very basic hand rolled encoder)
and write it to stdout
- log it with the given `Logger`
The basic structure is as such:
command.new {
name = "my-cool-command",
description = ":D",
exec = function(): integer
event.emit("cool_event", { adjective = "cool" })
event.emit("cool_event", { adjective = "neat" })
return 0
end,
events = {
cool_event = function(params: {string:any}): event.Report
return {
log_format = "This is from a %(adjective) event happening",
parameters = { adjective = params.adjective },
},
end,
},
}
Which with unstructured output will produce
$ cyan my-cool-command
Info This is from a cool event happening
Info This is from a neat event happening
But with structured output will produce
$ cyan --structured-output my-cool-command
{"event":"cool_event","data":{"adjective":"cool"}}
{"event":"cool_event","data":{"adjective":"neat"}}
This commit adds a little bit of this as a proof of concept to the
current build command, but not for everything that `build` can log.
But running
$ cyan build --update-all --structured-output --no-script
will produce nicely structured output, and some data massaging with jq
is easy enough. The following will produce an array of files that were
written by build
$ cyan build --update-all --structured-output --no-script | jq -n '[inputs | select(.event == "wrote_file") | .data.file]'
a19924f to
14f4fc4
Compare
Member
Author
|
Relevant issue #21 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This introduces an 'event' api where events can be 'emitted' by
commands, which goes through the following pipeline:
script hooks) by name
Reportwhich describes how to log and serialize the data
structured output flag is set will either
and write it to stdout
LoggerThe basic structure is as such:
Which with unstructured output will produce
But with structured output will produce
This commit adds a little bit of this as a proof of concept to the
current build command, but not for everything that
buildcan log.But running
will produce nicely structured output, and some data massaging with jq
is easy enough. The following will produce an array of files that were
written by build