gg_exec_shell

package
v0.3.75 Latest Latest
Warning

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

Go to latest
Published: May 28, 2025 License: BSD-3-Clause Imports: 14 Imported by: 0

README

Shell Scripts

This package contains utility to invoke .sh or .bat (or executables commands) files starting from a root directory.

The package also save in data files some default parameters (like credentials) to pass to scripts.

ENV Files

The shell controller can generate .env files that are executables that are launched automatically before the execution of a command or a shell script.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BashCommand = "/bin/bash"
	DirRoot     = "."
)
View Source
var TplAutorunSh string
View Source
var TplEnvSh string

Functions

func GetShellAutorunFilename added in v0.3.36

func GetShellAutorunFilename(command string) string

func GetShellCmd

func GetShellCmd() string

GetShellCmd returns the default shell command depending on the operating system. For Windows, it returns "cmd", otherwise it defaults to "/bin/sh".

func GetShellCmdFrom added in v0.3.37

func GetShellCmdFrom(command string) (response string)

GetShellCmdFrom determines the shell command to use based on the provided file or defaults to the system shell command.

func GetShellEnvFilename added in v0.3.36

func GetShellEnvFilename(command string) string

func GetShellTempFile

func GetShellTempFile() string

GetShellTempFile generates an absolute path for a temporary shell script file, with a platform-specific extension.

func IsAutorun added in v0.3.36

func IsAutorun(command string) bool

func IsEnv added in v0.3.36

func IsEnv(command string) bool

func IsShellCmd

func IsShellCmd(command string) bool

IsShellCmd determines if a given command string is a shell script or batch file based on its file extension.

func IsValidEnvValue added in v0.3.37

func IsValidEnvValue(text string) bool

func Quote added in v0.3.38

func Quote(s string) string

func Split added in v0.3.38

func Split(arg string) (response []string)

func ToArguments added in v0.3.38

func ToArguments(args ...string) (result []string)

func ToCommand added in v0.3.38

func ToCommand(item *ShellScriptItem, args ...string) (response []string)

func ToError added in v0.3.36

func ToError(command string, err error) (response error)

func Unquote added in v0.3.39

func Unquote(s string) string

func WriteShellAutorunFile added in v0.3.36

func WriteShellAutorunFile(dirTarget string, command string, rows []any) (response string, err error)

func WriteShellEnvFile added in v0.3.36

func WriteShellEnvFile(dirTarget, dirToExport string, command string, exports map[string]interface{}, rows []any) (response string, err error)

Types

type ShellExecResponse added in v0.3.36

type ShellExecResponse struct {
	CommandLine string   `json:"command-line"` // executed command
	Command     string   `json:"command"`      // executed command
	Arguments   []string `json:"arguments"`    //
	Env         []string `json:"environment"`  // executed command
	Response    string   `json:"response"`     // execution response
	Error       string   `json:"error"`        // execution error
}

func (*ShellExecResponse) GetError added in v0.3.36

func (instance *ShellExecResponse) GetError() error

func (*ShellExecResponse) HasError added in v0.3.36

func (instance *ShellExecResponse) HasError() bool

func (*ShellExecResponse) Map added in v0.3.36

func (instance *ShellExecResponse) Map() map[string]interface{}

func (*ShellExecResponse) SetCommand added in v0.3.39

func (instance *ShellExecResponse) SetCommand(args ...string) *ShellExecResponse

func (*ShellExecResponse) SetError added in v0.3.36

func (instance *ShellExecResponse) SetError(err error) *ShellExecResponse

func (*ShellExecResponse) SetResponse added in v0.3.36

func (instance *ShellExecResponse) SetResponse(response string, env []string, err error) *ShellExecResponse

func (*ShellExecResponse) String added in v0.3.36

func (instance *ShellExecResponse) String() string

type ShellHelper

type ShellHelper struct {
}
var Shell *ShellHelper

func NewShellHelper

func NewShellHelper() (instance *ShellHelper)

func (*ShellHelper) Error added in v0.3.45

func (instance *ShellHelper) Error(err any) error

Error processes the provided error and returns a new error based on specific conditions, or nil if no error exists.

func (*ShellHelper) New

func (instance *ShellHelper) New(root string) (response *ShellScriptCtrl)

func (*ShellHelper) Run added in v0.3.45

func (instance *ShellHelper) Run(dir string, environment []string, args ...string) (response *ShellExecResponse)

func (*ShellHelper) VerifyError added in v0.3.65

func (instance *ShellHelper) VerifyError(s string, e error) (response string, err error)

func (*ShellHelper) Which added in v0.3.45

func (instance *ShellHelper) Which(dir string, environment []string, executables ...string) (response []string, err error)

type ShellScriptCtrl

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

ShellScriptCtrl is a controller for managing and executing shell scripts or commands with customizable arguments.

func NewShellScriptCtrl

func NewShellScriptCtrl() (instance *ShellScriptCtrl)

func (*ShellScriptCtrl) Autorun added in v0.3.36

func (instance *ShellScriptCtrl) Autorun(command string) (response []*ShellExecResponse)

Autorun Run all autorun files for a specific command

func (*ShellScriptCtrl) AutorunAll added in v0.3.36

func (instance *ShellScriptCtrl) AutorunAll() (response []*ShellExecResponse)

AutorunAll Run all autorun files

func (*ShellScriptCtrl) CreateShellItemAutorun added in v0.3.36

func (instance *ShellScriptCtrl) CreateShellItemAutorun(command string, rows []interface{}) (filename string, err error)

func (*ShellScriptCtrl) CreateShellItemEnvironment added in v0.3.36

func (instance *ShellScriptCtrl) CreateShellItemEnvironment(command string, exports map[string]interface{}, rows []any) (filename string, err error)

func (*ShellScriptCtrl) GetRoot

func (instance *ShellScriptCtrl) GetRoot() string

func (*ShellScriptCtrl) GetShellItem

func (instance *ShellScriptCtrl) GetShellItem(command string) (response *ShellScriptItem)

GetShellItem retrieves a ShellScriptItem for the given command, creating it if it does not exist.

func (*ShellScriptCtrl) GetWorkspace added in v0.3.36

func (instance *ShellScriptCtrl) GetWorkspace() string

func (*ShellScriptCtrl) ListAutorunFiles added in v0.3.36

func (instance *ShellScriptCtrl) ListAutorunFiles(command string) (response []string)

ListAutorunFiles retrieves a list of autorun files based on the provided command. It ensures thread safety with a mutex lock.

func (*ShellScriptCtrl) ReadAll

func (instance *ShellScriptCtrl) ReadAll() (response []*ShellScriptItem)

ReadAll retrieves all ShellScriptItem objects managed by the ShellScriptCtrl instance, after ensuring they are loaded.

func (*ShellScriptCtrl) ResetShellItem

func (instance *ShellScriptCtrl) ResetShellItem(command string) *ShellScriptCtrl

ResetShellItem resets the prefix and suffix arguments for the specified command.

func (*ShellScriptCtrl) Run

func (instance *ShellScriptCtrl) Run(args ...string) (response *ShellExecResponse)

Run executes a shell script or command based on the arguments provided and returns the response or an error.

func (*ShellScriptCtrl) SaveAll

func (instance *ShellScriptCtrl) SaveAll() *ShellScriptCtrl

SaveAll force to save all shell items into index.dat file.

func (*ShellScriptCtrl) SetDefaults

func (instance *ShellScriptCtrl) SetDefaults(command string, prefix bool, args ...string) *ShellScriptCtrl

SetDefaults sets default prefix or suffix arguments for a specific command in the ShellScriptCtrl instance.

func (*ShellScriptCtrl) SetRoot

func (instance *ShellScriptCtrl) SetRoot(value string) *ShellScriptCtrl

SetRoot sets the root directory for the ShellScriptCtrl instance and updates its state by re-loading data.

func (*ShellScriptCtrl) SetWorkspace added in v0.3.36

func (instance *ShellScriptCtrl) SetWorkspace(value string) *ShellScriptCtrl

func (*ShellScriptCtrl) Split

func (instance *ShellScriptCtrl) Split(args ...string) (response []string)

Split divides the provided arguments into a processed list of strings for further handling or execution. The response is a list of arguments ready for execution as command or as shell script. This method is useful to see which arguments will be run as a command or shell command like a sort of "Run" simulation.

type ShellScriptItem

type ShellScriptItem struct {
	Uid             string   `json:"uid"`              // unique identifier
	Name            string   `json:"name"`             // name of the script or command. i.e. "myshell.sh", "pandoc", "ls", ...
	PrefixArguments []string `json:"prefix-arguments"` // default arguments to be passed to script at every call
	SuffixArguments []string `json:"suffix-arguments"` // default arguments
}

func (*ShellScriptItem) IsShellCmd

func (instance *ShellScriptItem) IsShellCmd() bool

func (*ShellScriptItem) Map

func (instance *ShellScriptItem) Map() map[string]interface{}

func (*ShellScriptItem) String

func (instance *ShellScriptItem) String() string

Jump to

Keyboard shortcuts

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