shell

package module
v0.0.0-...-f591c27 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 11 Imported by: 61

README

Golang utilities

Go Report Card GoDoc MIT License

Package contains some number of auxiliary routines to serve as OS system functions and Input/Output helper calls, which not found in Golang standard libraries.

License

Go-shell is licensed under MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRunAsRoot

func CheckRunAsRoot() bool

CheckRunAsRoot verify that current context is running under root privileges.

func CloseChannelOnSignals

func CloseChannelOnSignals(kill chan struct{}, quit chan struct{}, signals ...os.Signal)

CloseChannelOnSignals close channel once signals received.

func CloseContextOnSignals

func CloseContextOnSignals(cancel context.CancelFunc, quit chan struct{}, signals ...os.Signal)

CloseContextOnSignals call cancel method once signals received.

func CopyFile

func CopyFile(src, dst string) (int64, error)

CopyFile copy regular file. Code taken from: https://opensource.com/article/18/6/copying-files-go

func GetFreeSpace

func GetFreeSpace(path string) (uint64, error)

GetFreeSpace use syscall to find free space for path specified.

func IsLinuxMacOSFreeBSD

func IsLinuxMacOSFreeBSD() bool

IsLinuxMacOSFreeBSD determine that running OS belong to Linux, BSD or macOS.

Types

type App

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

App struct keep everything regarding external application started process including command line, wait channel which tracks process completion and exit code ether any exception happened in any stage of application start up or completion.

func NewApp

func NewApp(name string, args ...string) *App

NewApp return new application instance defined by executable name and arguments, and ready to start by following Run call.

func (*App) AddEnvironments

func (app *App) AddEnvironments(env []string)

AddEnvironments add environments in the form "key=value".

func (*App) CheckIsInstalled

func (app *App) CheckIsInstalled() error

CheckIsInstalled use Linux/FreeBSD utility [which] to find if app is installed or not in the system.

func (*App) ExitCodeOrError

func (app *App) ExitCodeOrError() *ExitCodeOrError

ExitCodeOrError return exit status once application has been finished.

func (*App) Kill

func (app *App) Kill() error

Kill terminate application started asynchronously.

func (*App) Run

func (app *App) Run(stdin io.Reader, stdout, stderr io.Writer) ExitCodeOrError

Run start application synchronously with link to the process stdout/stderr output, to get output. Method doesn't return control until the application finishes its execution.

func (*App) Start

func (app *App) Start(stdin io.Reader, stdout, stderr io.Writer) (chan ExitCodeOrError, error)

Start run application asynchronously and return channel to wait/track exit state and status. If application failed to run, error returned,

func (*App) Wait

func (app *App) Wait() ExitCodeOrError

Wait switch from asynchronous mode to synchronous and wait until application is finished.

type ExitCodeOrError

type ExitCodeOrError struct {
	ExitCode int
	Error    error
}

ExitCodeOrError keeps exit code from application termination either error if application failed in any stage.

Jump to

Keyboard shortcuts

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