Skip to content

🔒 CanUseSudo

Checks whether the sudo command is available on the current system.

When to Use

Use this when installing/uninstalling requires writing to system directories and you need to decide whether to prefix commands with sudo. ✅

Signature

go
func CanUseSudo() bool

Parameters

ParameterTypeDescription
NonePackage-level function, takes no parameters

Return Value

  • bool: true means sudo exists in the PATH; false means it is unavailable.

Example

go
package main

import (
	"fmt"

	"github.com/scagogogo/composer-skills/pkg/installer"
)

func main() {
	if installer.CanUseSudo() {
		fmt.Println("sudo is available for privilege escalation")
	} else {
		fmt.Println("sudo is unavailable; write to user-writable directories")
	}
}

Advanced

  • Implemented as whether exec.LookPath("sudo") succeeds. 🛠️
  • The result can be used to decide the value of Config.UseSudo, which in turn affects the behavior of Install, Uninstall, and similar methods. 🔗
  • On Windows it typically returns false; use administrator privileges instead of sudo. 🚫

Released under the MIT License