Class: Kuby::CLIBase

Inherits:
Object
  • Object
show all
Defined in:
lib/kuby/cli_base.rb

Direct Known Subclasses

Docker::CLI

Instance Method Summary collapse

Instance Method Details

#after_execute(&block) ⇒ Object

T::Sig::WithoutRuntime.sig { params(block: AfterCallback).void }



28
29
30
31
32
# File 'lib/kuby/cli_base.rb', line 28

def after_execute(&block)
  # @after_execute = T.let(@after_execute, T.nilable(T::Array[AfterCallback]))
  @after_execute ||= []
  @after_execute << block
end

#before_execute(&block) ⇒ Object

T::Sig::WithoutRuntime.sig { params(block: BeforeCallback).void }



21
22
23
24
25
# File 'lib/kuby/cli_base.rb', line 21

def before_execute(&block)
  # @before_execute = T.let(@before_execute, T.nilable(T::Array[BeforeCallback]))
  @before_execute ||= []
  @before_execute << block
end

#last_statusObject

T::Sig::WithoutRuntime.sig { returns(T.nilable(Process::Status)) }



16
17
18
# File 'lib/kuby/cli_base.rb', line 16

def last_status
  Thread.current[status_key]
end

#stderrObject

T::Sig::WithoutRuntime.sig { returns(T.nilable(T.any(IO, StringIO))) }



63
64
65
# File 'lib/kuby/cli_base.rb', line 63

def stderr
  Thread.current[stderr_key] || STDERR
end

#stderr=(new_stderr) ⇒ Object

T::Sig::WithoutRuntime.sig { params(new_stderr: T.nilable(T.any(IO, StringIO))).void }



68
69
70
# File 'lib/kuby/cli_base.rb', line 68

def stderr=(new_stderr)
  Thread.current[stderr_key] = new_stderr
end

#stdoutObject

T::Sig::WithoutRuntime.sig { returns(T.nilable(T.any(IO, StringIO))) }



53
54
55
# File 'lib/kuby/cli_base.rb', line 53

def stdout
  Thread.current[stdout_key] || STDOUT
end

#stdout=(new_stdout) ⇒ Object

T::Sig::WithoutRuntime.sig { params(new_stdout: T.nilable(T.any(IO, StringIO))).void }



58
59
60
# File 'lib/kuby/cli_base.rb', line 58

def stdout=(new_stdout)
  Thread.current[stdout_key] = new_stdout
end

#with_pipes(out = STDOUT, err = STDERR, &block) ⇒ Object

T::Sig::WithoutRuntime.sig

params(
  out: T.any(IO, StringIO),
  err: T.any(IO, StringIO),
  block: T.proc.void
).void



41
42
43
44
45
46
47
48
49
50
# File 'lib/kuby/cli_base.rb', line 41

def with_pipes(out = STDOUT, err = STDERR, &block)
  previous_stdout = self.stdout
  previous_stderr = self.stderr
  self.stdout = out
  self.stderr = err
  yield
ensure
  self.stdout = previous_stdout
  self.stderr = previous_stderr
end