Class: PromptWarden::CLI::Tail
- Inherits:
-
Object
- Object
- PromptWarden::CLI::Tail
- Defined in:
- lib/prompt_warden/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Tail
constructor
A new instance of Tail.
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ Tail
Returns a new instance of Tail.
92 93 94 |
# File 'lib/prompt_warden/cli.rb', line 92 def initialize() @options = end |
Class Method Details
.run(args = ARGV) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/prompt_warden/cli.rb', line 82 def self.run(args = ARGV) = (args) # Configure PromptWarden if not already configured configure_prompt_warden # Run the tail command new().run end |
Instance Method Details
#run ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/prompt_warden/cli.rb', line 96 def run puts "š PromptWarden CLI - Real-time event monitoring" puts "Press Ctrl+C to exit" puts "-" * 80 # Create a mock buffer for CLI mode @cli_buffer = CLIBuffer.new # Override the real buffer temporarily @original_buffer = PromptWarden.send(:buffer) PromptWarden.define_singleton_method(:buffer) { @cli_buffer } # Set up event listener @event_count = 0 @cli_buffer.on_event do |event| next unless EventFilter.matches?(event, @options) @event_count += 1 puts EventFormatter.format(event, json: @options[:json]) exit 0 if @options[:limit] && @event_count >= @options[:limit] end # Show recent events if not following unless @options[:follow] show_recent_events return end # Follow mode - wait for events if @options[:follow] puts "Waiting for events... (use --no-follow to see recent events only)" # Keep the process alive loop do sleep 1 end end rescue Interrupt puts "\nš Goodbye!" rescue => e puts "ā Error: #{e.}" puts e.backtrace if ENV['DEBUG'] exit 1 ensure # Restore original buffer PromptWarden.define_singleton_method(:buffer) { @original_buffer } end |