Class: Diogenes::Cli::Watch

Inherits:
Object
  • Object
show all
Defined in:
lib/diogenes/cli/watch.rb

Constant Summary collapse

DIOGENES_DIR =

: String

".diogenes"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv:, cwd:, out:, err:) ⇒ Watch

: (argv: Array, cwd: String, out: IO, err: IO) -> void



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

def initialize(argv:, cwd:, out:, err:)
  @argv = argv #: Array[String]
  @cwd = cwd #: String
  @out = out #: IO
  @err = err #: IO
end

Class Method Details

.run(argv:, cwd:, out:, err:, **_opts) ⇒ Object

: (argv: Array, cwd: String, out: IO, err: IO, **untyped) -> Integer



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

def self.run(argv:, cwd:, out:, err:, **_opts)
  new(argv:, cwd:, out:, err:).run
end

Instance Method Details

#runObject

: () -> Integer



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/diogenes/cli/watch.rb', line 25

def run
  diogenes_dir = File.join(@cwd, DIOGENES_DIR)
  unless Dir.exist?(diogenes_dir)
    @err.puts "No #{DIOGENES_DIR}/ found. Run `diogenes init` first."
    return 1
  end

  @out.puts "Watching #{DIOGENES_DIR}/ for changes. Press Ctrl+C to stop."
  @out.puts

  listener = build_listener(diogenes_dir)
  listener.start
  sleep
  0
rescue Interrupt
  @out.puts "\nStopped."
  0
end