Class: Llv::CLI
- Inherits:
-
Object
- Object
- Llv::CLI
- Defined in:
- lib/llv/cli.rb
Constant Summary collapse
- DEFAULTS =
{ port: 9292, host: "127.0.0.1", limit: 500, # Replay the whole file by default — when you launch llv you almost # always want to see what's already there. Pass --tail to opt out. from_start: true, tui: false, open_browser: true }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #install_traps ⇒ Object
- #run ⇒ Object
Constructor Details
Class Method Details
.start(argv) ⇒ Object
18 19 20 |
# File 'lib/llv/cli.rb', line 18 def self.start(argv) new(argv).run end |
Instance Method Details
#install_traps ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/llv/cli.rb', line 59 def install_traps shutdown = lambda do |_signo = nil| $stderr.puts "\nllv: stopping" # Process.exit! is the only way out of Puma's Launcher loop once it has # decided to "gracefully" stop and is blocked on its own threads. Process.exit!(0) end Signal.trap("INT", &shutdown) Signal.trap("TERM", &shutdown) end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/llv/cli.rb', line 27 def run parse! path = @argv.shift unless path warn "usage: llv [options] PATH/TO/development.log" exit 1 end store = GroupStore.new(limit: @options[:limit]) parser = Parser.new tailer = Tailer.new(path, from_start: @options[:from_start]) # Tailer#each_line returns immediately after starting the listener + # poll threads, so we don't need an extra wrapper thread. tailer.each_line do |line| event = parser.parse(line) store.ingest(event) end @tailer = tailer if @options[:tui] require_relative "tui" install_traps Tui::Program.new(store: store).run else require_relative "web" start_web(store) end ensure @tailer&.stop end |