Module: CommandKit::Sudo

Includes:
OS
Included in:
PackageManager
Defined in:
lib/command_kit/sudo.rb

Overview

Allows running commands with sudo.

Since:

  • 0.2.0

Instance Attribute Summary

Attributes included from OS

#os

Instance Method Summary collapse

Methods included from OS

#bsd?, #freebsd?, #initialize, #linux?, #macos?, #netbsd?, #openbsd?, #unix?, #windows?

Methods included from OS::ModuleMethods

#included

Instance Method Details

#sudo(command, *arguments) ⇒ Boolean?

Runs the command under sudo, if the user isn't already root.

Parameters:

  • command (String)

    The command to execute.

  • arguments (Array<String>)

    Additional arguments for the command.

Returns:

  • (Boolean, nil)

    Specifies whether the command was successfully ran or not.

Since:

  • 0.2.0



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/command_kit/sudo.rb', line 28

def sudo(command,*arguments)
  if windows?
    system('runas','/user:administrator',command,*arguments)
  else
    if Process.uid == 0
      system(command,*arguments)
    else
      system('sudo',command,*arguments)
    end
  end
end