permutil

package
v1.3.0-sp2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DarwinSudo

func DarwinSudo(cmd string, opt ...SudoOption) error

func DarwinSudoRaw

func DarwinSudoRaw(
	ctx context.Context,
	verbose string,
	cwd string,
	env map[string]string,
	command string,
	stdout, stderr io.Writer, statusCode func(int),
) error

func IAmAdmin

func IAmAdmin() bool

func IsFileUnreadAndUnWritable

func IsFileUnreadAndUnWritable(f string) bool

func LinuxPKExecSudo

func LinuxPKExecSudo(cmd string, opt ...SudoOption) error

func Sudo

func Sudo(cmd string, opt ...SudoOption) error

func WindowsSudo

func WindowsSudo(cmd string, opts ...SudoOption) error

Types

type SudoConfig

type SudoConfig struct {
	// 提示语,一般用于告诉用户这个 Sudo 是用来干嘛的
	Verbose string

	// CWD: 命令执行的目录是啥
	Workdir string

	// Env
	Environments map[string]string

	// 用于控制生命周期
	Ctx context.Context

	Stdout, Stderr  io.Writer
	ExitCodeHandler func(int)
}

func NewDefaultSudoConfig

func NewDefaultSudoConfig() *SudoConfig

type SudoOption

type SudoOption func(config *SudoConfig)

func WithContext

func WithContext(ctx context.Context) SudoOption

func WithEnv

func WithEnv(k, v string) SudoOption

func WithExitCodeHandler

func WithExitCodeHandler(i func(int)) SudoOption

func WithStderr

func WithStderr(w io.Writer) SudoOption

func WithStdout

func WithStdout(w io.Writer) SudoOption

func WithVerbose

func WithVerbose(i string) SudoOption

func WithWorkdir

func WithWorkdir(i string) SudoOption

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL