Sha256: d69bd7b41467b2789dff016bc085e7ca0499affa3fb34d1d89cc7ffc8cfc69db

Contents?: true

Size: 1.63 KB

Versions: 38

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module CommandLine
  # The result returned from running {CommandLine.command_line}.
  class Result
    def initialize(stdout, stderr, status)
      @stdout = stdout
      @stderr = stderr
      @status = status
    end

    # The complete contents of stdout after running the application.
    #
    # @example
    #   command_line('echo', 'hi').stdout
    #   # => "hi\n"
    #
    # @return [String]
    attr_reader :stdout

    # The complete contents of stderr after running the application.
    #
    # @example
    #   command_line('grep').stderr
    #   # => "usage: grep ..."
    #
    # @return [String]
    attr_reader :stderr

    # Returns `true` if the application exited normally.
    #
    # @example
    #   command_line('grep').exited?
    #
    # @return [Boolean]
    def exited?
      @status.exited?
    end

    # The numeric exit status of the application if it exited normally.
    #
    # @example
    #   command_line('echo', 'hi').exitstatus
    #   # => 0
    #   command_line('grep').exitstatus
    #   # => 2
    #
    # @return [Integer, nil]
    def exitstatus
      @status.exitstatus
    end

    # Returns `true` if the command exited normally with a success status.
    #
    # @example
    #   command_line('echo', 'hi').success?
    #   # => true
    #
    # @return [Boolean]
    def success?
      !@status.nil? && @status.success?
    end

    # Returns `true` if the command failed to exit normally or exited with a
    # failing status.
    #
    # @example
    #   command_line('grep').failure?
    #   # => true
    #
    # @return [Boolean]
    def failure?
      !success?
    end
  end
end

Version data entries

38 entries across 38 versions & 2 rubygems

Version Path
qiita_org-0.1.35 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.25 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.24 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.23 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.22 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.21 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.20 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.19 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.18 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.17 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb
qiita_org-0.1.16 gems/ruby/2.7.0/gems/command_line-2.0.1/lib/command_line/result.rb