module CommandKit::OS

Provides methods for determining the current OS.

## Examples

require 'command_kit/command'
require 'command_kit/os'

class Command < CommandKit::Command

  include CommandKit::OS

  def main(*argv)
    if linux?
      # ...
    elsif macos?
      # ...
    elsif freebsd?
      # ...
    elsif windows?
      # ...
    end
  end

end

Attributes

os[R]

The current OS.

@return [:linux, :macos, :freebsd, :openbsd, :netbsd, :windows, nil]

@api public

@since 0.2.0

Public Class Methods

new(os: self.class.os, **kwargs) click to toggle source

Initializes the command.

@param [:linux, :macos, :freebsd, :openbsd, :netbsd, :windows, nil] os

Overrides the default OS.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments.

@api public

@since 0.2.0

Calls superclass method
# File lib/command_kit/os.rb, line 97
def initialize(os: self.class.os, **kwargs)
  super(**kwargs)

  @os = os
end

Public Instance Methods

bsd?() click to toggle source

Determines if the current OS is BSD based.

@return [Boolean]

@since 0.2.0

@api public

# File lib/command_kit/os.rb, line 173
def bsd?
  freebsd? || openbsd? || netbsd?
end
freebsd?() click to toggle source

Determines if the current OS is FreeBSD.

@return [Boolean]

@api public

@since 0.2.0

# File lib/command_kit/os.rb, line 134
def freebsd?
  @os == :freebsd
end
linux?() click to toggle source

Determines if the current OS is Linux.

@return [Boolean]

@api public

# File lib/command_kit/os.rb, line 110
def linux?
  @os == :linux
end
macos?() click to toggle source

Determines if the current OS is macOS.

@return [Boolean]

@api public

# File lib/command_kit/os.rb, line 121
def macos?
  @os == :macos
end
netbsd?() click to toggle source

Determines if the current OS is NetBSD.

@return [Boolean]

@api public

@since 0.2.0

# File lib/command_kit/os.rb, line 160
def netbsd?
  @os == :netbsd
end
openbsd?() click to toggle source

Determines if the current OS is OpenBSD.

@return [Boolean]

@api public

@since 0.2.0

# File lib/command_kit/os.rb, line 147
def openbsd?
  @os == :openbsd
end
unix?() click to toggle source

Determines if the current OS is UNIX based.

@return [Boolean]

@since 0.2.0

@api public

# File lib/command_kit/os.rb, line 186
def unix?
  linux? || macos? || bsd?
end
windows?() click to toggle source

Determines if the current OS is Windows.

@return [Boolean]

@api public

# File lib/command_kit/os.rb, line 197
def windows?
  @os == :windows
end