Class: WhatsAppNotifier::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/whatsapp_notifier/cli.rb

Overview

Command-line entry point (‘whatsapp_notifier doctor|service`). Lives in lib (the bin stub just calls CLI.start) so it can be unit-tested.

Constant Summary collapse

CHROMIUM_AUTODETECT_PATHS =

Probed when PUPPETEER_EXECUTABLE_PATH is unset — the same Linux paths Doctor accepts (Debian names the binary ‘chromium`, Ubuntu/snap-free builds `chromium-browser`).

["/usr/bin/chromium", "/usr/bin/chromium-browser"].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/whatsapp_notifier/cli.rb', line 12

def self.exit_on_failure?
  true
end

Instance Method Details

#doctorObject

Raises:

  • (Thor::Error)


17
18
19
20
21
22
# File 'lib/whatsapp_notifier/cli.rb', line 17

def doctor
  ok = WhatsAppNotifier::Doctor.run
  raise Thor::Error, "Doctor checks failed. Apply fixes above and run again." unless ok

  puts "All checks passed."
end

#serviceObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/whatsapp_notifier/cli.rb', line 27

def service
  service_path = WhatsAppNotifier.service_path
  puts "Starting WhatsApp Notifier Service from #{service_path}..."

  configure_port
  ENV["WHATSAPP_SESSION_DIR"] ||= WhatsAppNotifier::Doctor.session_dir
  ensure_bun!
  autodetect_chromium

  Dir.chdir(service_path) do
    install_dependencies(service_path)
    exec("bun index.ts")
  end
end