Documentation
¶
Index ¶
- Variables
- func ArgsFrom(line string) []string
- func ArgsOrIn(args []string) (string, error)
- func ExeCacheDir() (string, error)
- func ExeConfigDir() (string, error)
- func ExeIsHardLink() (bool, error)
- func ExeIsSymLink() (bool, error)
- func ExeName() string
- func ExeStateDir() (string, error)
- func Exec(args ...string) error
- func Executable() (string, error)
- func Exit()
- func ExitError(err ...any)
- func ExitOff()
- func ExitOn()
- func FileOrIn(file string) (string, error)
- func IsAdmin() bool
- func Out(args ...string) string
- func RealExeCacheDir() (string, error)
- func RealExeName() (string, error)
- func RealExeStateDir() (string, error)
- func ShellIsBash() bool
- func ShellIsFish() bool
- func ShellIsPowerShell() bool
- func ShellIsZsh() bool
- func SysExec(args ...string) error
- func Trap(handler func(), signals ...os.Signal)
Constants ¶
This section is empty.
Variables ¶
var AllowPanic = false
AllowPanic disables TrapPanic stopping it from cleaning panic errors.
var DefaultInterruptHandler = func() { fmt.Print("\b\b"); Exit() }
var DoNotExit bool
DoNotExit effectively disables Exit and ExitError allowing the program to continue running, usually for test evaluation.
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 ¶
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 ¶
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 ExeConfigDir ¶
func ExeIsHardLink ¶
func ExeIsSymLink ¶
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 Exec ¶
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
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 FileOrIn ¶ added in v0.4.0
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 ¶
Out returns the standard output of the executed command as a string. Errors are logged but not returned.
func RealExeCacheDir ¶
func RealExeName ¶
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 ShellIsBash ¶
func ShellIsBash() bool
func ShellIsFish ¶
func ShellIsFish() bool
func ShellIsPowerShell ¶
func ShellIsPowerShell() bool
func ShellIsZsh ¶
func ShellIsZsh() bool
func SysExec ¶
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.
Types ¶
This section is empty.