Sha256: 3ab70bcc8da666fa263cb7a72f37565f5fb1165a78de7b34bb505d0f16e4d4e4

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module Net
  module SSH
    class SessionCommand
      attr_reader   :command, :output, :exit_code
      attr_reader   :duration
      attr_accessor :start_time, :finish_time
      
      # Initialize a new session command
      # @param command [String] original command
      # @param output [String] command execution output
      # @param exit_code [Integer] command execution exit code
      # @param duration [Float] execution time in seconds
      def initialize(command, output, exit_code, duration=0)
        @command   = command
        @output    = output || ''
        @exit_code = Integer(exit_code) rescue 1
        @duration  = Float(duration)
      end

      # Check if exit code is successful
      # @return [Boolean]
      def success?
        exit_code == 0
      end

      # Check if exit code is not successful
      # @return [Boolean]
      def failure?
        exit_code != 0
      end

      # Get command string representation
      # @return [String]
      def to_s
        "[#{command}] => #{exit_code}, #{output.to_s.bytesize} bytes, #{duration} seconds"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
net-ssh-session-0.1.0 lib/net/ssh/session_command.rb