osutils

package
v0.0.0-...-41e44c1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const ExeExtension = ""
View Source
const LineSep = "\n"

LineSep is the line separator character string used on the GOOS

Variables

This section is empty.

Functions

func BashifyPath

func BashifyPath(absolutePath string) (string, error)

BashifyPath takes a windows style path and turns it into a bash style path eg. C:\temp becomes /c/temp

func BashifyPathEnv

func BashifyPathEnv(pathList string) (string, error)

func CmdExitCode

func CmdExitCode(cmd *exec.Cmd) (code int)

CmdExitCode returns the exit code of a command

func CmdString

func CmdString(c *exec.Cmd) string

CmdString returns a human-readable description of c. This is a copy of the Go 1.13 (cmd.String) function

func Command

func Command(name string, arg ...string) *exec.Cmd

func DecodeCmd

func DecodeCmd(cmd string) (string, []string)

DecodeCmd takes an encoded command and decodes it by returning a shell variant based on the OS we're on

func EnvMapToSlice

func EnvMapToSlice(envMap map[string]string) []string

func EnvSliceToMap

func EnvSliceToMap(envSlice []string) map[string]string

func ExecSimple

func ExecSimple(bin string, args []string, env []string) (string, string, error)

func ExecSimpleFromDir

func ExecSimpleFromDir(dir, bin string, args []string, env []string) (string, string, error)

func Executable

func Executable() string

Executable returns the resolved path to the currently running executable.

func ExecutableName

func ExecutableName() string

ExecutableName returns the name of the executable called with the extension removed and falls back to the command used to call the executable.

func ExecutablePaths

func ExecutablePaths(env map[string]string) ([]string, error)

func Executables

func Executables(bins []string) ([]string, error)

Executables will find all directories that contain executables from the provided list of paths

func Execute

func Execute(command string, arg []string, optSetter func(cmd *exec.Cmd) error) (int, *exec.Cmd, error)

Execute will run the given command and with optional settings for the exec.Cmd struct

func ExecuteAndForget

func ExecuteAndForget(command string, args []string, opts ...func(cmd *exec.Cmd) error) (*os.Process, error)

ExecuteAndForget will run the given command in the background, returning immediately.

func ExecuteAndPipeStd

func ExecuteAndPipeStd(command string, arg []string, env []string) (int, *exec.Cmd, error)

ExecuteAndPipeStd will run the given command and pipe stdin, stdout and stderr

func ExecuteInBackground

func ExecuteInBackground(command string, args []string, opts ...func(cmd *exec.Cmd) error) (*exec.Cmd, *bytes.Buffer, *bytes.Buffer, error)

ExecuteInBackground runs the command in background and returns a buffers for stdout and stderr

func FilterExesOnPATH

func FilterExesOnPATH(executable string, PATH string, filter func(exe string) bool) []string

FindExeOnPATH returns the first path from the PATH env var for which the executable exists

func FindExeInside

func FindExeInside(executable string, PATH string) string

func FindExeOnPATH

func FindExeOnPATH(executable string, PATH string) string

FindExeOnPATH returns the first path from the PATH env var for which the executable exists

func Getwd

func Getwd() (string, error)

Getwd is an alias of os.Getwd which wraps the error in our localized error message and FailGetWd, which is user facing (doesn't get logged)

func GetwdUnsafe

func GetwdUnsafe() string

func InheritEnv

func InheritEnv(env map[string]string) map[string]string

InheritEnv returns a union of the given environment and os.Environ(). If the given environment and os.Environ() share any environment variables, the former's will be used over the latter's.

func IsAccessDeniedError

func IsAccessDeniedError(err error) bool

IsAccessDeniedError is primarily used to determine if an operation failed due to insufficient permissions (e.g. attempting to kill an admin process as a normal user)

func IsAdmin

func IsAdmin() (bool, error)

func IsNotExistError

func IsNotExistError(err error) bool

func NotExistError

func NotExistError() error

func OpenEditor

func OpenEditor(filename string) error

func OpenURI

func OpenURI(input string) error

func PropagateEnv

func PropagateEnv() error

func SetStringValue

func SetStringValue(key RegistryKey, name string, valType uint32, value string) error

func SysProcAttrForBackgroundProcess

func SysProcAttrForBackgroundProcess() *syscall.SysProcAttr

func SysProcAttrForNewProcessGroup

func SysProcAttrForNewProcessGroup() *syscall.SysProcAttr

SysProcAttrForNewProcessGroup returns a SysProcAttr structure configured to start a process with a new process group

func UniqueExes

func UniqueExes(exePaths []string, pathext string) ([]string, error)

UniqueExes filters the array of executables for those that would be selected by the command shell in case of a name collision

Types

type RegistryKey

type RegistryKey interface {
	GetStringValue(name string) (val string, valtype uint32, err error)
	SetStringValue(name, value string) error
	SetExpandStringValue(name, value string) error
	DeleteValue(name string) error
	Close() error
}

func CreateCurrentUserKey

func CreateCurrentUserKey(path string) (RegistryKey, bool, error)

func CreateUserKey

func CreateUserKey(path string) (RegistryKey, bool, error)

func OpenSystemKey

func OpenSystemKey(path string) (RegistryKey, error)

func OpenUserKey

func OpenUserKey(path string) (RegistryKey, error)

type ShellEscape

type ShellEscape struct {
	// contains filtered or unexported fields
}

ShellEscape serve to escape arguments passed to shell commands

func NewBashEscaper

func NewBashEscaper() *ShellEscape

NewBashEscaper creates a new instance of ShellEscape that's configured for escaping bash style arguments

func NewBatchEscaper

func NewBatchEscaper() *ShellEscape

NewBatchEscaper creates a new instance of ShellEscape that's configured for escaping batch style arguments

func NewCmdEscaper

func NewCmdEscaper() *ShellEscape

NewCmdEscaper creates a new instance of ShellEscape that's configured for escaping cmd arguments

func (*ShellEscape) Escape

func (s *ShellEscape) Escape(value string) string

Escape will escape any characters that require escaping for the purpose of quoting

func (*ShellEscape) EscapeLineEnd

func (s *ShellEscape) EscapeLineEnd(value string) string

EscapeLineEnd will escape any line end characters that require escaping for the purpose of quoting

func (*ShellEscape) Quote

func (s *ShellEscape) Quote(value string) string

Quote implements SubShell.Quote

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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