Documentation ¶
Overview ¶
Package builtin implements some built-in functions for gosl (Go Language Script Language, github.com/daviddengcn/gosl)
For use of convinience as a script language, the parameters are commonly defined as an interface{}.
Index ¶
- Variables
- func Bash(cmd interface{}, args ...interface{}) (error, int)
- func BashEval(cmd interface{}, args ...interface{}) string
- func BashWithStdout(cmd interface{}, args ...interface{}) (string, error, int)
- func Eprint(args ...interface{})
- func Eprintf(format interface{}, args ...interface{})
- func Eprintfln(format interface{}, args ...interface{})
- func Eprintln(args ...interface{})
- func Eval(exe interface{}, args ...string) string
- func Exec(exe interface{}, args ...string) (error, int)
- func ExecWithStdErrOut(exe interface{}, args ...string) (stdout, stderr string, err error, errCode int)
- func ExecWithStdout(exe interface{}, args ...string) (stdout string, err error, errCode int)
- func Exists(p interface{}, args ...interface{}) bool
- func Fatalf(msg interface{}, args ...interface{})
- func I(v interface{}, def ...interface{}) int
- func IsDir(p interface{}, args ...interface{}) bool
- func IsFile(p interface{}, args ...interface{}) bool
- func Match(str interface{}, pattern interface{}) []string
- func MustSucc(err error, code int)
- func Printfln(format interface{}, args ...interface{})
- func Pwd() string
- func S(v interface{}, args ...interface{}) string
- func S2Is(args ...string) (ifs []interface{})
- func ScriptDir() string
- func ScriptName() string
- func SortF(Len int, Less func(int, int) bool, Swap func(int, int))
- func Succ(err error, code int) bool
Constants ¶
This section is empty.
Variables ¶
var DefExitCode = 1
DefExitCode is the default exit code.
var ( // Set DryRun to true will make all Exec related functions in dry run mode, i.e. they only print the command to run. DryRun = false )
Functions ¶
func BashEval ¶
func BashEval(cmd interface{}, args ...interface{}) string
BashEval is similar to BashWithStdout but only returns captured stdout as a string. Trainling newlines are deleted. It's like the backtick substitution in Bash.
func BashWithStdout ¶
BashWithStdout is similar to Bash but with stdout captured and returned as a string.
func Eprint ¶
func Eprint(args ...interface{})
Eprint is similar to fmt.Print but the output is stderr.
func Eprintf ¶
func Eprintf(format interface{}, args ...interface{})
Eprintf is similar to fmt.Printf but the output is stderr.
func Eprintfln ¶
func Eprintfln(format interface{}, args ...interface{})
Eprintfln is similar to Eprintf but with a trailing new-line printed
func Eprintln ¶
func Eprintln(args ...interface{})
Eprintln is similar to fmt.Println but the output is stderr.
func Eval ¶
Eval is similar to ExecWithStdout but with stdout captured and returned as a string. Trainling newlines are deleted.
func Exec ¶
Exec runs a command. exe is the path to the executable and args are arugment passed to it.
If the command is executed successfuly without mistakes, (nil, 0) will be returned. Otherwise, the error and error code will be returned. NOTE the error code could be 0 with a non-nil error.
Stdout/stderr are directed to the current stdout/stderr.
func ExecWithStdErrOut ¶
func ExecWithStdErrOut(exe interface{}, args ...string) (stdout, stderr string, err error, errCode int)
ExecWithStdout is similar to Exec but the stdout/stderr are captured and returned as the first/second return values.
func ExecWithStdout ¶
ExecWithStdout is similar to Exec but the stdout is captured and returned as the first return value.
func Exists ¶
func Exists(p interface{}, args ...interface{}) bool
Exists checks whether the path exists
func Fatalf ¶
func Fatalf(msg interface{}, args ...interface{})
Fatalf prints a message and let the program exit with DefExitCode.
func I ¶
func I(v interface{}, def ...interface{}) int
I converts anything into an int. When the value is malformed, if the optional default value is specified, it is converted to int and returned; otherwise, 0 is returned.
func IsDir ¶
func IsDir(p interface{}, args ...interface{}) bool
IsDir returns true only if the path exists and indicates a directory
func IsFile ¶
func IsFile(p interface{}, args ...interface{}) bool
IsFile returns true only if the path exists and indicates a file
func Match ¶
func Match(str interface{}, pattern interface{}) []string
Match use regular expression pattern to match str and returns all capturing groups.
func Printfln ¶
func Printfln(format interface{}, args ...interface{})
Printfln is similar to fmt.Printf but with a trailing new-line printed
func S ¶
func S(v interface{}, args ...interface{}) string
S converts anything into a string. If args is specified, v is used as a format string.
func S2Is ¶
func S2Is(args ...string) (ifs []interface{})
S2Is returns a slice of interface{} given strings.
func ScriptName ¶
func ScriptName() string
ScriptName returns the filename of the current script not including the path.
Types ¶
This section is empty.