Documentation
¶
Index ¶
- Variables
- func GetShellAutorunFilename(command string) string
- func GetShellCmd() string
- func GetShellCmdFrom(command string) (response string)
- func GetShellEnvFilename(command string) string
- func GetShellTempFile() string
- func IsAutorun(command string) bool
- func IsEnv(command string) bool
- func IsShellCmd(command string) bool
- func IsValidEnvValue(text string) bool
- func Quote(s string) string
- func Split(arg string) (response []string)
- func ToArguments(args ...string) (result []string)
- func ToCommand(item *ShellScriptItem, args ...string) (response []string)
- func ToError(command string, err error) (response error)
- func Unquote(s string) string
- func WriteShellAutorunFile(dirTarget string, command string, rows []any) (response string, err error)
- func WriteShellEnvFile(dirTarget, dirToExport string, command string, exports map[string]interface{}, ...) (response string, err error)
- type ShellExecResponse
- func (instance *ShellExecResponse) GetError() error
- func (instance *ShellExecResponse) HasError() bool
- func (instance *ShellExecResponse) Map() map[string]interface{}
- func (instance *ShellExecResponse) SetCommand(args ...string) *ShellExecResponse
- func (instance *ShellExecResponse) SetError(err error) *ShellExecResponse
- func (instance *ShellExecResponse) SetResponse(response string, env []string, err error) *ShellExecResponse
- func (instance *ShellExecResponse) String() string
- type ShellHelper
- func (instance *ShellHelper) Error(err any) error
- func (instance *ShellHelper) New(root string) (response *ShellScriptCtrl)
- func (instance *ShellHelper) Run(dir string, environment []string, args ...string) (response *ShellExecResponse)
- func (instance *ShellHelper) VerifyError(s string, e error) (response string, err error)
- func (instance *ShellHelper) Which(dir string, environment []string, executables ...string) (response []string, err error)
- type ShellScriptCtrl
- func (instance *ShellScriptCtrl) Autorun(command string) (response []*ShellExecResponse)
- func (instance *ShellScriptCtrl) AutorunAll() (response []*ShellExecResponse)
- func (instance *ShellScriptCtrl) CreateShellItemAutorun(command string, rows []interface{}) (filename string, err error)
- func (instance *ShellScriptCtrl) CreateShellItemEnvironment(command string, exports map[string]interface{}, rows []any) (filename string, err error)
- func (instance *ShellScriptCtrl) GetRoot() string
- func (instance *ShellScriptCtrl) GetShellItem(command string) (response *ShellScriptItem)
- func (instance *ShellScriptCtrl) GetWorkspace() string
- func (instance *ShellScriptCtrl) ListAutorunFiles(command string) (response []string)
- func (instance *ShellScriptCtrl) ReadAll() (response []*ShellScriptItem)
- func (instance *ShellScriptCtrl) ResetShellItem(command string) *ShellScriptCtrl
- func (instance *ShellScriptCtrl) Run(args ...string) (response *ShellExecResponse)
- func (instance *ShellScriptCtrl) SaveAll() *ShellScriptCtrl
- func (instance *ShellScriptCtrl) SetDefaults(command string, prefix bool, args ...string) *ShellScriptCtrl
- func (instance *ShellScriptCtrl) SetRoot(value string) *ShellScriptCtrl
- func (instance *ShellScriptCtrl) SetWorkspace(value string) *ShellScriptCtrl
- func (instance *ShellScriptCtrl) Split(args ...string) (response []string)
- type ShellScriptItem
Constants ¶
This section is empty.
Variables ¶
var ( BashCommand = "/bin/bash" DirRoot = "." )
var TplAutorunSh string
var TplEnvSh string
Functions ¶
func GetShellAutorunFilename ¶ added in v0.3.36
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
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 GetShellTempFile ¶
func GetShellTempFile() string
GetShellTempFile generates an absolute path for a temporary shell script file, with a platform-specific extension.
func IsShellCmd ¶
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 ToArguments ¶ added in v0.3.38
func ToCommand ¶ added in v0.3.38
func ToCommand(item *ShellScriptItem, args ...string) (response []string)
func WriteShellAutorunFile ¶ added in v0.3.36
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)
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 (*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