Documentation ¶
Index ¶
- Variables
- func IsNoNotFound(err error) bool
- type CmdInfo
- type RunCtx
- type Runner
- func (r *Runner) DefinedScripts() map[string]any
- func (r *Runner) InitLoad() error
- func (r *Runner) IsDefinedScript(name string) bool
- func (r *Runner) LoadDefineScripts() (err error)
- func (r *Runner) LoadScriptFiles() error
- func (r *Runner) RawDefinedScript(name string) (any, bool)
- func (r *Runner) Run(name string, args []string, ctx *RunCtx) error
- func (r *Runner) RunDefinedScript(name string, args []string, ctx *RunCtx) error
- func (r *Runner) RunScriptFile(name string, args []string, ctx *RunCtx) error
- func (r *Runner) RunScriptInfo(si *ScriptInfo, inArgs []string, ctx *RunCtx) error
- func (r *Runner) ScriptDefineInfo(name string) (*ScriptInfo, error)
- func (r *Runner) ScriptFileInfo(name string) (*ScriptInfo, error)
- func (r *Runner) ScriptFiles() map[string]string
- func (r *Runner) Search(name string, args []string, limit int) map[string]string
- func (r *Runner) TryRun(name string, args []string, ctx *RunCtx) (found bool, err error)
- type ScriptInfo
- type Variable
Constants ¶
This section is empty.
Variables ¶
View Source
var AllowExt = []string{".sh", ".zsh", ".bash", ".php", ".go", ".gop", ".kts", ".java", ".gry", ".groovy"}
AllowExt list
View Source
var AllowTypes = []string{"sh", "zsh", "bash"}
AllowTypes shell wrapper for run script
View Source
var ErrNotFound = errors.New("script not found")
ErrNotFound error
View Source
var ExtToBinMap = map[string]string{
".sh": "sh",
".zsh": "zsh",
".bash": "bash",
".php": "php",
".gry": "groovy",
".groovy": "groovy",
".go": "go run",
}
ExtToBinMap data
eg:
'#!/usr/bin/env bash' '#!/usr/bin/env -S go run'
Functions ¶
Types ¶
type CmdInfo ¶
type CmdInfo struct { // Workdir for run script Workdir string // Vars for run cmd. allow exec a command line TODO Vars map[string]string // Env setting for run Env map[string]string // Line command line for run. eg: go run main.go Line string // Type wrap for run. allow: sh, bash, zsh Type string // Msg on run fail Msg string // Silent mode, dont print exec command line. Silent bool `json:"silent"` // contains filtered or unexported fields }
CmdInfo struct
type RunCtx ¶
type RunCtx struct { // Name for script run Name string Type string // Verbose show more info on run Verbose bool // DryRun script DryRun bool // Workdir for run script Workdir string // Env setting for run Env map[string]string // Silent mode, dont print exec command line. Silent bool `json:"silent"` // BeforeFn hook BeforeFn func(si *ScriptInfo, ctx *RunCtx) }
RunCtx definition
type Runner ¶
type Runner struct { // Scripts config and loaded from DefineFiles. // // format: {name: info, name2: info2, ...} Scripts map[string]any `json:"scripts"` // DefineDir scripts define dir, will read and add to Scripts DefineDir string `json:"define_dir"` // DefineFiles scripts define files, will read and add to Scripts // // Allow vars: $user, $os // // eg: // - config/module/scripts.yml // - ?config/module/scripts.$os.yml // start withs '?' - an optional file, load on exists. DefineFiles []string `json:"define_files"` // TypeShell wrapper for run each script. // // value like: bash, sh, zsh or empty for direct run command TypeShell string `json:"type_shell"` // ParseEnv var on script command ParseEnv bool `json:"parse_env"` // ScriptDirs script file dirs, allow multi ScriptDirs []string `json:"script_dirs"` // AllowedExt allowed script file extensions. eg: .go, .sh AllowedExt []string `json:"allowed_ext"` // FindBinByExt on run a script file FindBinByExt bool `json:"find_bin_by_ext"` // ExtToBinMap settings ExtToBinMap map[string]string `json:"ext_to_bin_map"` // PathResolver handler PathResolver func(path string) string // contains filtered or unexported fields }
Runner struct
func (*Runner) IsDefinedScript ¶
IsDefinedScript name
func (*Runner) LoadDefineScripts ¶
LoadDefineScripts from DefineFiles
func (*Runner) LoadScriptFiles ¶
LoadScriptFiles from the ScriptDirs
func (*Runner) RawDefinedScript ¶
RawDefinedScript raw info get
func (*Runner) RunDefinedScript ¶
RunDefinedScript by input name and with arguments
func (*Runner) RunScriptFile ¶
RunScriptFile by input name and with arguments
func (*Runner) RunScriptInfo ¶
func (r *Runner) RunScriptInfo(si *ScriptInfo, inArgs []string, ctx *RunCtx) error
RunScriptInfo by args and context
func (*Runner) ScriptDefineInfo ¶
func (r *Runner) ScriptDefineInfo(name string) (*ScriptInfo, error)
ScriptDefineInfo get script info as ScriptInfo
func (*Runner) ScriptFileInfo ¶
func (r *Runner) ScriptFileInfo(name string) (*ScriptInfo, error)
ScriptFileInfo info get
type ScriptInfo ¶
type ScriptInfo struct { // Type wrap for run script. allow: sh, bash, zsh Type string // Workdir for run script Workdir string // Platform limit. allow: windows, linux, darwin Platform []string // Output target. default is stdout Output string // Vars for run script. allow exec a command line TODO Vars map[string]string // Ext enable ext: proxy, clip Ext string // Deps commands list Deps []string // Name for script Name string // Desc message Desc string // Env setting for run Env map[string]string // Args script args definition. Args, ArgNames []string // Cmds commands list Cmds []string // Silent mode, dont print exec command line. Silent bool `json:"silent"` // PreCond for run script. eg: test -f .env PreCond string // File script file path in Runner.ScriptDirs File string BinName string FileExt string // eg: .go }
ScriptInfo struct Info, Meta
func (*ScriptInfo) ParseArgs ¶
func (si *ScriptInfo) ParseArgs() (args []string)
ParseArgs on commands
func (*ScriptInfo) WithFallbackType ¶
func (si *ScriptInfo) WithFallbackType(typ string) *ScriptInfo
WithFallbackType on not set
Click to show internal directories.
Click to hide internal directories.