diff --git a/Makefile b/Makefile index 96afb09..5b604cf 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ RUNTIME_MODULES = \ github.com/qri-io/starlib/encoding/base64 \ github.com/qri-io/starlib/encoding/csv \ github.com/qri-io/starlib/encoding/json \ + github.com/qri-io/starlib/encoding/yaml \ github.com/qri-io/starlib/re \ github.com/qri-io/starlib/http diff --git a/_documentation/runtime/base64.md b/_documentation/runtime/base64.md index cf8109a..69a7424 100644 --- a/_documentation/runtime/base64.md +++ b/_documentation/runtime/base64.md @@ -5,6 +5,7 @@ title: 'encoding/base64' base64 defines base64 encoding & decoding functions, often used to represent binary as text. ## Functions + #### def decode ```go decode(src,encoding="standard") string @@ -19,6 +20,7 @@ parse base64 input, giving back the plain string representation | 'encoding' | 'string' | optional. string to set decoding dialect. allowed values are: standard,standard_raw,url,url_raw | + #### def encode ```go encode(src,encoding="standard") string diff --git a/_documentation/runtime/csv.md b/_documentation/runtime/csv.md index 0aee134..7921d61 100644 --- a/_documentation/runtime/csv.md +++ b/_documentation/runtime/csv.md @@ -5,6 +5,7 @@ title: 'encoding/csv' csv reads comma-separated values files ## Functions + #### def read_all ```go read_all(source, comma=",", comment="", lazy_quotes=False, trim_leading_space=False, fields_per_record=0, skip=0) [][]string @@ -24,6 +25,7 @@ read all rows from a source string, returning a list of string lists | 'skip' | 'int' | number of rows to skip, omitting from returned rows | + #### def write_all ```go write_all(source,comma=",") string diff --git a/_documentation/runtime/filepath.md b/_documentation/runtime/filepath.md index 899678d..5b177f5 100644 --- a/_documentation/runtime/filepath.md +++ b/_documentation/runtime/filepath.md @@ -5,6 +5,7 @@ title: 'path/filepath' filepath implements utility routines for manipulating filename paths in a way compatible with the target operating system-defined file path ## Functions + #### def abs ```go abs(path) string @@ -18,6 +19,7 @@ returns an absolute representation of path. If the path is not absolute it will | 'path' | 'string' | relative or absolute path | + #### def base ```go base(path) string @@ -31,6 +33,7 @@ returns the last element of path. Trailing path separators are removed before ex | 'path' | 'string' | input path | + #### def clean ```go clean(path) string @@ -44,6 +47,7 @@ returns the shortest path name equivalent to path by purely lexical processing. | 'path' | 'string' | input path | + #### def dir ```go dir(path) string @@ -57,6 +61,7 @@ returns all but the last element of path, typically the path's directory. After | 'path' | 'string' | input path | + #### def ext ```go ext(path) string @@ -70,6 +75,7 @@ returns the file name extension used by path. The extension is the suffix beginn | 'path' | 'string' | input path | + #### def glob ```go glob(pattern) list @@ -83,6 +89,7 @@ returns the names of all files matching pattern or None if there is no matching | 'pattern' | 'string' | pattern ([syntax](https://golang.org/pkg/path/filepath/#Match)) | + #### def is_abs ```go is_abs(path) bool @@ -96,6 +103,7 @@ reports whether the path is absolute. | 'path' | 'string' | input path | + #### def join ```go join(elements) string @@ -109,6 +117,7 @@ joins any number of path elements into a single path, adding a `filepath.separat | 'elements' | 'lists' | list of path elements to be joined | + #### def rel ```go rel(basepath, targpath) string diff --git a/_documentation/runtime/http.md b/_documentation/runtime/http.md index df8ef7b..0c9724a 100644 --- a/_documentation/runtime/http.md +++ b/_documentation/runtime/http.md @@ -1,10 +1,11 @@ --- -title: '' +title: 'http' --- http defines an HTTP client implementation ## Functions + #### def delete ```go delete(url,params={},headers={},body="",form_body={},json_body={},auth=()) response @@ -23,6 +24,7 @@ perform an HTTP DELETE request, returning a response | 'auth' | 'tuple' | optional. (username,password) tuple for http basic authorization | + #### def get ```go get(url,params={},headers={},auth=()) response @@ -38,6 +40,7 @@ perform an HTTP GET request, returning a response | 'auth' | 'tuple' | optional. (username,password) tuple for http basic authorization | + #### def options ```go options(url,params={},headers={},body="",form_body={},json_body={},auth=()) response @@ -56,6 +59,7 @@ perform an HTTP OPTIONS request, returning a response | 'auth' | 'tuple' | optional. (username,password) tuple for http basic authorization | + #### def patch ```go patch(url,params={},headers={},body="",form_body={},json_body={},auth=()) response @@ -74,6 +78,7 @@ perform an HTTP PATCH request, returning a response | 'auth' | 'tuple' | optional. (username,password) tuple for http basic authorization | + #### def post ```go post(url,params={},headers={},body="",form_body={},json_body={},auth=()) response @@ -92,6 +97,7 @@ perform an HTTP POST request, returning a response | 'auth' | 'tuple' | optional. (username,password) tuple for http basic authorization | + #### def put ```go put(url,params={},headers={},body="",form_body={},json_body={},auth=()) response @@ -127,12 +133,14 @@ the result of performing a http request **Methods** + #### def body ```go body() string ``` output response body as a string + #### def json ```go json() diff --git a/_documentation/runtime/json.md b/_documentation/runtime/json.md index 03b1608..d26679f 100644 --- a/_documentation/runtime/json.md +++ b/_documentation/runtime/json.md @@ -5,6 +5,7 @@ title: 'encoding/json' json provides functions for working with json data ## Functions + #### def dumps ```go dumps(obj) string @@ -18,6 +19,7 @@ serialize obj to a JSON string | 'obj' | 'object' | input object | + #### def loads ```go loads(source) object diff --git a/_documentation/runtime/os.md b/_documentation/runtime/os.md index 3fb0ac4..58fadb9 100644 --- a/_documentation/runtime/os.md +++ b/_documentation/runtime/os.md @@ -5,6 +5,7 @@ title: 'os' os provides a platform-independent interface to operating system functionality. ## Functions + #### def chdir ```go chdir(dir) @@ -18,6 +19,7 @@ changes the current working directory to the named directory. | 'dir' | 'string' | target dir | + #### def getenv ```go getenv(key) dir @@ -31,12 +33,14 @@ retrieves the value of the environment variable named by the key. | 'key' | 'string' | name of the environment variable | + #### def getwd ```go getwd() dir ``` returns a rooted path name corresponding to the current directory. + #### def mkdir ```go mkdir(name, perms=0o777) @@ -51,6 +55,7 @@ creates a new directory with the specified name and permission bits (before umas | 'perms' | 'int' | optional, permission of the folder | + #### def mkdir_all ```go mkdir_all(name, perms=0o777) @@ -65,6 +70,7 @@ creates a new directory with the specified name and permission bits (before umas | 'perms' | 'int' | optional, permission of the folder | + #### def read_file ```go read_file(filename) string @@ -80,6 +86,7 @@ reads the file named by filename and returns the contents. | 'perms' | 'int' | optional, permission of the file | + #### def remove ```go remove(name) @@ -93,6 +100,7 @@ removes the named file or (empty) directory. | 'name' | 'string' | name of the file or directory to be deleted | + #### def remove_all ```go remove_all(path) @@ -106,6 +114,7 @@ removes path and any children it contains. It removes everything it can but retu | 'name' | 'string' | path to be deleted | + #### def rename ```go rename(oldpath, newpath) @@ -120,6 +129,7 @@ renames (moves) oldpath to newpath. If newpath already exists and is not a direc | 'newpath' | 'string' | new path | + #### def setenv ```go setenv(key, value) dir @@ -134,6 +144,7 @@ sets the value of the environment variable named by the key. | 'value' | 'string' | value of the environment variable | + #### def write_file ```go write_file(filename, data, perms=0o644) diff --git a/_documentation/runtime/re.md b/_documentation/runtime/re.md index ba0aacf..a57adea 100644 --- a/_documentation/runtime/re.md +++ b/_documentation/runtime/re.md @@ -1,10 +1,11 @@ --- -title: '' +title: 're' --- re defines regular expression functions, it's intended to be a drop-in subset of python's re module for starlark: https://docs.python.org/3/library/re.html ## Functions + #### def findall ```go findall(pattern, text, flags=0) @@ -20,6 +21,7 @@ Returns all non-overlapping matches of pattern in string, as a list of strings. | 'flags' | 'int' | integer flags to control regex behaviour. reserved for future use | + #### def split ```go split(pattern, text, maxsplit=0, flags=0) @@ -36,6 +38,7 @@ Split text by the occurrences of pattern. If capturing parentheses are used in p | 'flags' | 'int' | integer flags to control regex behaviour. reserved for future use | + #### def sub ```go sub(pattern, repl, text, count=0, flags=0) diff --git a/_documentation/runtime/yaml.md b/_documentation/runtime/yaml.md new file mode 100644 index 0000000..53e5dcf --- /dev/null +++ b/_documentation/runtime/yaml.md @@ -0,0 +1,36 @@ +--- +title: 'encoding/yaml' +--- + +yaml provides functions for working with yaml data +## Functions + + +#### def dumps +```go +dumps(obj) string +``` +serialize obj to a yaml string + +**parameters:** + +| name | type | description | +|------|------|-------------| +| 'obj' | 'object' | input object | + + + +#### def loads +```go +loads(source) object +``` +read a source yaml string to a starlark object + +**parameters:** + +| name | type | description | +|------|------|-------------| +| 'source' | 'string' | input string of yaml data | + + + diff --git a/starlark/runtime/runtime.go b/starlark/runtime/runtime.go index 367c10c..181366c 100644 --- a/starlark/runtime/runtime.go +++ b/starlark/runtime/runtime.go @@ -8,6 +8,7 @@ import ( "github.com/qri-io/starlib/encoding/base64" "github.com/qri-io/starlib/encoding/csv" "github.com/qri-io/starlib/encoding/json" + "github.com/qri-io/starlib/encoding/yaml" "github.com/qri-io/starlib/http" "github.com/qri-io/starlib/re" "go.starlark.net/repl" @@ -37,6 +38,7 @@ func NewRuntime(pm *terraform.PluginManager) *Runtime { "encoding/json": json.LoadModule, "encoding/base64": base64.LoadModule, "encoding/csv": csv.LoadModule, + "encoding/yaml": yaml.LoadModule, "re": re.LoadModule, "http": http.LoadModule, },