diff options
author | John Keiser <jkeiser@opscode.com> | 2014-04-30 09:51:19 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2014-04-30 09:51:19 -0700 |
commit | 33d86aa1217877f6eae000edd7b45741c9a754c3 (patch) | |
tree | 1d2e8d532455f34666fb9385b7a9c77aa4b1223e /lib/chef/event_dispatch | |
parent | 56d6725b9fd1133d3a953b55096460fb4b219679 (diff) | |
download | chef-33d86aa1217877f6eae000edd7b45741c9a754c3.tar.gz |
Add ability to stream (and indent) command output
Diffstat (limited to 'lib/chef/event_dispatch')
-rw-r--r-- | lib/chef/event_dispatch/base.rb | 14 | ||||
-rw-r--r-- | lib/chef/event_dispatch/events_output_stream.rb | 29 |
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/chef/event_dispatch/base.rb b/lib/chef/event_dispatch/base.rb index 82beefeec9..bfd4503097 100644 --- a/lib/chef/event_dispatch/base.rb +++ b/lib/chef/event_dispatch/base.rb @@ -277,6 +277,20 @@ class Chef def resource_updated(resource, action) end + # A stream has opened. + def stream_opened(stream, options = {}) + end + + # A stream has closed. + def stream_closed(stream, options = {}) + end + + # A chunk of data from a stream. The stream is managed by "stream," which + # can be any tag whatsoever. Data in different "streams" may not be placed + # on the same line or even sent to the same console. + def stream_output(stream, output, options = {}) + end + # Called before handlers run def handlers_start(handler_count) end diff --git a/lib/chef/event_dispatch/events_output_stream.rb b/lib/chef/event_dispatch/events_output_stream.rb new file mode 100644 index 0000000000..8de9b0fed1 --- /dev/null +++ b/lib/chef/event_dispatch/events_output_stream.rb @@ -0,0 +1,29 @@ +class Chef + module EventDispatch + class EventsOutputStream + # This is a fake stream that connects to events. + # + # == Arguments + # events: the EventDispatch object to send data to (run_context.events) + # options is a hash with these possible options: + # - name: a string that identifies the stream to the user. Preferably short. + + def initialize(events, options = {}) + @events = events + @options = options + events.stream_opened(self, options) + end + + attr_reader :options + attr_reader :events + + def print(str) + events.stream_output(self, str, options) + end + + def close + events.stream_closed(self, options) + end + end + end +end |