run

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 12 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllowPanic = false

AllowPanic disables TrapPanic stopping it from cleaning panic errors.

View Source
var DefaultInterruptHandler = func() { fmt.Print("\b\b"); Exit() }
View Source
var DoNotExit bool

DoNotExit effectively disables Exit and ExitError allowing the program to continue running, usually for test evaluation.

View Source
var TrapPanic = func() {
	if !AllowPanic {
		if r := recover(); r != nil {
			log.Println(r)
			os.Exit(1)
		}
	}
}

TrapPanic recovers from any panic and more gracefully displays the panic by logging it before exiting with a return value of 1.

Functions

func ArgsFrom

func ArgsFrom(line string) []string

ArgsFrom returns a list of field strings split on space (using strings.Fields) with an extra trailing special space item appended if the line has any trailing spaces at all signifying a definite word boundary and not a potential prefix. This is critical for resolving completion with [bonzai.Completer].

func ArgsOrIn

func ArgsOrIn(args []string) (string, error)

ArgsOrIn takes a slice or nil as argument and if the slice has any length greater than 0 returns all the argument joined together with a single space between them. Otherwise, it reads standard input until end of file reached (Cntl-D).

func ExeCacheDir

func ExeCacheDir() (string, error)

func ExeConfigDir

func ExeConfigDir() (string, error)
func ExeIsHardLink() (bool, error)
func ExeIsSymLink() (bool, error)

func ExeName

func ExeName() string

ExeName returns just the base name of the executable by parsing it from os.Args at index 0 (same as $0 in shell). No attempt to resolve any symbolic links or remove any suffix is made.

func ExeStateDir

func ExeStateDir() (string, error)

func Exec

func Exec(args ...string) error

Exec checks for existence of first argument as an executable on the system and then runs it with exec.Command.Run exiting in a way that is supported across all architectures that Go supports. The os.Stdin, os.Stdout, and os.Stderr are connected directly to that of the calling program. Sometimes this is insufficient and the UNIX-specific SysExec is preferred.

func Executable added in v0.6.1

func Executable() (string, error)

Executable returns the absolute path of the executable, resolving any symbolic links. It first retrieves the executable path using os.Executable and, if successful, evaluates any symbolic links in the path using filepath.EvalSymlinks.

func Exit

func Exit()

Exit calls os.Exit(0) unless DoNotExit has been set to true. Cmds should never call Exit themselves returning a nil error from their Methods instead.

func ExitError

func ExitError(err ...any)

ExitError prints err and exits with 1 return value unless DoNotExit has been set to true. Commands should usually never call ExitError themselves returning an error from their Method instead.

func ExitOff

func ExitOff()

ExitOff sets DoNotExit to false.

func ExitOn

func ExitOn()

ExitOn sets DoNotExit to true.

func FileOrIn added in v0.4.0

func FileOrIn(file string) (string, error)

FileOrIn takes a string containing a path to a file. If the file does not exist (or file is empty string) then read from os.Stdin.

func IsAdmin added in v0.5.1

func IsAdmin() bool

IsAdmin checks whether this program is run as a privileged user. In windows this will always return false.

func Out

func Out(args ...string) string

Out returns the standard output of the executed command as a string. Errors are logged but not returned.

func RealExeCacheDir

func RealExeCacheDir() (string, error)

func RealExeName

func RealExeName() (string, error)

RealExeName retrieves the name of the current executable, resolving any symbolic links to return the base name. It returns an error if unable to retrieve or evaluate the executable path.

func RealExeStateDir

func RealExeStateDir() (string, error)

func ShellIsBash

func ShellIsBash() bool

func ShellIsFish

func ShellIsFish() bool

func ShellIsPowerShell

func ShellIsPowerShell() bool

func ShellIsZsh

func ShellIsZsh() bool

func SysExec

func SysExec(args ...string) error

SysExec will check for the existence of the first argument as an executable on the system and then execute it using syscall.Exec(), which replaces the currently running program with the new one in all respects (stdin, stdout, stderr, process ID, signal handling, etc). Generally speaking, this is only available on UNIX variations. This is exceptionally faster and cleaner than calling any of the os/exec variations, but it can make your code far be less compatible with different operating systems.

func Trap added in v0.5.0

func Trap(handler func(), signals ...os.Signal)

Trap sets up a signal handler for signals that calls the handler.

Types

This section is empty.

Directories

Path Synopsis
test
trap command

Jump to

Keyboard shortcuts

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