builtin

package
v0.0.0-...-db18545 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2015 License: Apache-2.0 Imports: 10 Imported by: 1

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

Constants

This section is empty.

Variables

View Source
var DefExitCode = 1

DefExitCode is the default exit code.

View Source
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 Bash

func Bash(cmd interface{}, args ...interface{}) (error, int)

Bash runs a command with bash. Return values are defined in Exec.

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

func BashWithStdout(cmd interface{}, args ...interface{}) (string, error, int)

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

func Eval(exe interface{}, args ...string) string

Eval is similar to ExecWithStdout but with stdout captured and returned as a string. Trainling newlines are deleted.

func Exec

func Exec(exe interface{}, args ...string) (error, int)

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

func ExecWithStdout(exe interface{}, args ...string) (stdout string, err error, errCode int)

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 MustSucc

func MustSucc(err error, code int)

MustSucc checks the result of Exec/Bash. If not succeed, exit the application.

func Printfln

func Printfln(format interface{}, args ...interface{})

Printfln is similar to fmt.Printf but with a trailing new-line printed

func Pwd

func Pwd() string

Pwd is similar to os.Getwd() without error returned.

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 ScriptDir

func ScriptDir() string

ScriptDir returns the folder of the current script.

func ScriptName

func ScriptName() string

ScriptName returns the filename of the current script not including the path.

func SortF

func SortF(Len int, Less func(int, int) bool, Swap func(int, int))

SortF sorts the data defined by the length, Less and Swap functions.

func Succ

func Succ(err error, code int) bool

Succ check whether return values of Exec and friends means succeed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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