Exception: WifiWand::CommandExecutor::OsCommandError

Inherits:
Error
  • Object
show all
Defined in:
lib/wifi_wand/services/command_executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#append_help_hint?, #exception, #message_for_display

Constructor Details

#initialize(result: nil, exitstatus: nil, termsig: nil, command: nil, text: nil) ⇒ OsCommandError

Returns a new instance of OsCommandError.



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/wifi_wand/services/command_executor.rb', line 370

def initialize(result: nil, exitstatus: nil, termsig: nil, command: nil, text: nil)
  @result = result || OsCommandResult.new(
    stdout:          text,
    stderr:          '',
    combined_output: text,
    exitstatus:      exitstatus,
    termsig:         termsig,
    command:         command,
    duration:        nil
  )

  @exitstatus = @result.exitstatus
  @termsig = @result.termsig
  @command = @result.command
  @text = @result.combined_output
  super(@text)
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



368
369
370
# File 'lib/wifi_wand/services/command_executor.rb', line 368

def command
  @command
end

#exitstatusObject (readonly)

Returns the value of attribute exitstatus.



368
369
370
# File 'lib/wifi_wand/services/command_executor.rb', line 368

def exitstatus
  @exitstatus
end

#resultObject (readonly)

Returns the value of attribute result.



368
369
370
# File 'lib/wifi_wand/services/command_executor.rb', line 368

def result
  @result
end

#termsigObject (readonly)

Returns the value of attribute termsig.



368
369
370
# File 'lib/wifi_wand/services/command_executor.rb', line 368

def termsig
  @termsig
end

#textObject (readonly)

Returns the value of attribute text.



368
369
370
# File 'lib/wifi_wand/services/command_executor.rb', line 368

def text
  @text
end

Instance Method Details

#display_messageObject



388
389
390
391
392
393
394
# File 'lib/wifi_wand/services/command_executor.rb', line 388

def display_message
  lines = []
  lines << message unless message.empty?
  lines << "Command failed: #{command}"
  lines << result.termination_status
  lines.join("\n")
end

#to_hObject



396
397
398
399
400
# File 'lib/wifi_wand/services/command_executor.rb', line 396

def to_h
  data = { exitstatus: exitstatus, command: command, text: text }
  data[:termsig] = termsig if termsig
  data
end