Class: Bard::Command

Inherits:
Struct
  • Object
show all
Defined in:
lib/bard/command.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commandObject

Returns the value of attribute command

Returns:

  • (Object)

    the current value of command



4
5
6
# File 'lib/bard/command.rb', line 4

def command
  @command
end

#homeObject

Returns the value of attribute home

Returns:

  • (Object)

    the current value of home



4
5
6
# File 'lib/bard/command.rb', line 4

def home
  @home
end

#onObject

Returns the value of attribute on

Returns:

  • (Object)

    the current value of on



4
5
6
# File 'lib/bard/command.rb', line 4

def on
  @on
end

Class Method Details

.exec!(command, on: :local, home: false) ⇒ Object



15
16
17
# File 'lib/bard/command.rb', line 15

def self.exec! command, on: :local, home: false
  new(command, on, home).exec!
end

.run(command, on: :local, home: false, verbose: false, quiet: false) ⇒ Object



11
12
13
# File 'lib/bard/command.rb', line 11

def self.run command, on: :local, home: false, verbose: false, quiet: false
  new(command, on, home).run verbose:, quiet:
end

.run!(command, on: :local, home: false, verbose: false, quiet: false) ⇒ Object



7
8
9
# File 'lib/bard/command.rb', line 7

def self.run! command, on: :local, home: false, verbose: false, quiet: false
  new(command, on, home).run! verbose:, quiet:
end

Instance Method Details

#exec!Object



39
40
41
# File 'lib/bard/command.rb', line 39

def exec!
  exec full_command
end

#run(verbose: false, quiet: false) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bard/command.rb', line 25

def run verbose: false, quiet: false
  if verbose
    system full_command(quiet: quiet)
  else
    stdout, stderr, status = Open3.capture3(full_command)
    failed = status.to_i.nonzero?
    if failed && !quiet
      $stdout.puts stdout
      $stderr.puts stderr
    end
    !failed && stdout
  end
end

#run!(verbose: false, quiet: false) ⇒ Object



19
20
21
22
23
# File 'lib/bard/command.rb', line 19

def run! verbose: false, quiet: false
  if !run(verbose:, quiet:)
    raise Error.new(full_command)
  end
end