Packages

Gleam SDK for Dagger — type-safe pipelines via GraphQL codegen

Current section

Files

Jump to
dagger_gleam src dagger dsl directory.gleam
Raw

src/dagger/dsl/directory.gleam

// AUTO-GENERATED BY DAGGER_GLEAM - DO NOT EDIT
import dagger/types.{type Client, type Try} as types
import dagger/interpreter
import dagger/dsl/types as t
import gleam/dynamic/decode
import gleam/list
import gleam/option.{type Option, None, Some}
pub type Opts {
Opts(
source_root_path: Option(String),
dockerfile: Option(String),
platform: Option(String),
build_args: Option(List(t.BuildArg)),
target: Option(String),
secrets: Option(List(t.Secret)),
no_init: Option(Bool),
ssh: Option(t.Socket),
path: Option(String),
expected_type: Option(t.ExistsType),
do_not_follow_symlinks: Option(Bool),
wipe: Option(Bool),
exclude: Option(List(String)),
include: Option(List(String)),
gitignore: Option(Bool),
paths: Option(List(String)),
globs: Option(List(String)),
literal: Option(Bool),
multiline: Option(Bool),
dotall: Option(Bool),
insensitive: Option(Bool),
skip_ignored: Option(Bool),
skip_hidden: Option(Bool),
files_only: Option(Bool),
limit: Option(Int),
container: Option(t.Container),
cmd: Option(List(String)),
experimental_privileged_nesting: Option(Bool),
insecure_root_capabilities: Option(Bool),
owner: Option(String),
permissions: Option(Int),
)
}
fn defaults() -> Opts {
Opts(
source_root_path: None,
dockerfile: None,
platform: None,
build_args: None,
target: None,
secrets: None,
no_init: None,
ssh: None,
path: None,
expected_type: None,
do_not_follow_symlinks: None,
wipe: None,
exclude: None,
include: None,
gitignore: None,
paths: None,
globs: None,
literal: None,
multiline: None,
dotall: None,
insensitive: None,
skip_ignored: None,
skip_hidden: None,
files_only: None,
limit: None,
container: None,
cmd: None,
experimental_privileged_nesting: None,
insecure_root_capabilities: None,
owner: None,
permissions: None,
)
}
pub fn none(opts: Opts) -> Opts {
opts
}
pub fn source_root_path(opts: Opts, val: String) -> Opts {
Opts(..opts, source_root_path: Some(val))
}
pub fn dockerfile(opts: Opts, val: String) -> Opts {
Opts(..opts, dockerfile: Some(val))
}
pub fn platform(opts: Opts, val: String) -> Opts {
Opts(..opts, platform: Some(val))
}
pub fn build_args(opts: Opts, val: List(t.BuildArg)) -> Opts {
Opts(..opts, build_args: Some(val))
}
pub fn target(opts: Opts, val: String) -> Opts {
Opts(..opts, target: Some(val))
}
pub fn secrets(opts: Opts, val: List(t.Secret)) -> Opts {
Opts(..opts, secrets: Some(val))
}
pub fn no_init(opts: Opts, val: Bool) -> Opts {
Opts(..opts, no_init: Some(val))
}
pub fn ssh(opts: Opts, val: t.Socket) -> Opts {
Opts(..opts, ssh: Some(val))
}
pub fn path(opts: Opts, val: String) -> Opts {
Opts(..opts, path: Some(val))
}
pub fn expected_type(opts: Opts, val: t.ExistsType) -> Opts {
Opts(..opts, expected_type: Some(val))
}
pub fn do_not_follow_symlinks(opts: Opts, val: Bool) -> Opts {
Opts(..opts, do_not_follow_symlinks: Some(val))
}
pub fn wipe(opts: Opts, val: Bool) -> Opts {
Opts(..opts, wipe: Some(val))
}
pub fn exclude(opts: Opts, val: List(String)) -> Opts {
Opts(..opts, exclude: Some(val))
}
pub fn include(opts: Opts, val: List(String)) -> Opts {
Opts(..opts, include: Some(val))
}
pub fn gitignore(opts: Opts, val: Bool) -> Opts {
Opts(..opts, gitignore: Some(val))
}
pub fn paths(opts: Opts, val: List(String)) -> Opts {
Opts(..opts, paths: Some(val))
}
pub fn globs(opts: Opts, val: List(String)) -> Opts {
Opts(..opts, globs: Some(val))
}
pub fn literal(opts: Opts, val: Bool) -> Opts {
Opts(..opts, literal: Some(val))
}
pub fn multiline(opts: Opts, val: Bool) -> Opts {
Opts(..opts, multiline: Some(val))
}
pub fn dotall(opts: Opts, val: Bool) -> Opts {
Opts(..opts, dotall: Some(val))
}
pub fn insensitive(opts: Opts, val: Bool) -> Opts {
Opts(..opts, insensitive: Some(val))
}
pub fn skip_ignored(opts: Opts, val: Bool) -> Opts {
Opts(..opts, skip_ignored: Some(val))
}
pub fn skip_hidden(opts: Opts, val: Bool) -> Opts {
Opts(..opts, skip_hidden: Some(val))
}
pub fn files_only(opts: Opts, val: Bool) -> Opts {
Opts(..opts, files_only: Some(val))
}
pub fn limit(opts: Opts, val: Int) -> Opts {
Opts(..opts, limit: Some(val))
}
pub fn container(opts: Opts, val: t.Container) -> Opts {
Opts(..opts, container: Some(val))
}
pub fn cmd(opts: Opts, val: List(String)) -> Opts {
Opts(..opts, cmd: Some(val))
}
pub fn experimental_privileged_nesting(opts: Opts, val: Bool) -> Opts {
Opts(..opts, experimental_privileged_nesting: Some(val))
}
pub fn insecure_root_capabilities(opts: Opts, val: Bool) -> Opts {
Opts(..opts, insecure_root_capabilities: Some(val))
}
pub fn owner(opts: Opts, val: String) -> Opts {
Opts(..opts, owner: Some(val))
}
pub fn permissions(opts: Opts, val: Int) -> Opts {
Opts(..opts, permissions: Some(val))
}
pub fn directory() -> t.Directory {
let field = types.Field(name: "directory", args: [], subfields: [])
t.Directory(op: types.Pure([field]))
}
/// Converts this directory to a local git repository
pub fn as_git(parent: t.Directory) -> t.GitRepository {
let field = types.Field(name: "asGit", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.GitRepository(op: new_op)
}
fn encode_as_module(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.source_root_path {
Some(val) -> Ok(#("sourceRootPath", types.GString(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Load the directory as a Dagger module source
pub fn as_module(parent: t.Directory, with with_fn: fn(Opts) -> Opts) -> t.Module {
let opts = with_fn(defaults())
let field = types.Field(name: "asModule", args: encode_as_module(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Module(op: new_op)
}
fn encode_as_module_source(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.source_root_path {
Some(val) -> Ok(#("sourceRootPath", types.GString(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Load the directory as a Dagger module source
pub fn as_module_source(parent: t.Directory, with with_fn: fn(Opts) -> Opts) -> t.ModuleSource {
let opts = with_fn(defaults())
let field = types.Field(name: "asModuleSource", args: encode_as_module_source(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.ModuleSource(op: new_op)
}
/// Return the difference between this directory and another directory, typically an older snapshot.
/// The difference is encoded as a changeset, which also tracks removed files, and can be applied to other directories.
pub fn changes(parent: t.Directory, from from: t.Directory) -> t.Changeset {
let field = types.Field(name: "changes", args: [#("from", types.GDeferred(from.op))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Changeset(op: new_op)
}
/// Change the owner of the directory contents recursively.
pub fn chown(parent: t.Directory, path path: String, owner owner: String) -> t.Directory {
let field = types.Field(name: "chown", args: [#("path", types.GString(path)), #("owner", types.GString(owner))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Return the difference between this directory and an another directory. The difference is encoded as a directory.
pub fn diff(parent: t.Directory, other other: t.Directory) -> t.Directory {
let field = types.Field(name: "diff", args: [#("other", types.GDeferred(other.op))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Return the directory's digest. The format of the digest is not guaranteed to be stable between releases of Dagger. It is guaranteed to be stable between invocations of the same Dagger engine.
pub fn digest(parent: t.Directory, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "digest", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("digest")))
}
}
)
}
handler(interpreter.run(op, client))
}
fn encode_docker_build(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.dockerfile {
Some(val) -> Ok(#("dockerfile", types.GString(val)))
None -> Error(Nil)
},
case opts.platform {
Some(val) -> Ok(#("platform", types.GString(val)))
None -> Error(Nil)
},
case opts.build_args {
Some(val) -> Ok(#("buildArgs", types.GList(list.map(val, fn(x) { types.GObject(t.build_arg_to_json(x)) }))))
None -> Error(Nil)
},
case opts.target {
Some(val) -> Ok(#("target", types.GString(val)))
None -> Error(Nil)
},
case opts.secrets {
Some(val) -> Ok(#("secrets", types.GList(list.map(val, fn(x) { types.GDeferred(x.op) }))))
None -> Error(Nil)
},
case opts.no_init {
Some(val) -> Ok(#("noInit", types.GBool(val)))
None -> Error(Nil)
},
case opts.ssh {
Some(val) -> Ok(#("ssh", types.GDeferred(val.op)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Use Dockerfile compatibility to build a container from this directory. Only use this function for Dockerfile compatibility. Otherwise use the native Container type directly, it is feature-complete and supports all Dockerfile features.
pub fn docker_build(parent: t.Directory, with with_fn: fn(Opts) -> Opts) -> t.Container {
let opts = with_fn(defaults())
let field = types.Field(name: "dockerBuild", args: encode_docker_build(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Container(op: new_op)
}
fn encode_entries(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.path {
Some(val) -> Ok(#("path", types.GString(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Returns a list of files and directories at the given path.
pub fn entries(parent: t.Directory, with with_fn: fn(Opts) -> Opts, client client: Client, then handler: fn(Try(List(String))) -> a) -> a {
let opts = with_fn(defaults())
let field = types.Field(name: "entries", args: encode_entries(opts), subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.list(decode.string))) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("entries")))
}
}
)
}
handler(interpreter.run(op, client))
}
fn encode_exists(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.expected_type {
Some(val) -> Ok(#("expectedType", types.GString(t.exists_type_to_json(val))))
None -> Error(Nil)
},
case opts.do_not_follow_symlinks {
Some(val) -> Ok(#("doNotFollowSymlinks", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// check if a file or directory exists
pub fn exists(parent: t.Directory, path path: String, with with_fn: fn(Opts) -> Opts, client client: Client, then handler: fn(Try(Bool)) -> a) -> a {
let opts = with_fn(defaults())
let field = types.Field(name: "exists", args: list.append([#("path", types.GString(path))], encode_exists(opts)), subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.bool)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("exists")))
}
}
)
}
handler(interpreter.run(op, client))
}
fn encode_export(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.wipe {
Some(val) -> Ok(#("wipe", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Writes the contents of the directory to a path on the host.
pub fn export(parent: t.Directory, path path: String, with with_fn: fn(Opts) -> Opts, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let opts = with_fn(defaults())
let field = types.Field(name: "export", args: list.append([#("path", types.GString(path))], encode_export(opts)), subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("export")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Retrieve a file at the given path.
pub fn file(parent: t.Directory, path path: String) -> t.File {
let field = types.Field(name: "file", args: [#("path", types.GString(path))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.File(op: new_op)
}
fn encode_filter(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.exclude {
Some(val) -> Ok(#("exclude", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
},
case opts.include {
Some(val) -> Ok(#("include", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
},
case opts.gitignore {
Some(val) -> Ok(#("gitignore", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Return a snapshot with some paths included or excluded
pub fn filter(parent: t.Directory, with with_fn: fn(Opts) -> Opts) -> t.Directory {
let opts = with_fn(defaults())
let field = types.Field(name: "filter", args: encode_filter(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Search up the directory tree for a file or directory, and return its path. If no match, return null
pub fn find_up(parent: t.Directory, name name: String, start start: String, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "findUp", args: [#("name", types.GString(name)), #("start", types.GString(start))], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("findUp")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Returns a list of files and directories that matche the given pattern.
pub fn glob(parent: t.Directory, pattern pattern: String, client client: Client, then handler: fn(Try(List(String))) -> a) -> a {
let field = types.Field(name: "glob", args: [#("pattern", types.GString(pattern))], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.list(decode.string))) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("glob")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// A unique identifier for this Directory.
pub fn id(parent: t.Directory) -> t.Directory {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Returns the name of the directory.
pub fn name(parent: t.Directory, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "name", args: [], subfields: [])
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.string)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("name")))
}
}
)
}
handler(interpreter.run(op, client))
}
fn encode_search(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.paths {
Some(val) -> Ok(#("paths", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
},
case opts.globs {
Some(val) -> Ok(#("globs", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
},
case opts.literal {
Some(val) -> Ok(#("literal", types.GBool(val)))
None -> Error(Nil)
},
case opts.multiline {
Some(val) -> Ok(#("multiline", types.GBool(val)))
None -> Error(Nil)
},
case opts.dotall {
Some(val) -> Ok(#("dotall", types.GBool(val)))
None -> Error(Nil)
},
case opts.insensitive {
Some(val) -> Ok(#("insensitive", types.GBool(val)))
None -> Error(Nil)
},
case opts.skip_ignored {
Some(val) -> Ok(#("skipIgnored", types.GBool(val)))
None -> Error(Nil)
},
case opts.skip_hidden {
Some(val) -> Ok(#("skipHidden", types.GBool(val)))
None -> Error(Nil)
},
case opts.files_only {
Some(val) -> Ok(#("filesOnly", types.GBool(val)))
None -> Error(Nil)
},
case opts.limit {
Some(val) -> Ok(#("limit", types.GInt(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Searches for content matching the given regular expression or literal string.
/// Uses Rust regex syntax; escape literal ., [, ], {, }, | with backslashes.
pub fn search(parent: t.Directory, pattern pattern: String, with with_fn: fn(Opts) -> Opts, select select: fn(t.SearchResult) -> List(types.Field), client client: Client, then handler: fn(Try(List(t.SearchResult))) -> a) -> a {
let opts = with_fn(defaults())
let subfields = select(t.SearchResult(op: types.Pure([])))
let field = types.Field(name: "search", args: list.append([#("pattern", types.GString(pattern))], encode_search(opts)), subfields: subfields)
let op = {
use q <- types.bind(parent.op)
let full_query = list.append(q, [field])
types.Fetch(
fields: full_query,
decoder: decode.dynamic,
next: fn(dyn) {
let path = types.make_path(full_query)
case decode.run(dyn, decode.at(path, decode.list(decode.dynamic))) {
Ok(items) -> types.Pure(Ok(list.map(items, fn(_) { t.SearchResult(op: types.Pure(full_query)) })))
Error(_) -> types.Pure(Error(types.DecodingError("search")))
}
}
)
}
handler(interpreter.run(op, client))
}
fn encode_stat(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.do_not_follow_symlinks {
Some(val) -> Ok(#("doNotFollowSymlinks", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Return file status
pub fn stat(parent: t.Directory, path path: String, with with_fn: fn(Opts) -> Opts) -> t.Stat {
let opts = with_fn(defaults())
let field = types.Field(name: "stat", args: list.append([#("path", types.GString(path))], encode_stat(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Stat(op: new_op)
}
/// Force evaluation in the engine.
pub fn sync(parent: t.Directory) -> t.Directory {
let field = types.Field(name: "sync", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
fn encode_terminal(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.container {
Some(val) -> Ok(#("container", types.GDeferred(val.op)))
None -> Error(Nil)
},
case opts.cmd {
Some(val) -> Ok(#("cmd", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
},
case opts.experimental_privileged_nesting {
Some(val) -> Ok(#("experimentalPrivilegedNesting", types.GBool(val)))
None -> Error(Nil)
},
case opts.insecure_root_capabilities {
Some(val) -> Ok(#("insecureRootCapabilities", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Opens an interactive terminal in new container with this directory mounted inside.
pub fn terminal(parent: t.Directory, with with_fn: fn(Opts) -> Opts) -> t.Directory {
let opts = with_fn(defaults())
let field = types.Field(name: "terminal", args: encode_terminal(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Return a directory with changes from another directory applied to it.
pub fn with_changes(parent: t.Directory, changes changes: t.Changeset) -> t.Directory {
let field = types.Field(name: "withChanges", args: [#("changes", types.GDeferred(changes.op))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
fn encode_with_directory(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.exclude {
Some(val) -> Ok(#("exclude", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
},
case opts.include {
Some(val) -> Ok(#("include", types.GList(list.map(val, fn(x) { types.GString(x) }))))
None -> Error(Nil)
},
case opts.gitignore {
Some(val) -> Ok(#("gitignore", types.GBool(val)))
None -> Error(Nil)
},
case opts.owner {
Some(val) -> Ok(#("owner", types.GString(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Return a snapshot with a directory added
pub fn with_directory(parent: t.Directory, path path: String, source source: t.Directory, with with_fn: fn(Opts) -> Opts) -> t.Directory {
let opts = with_fn(defaults())
let field = types.Field(name: "withDirectory", args: list.append([#("path", types.GString(path)), #("source", types.GDeferred(source.op))], encode_with_directory(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Raise an error.
pub fn with_error(parent: t.Directory, err err: String) -> t.Directory {
let field = types.Field(name: "withError", args: [#("err", types.GString(err))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
fn encode_with_file(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.owner {
Some(val) -> Ok(#("owner", types.GString(val)))
None -> Error(Nil)
},
case opts.permissions {
Some(val) -> Ok(#("permissions", types.GInt(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Retrieves this directory plus the contents of the given file copied to the given path.
pub fn with_file(parent: t.Directory, path path: String, source source: t.File, with with_fn: fn(Opts) -> Opts) -> t.Directory {
let opts = with_fn(defaults())
let field = types.Field(name: "withFile", args: list.append([#("path", types.GString(path)), #("source", types.GDeferred(source.op))], encode_with_file(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
fn encode_with_files(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.permissions {
Some(val) -> Ok(#("permissions", types.GInt(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Retrieves this directory plus the contents of the given files copied to the given path.
pub fn with_files(parent: t.Directory, path path: String, sources sources: List(t.File), with with_fn: fn(Opts) -> Opts) -> t.Directory {
let opts = with_fn(defaults())
let field = types.Field(name: "withFiles", args: list.append([#("path", types.GString(path)), #("sources", types.GList(list.map(sources, fn(x) { types.GDeferred(x.op) })))], encode_with_files(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
fn encode_with_new_directory(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.permissions {
Some(val) -> Ok(#("permissions", types.GInt(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Retrieves this directory plus a new directory created at the given path.
pub fn with_new_directory(parent: t.Directory, path path: String, with with_fn: fn(Opts) -> Opts) -> t.Directory {
let opts = with_fn(defaults())
let field = types.Field(name: "withNewDirectory", args: list.append([#("path", types.GString(path))], encode_with_new_directory(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
fn encode_with_new_file(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.permissions {
Some(val) -> Ok(#("permissions", types.GInt(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Return a snapshot with a new file added
pub fn with_new_file(parent: t.Directory, path path: String, contents contents: String, with with_fn: fn(Opts) -> Opts) -> t.Directory {
let opts = with_fn(defaults())
let field = types.Field(name: "withNewFile", args: list.append([#("path", types.GString(path)), #("contents", types.GString(contents))], encode_with_new_file(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Retrieves this directory with the given Git-compatible patch applied.
pub fn with_patch(parent: t.Directory, patch patch: String) -> t.Directory {
let field = types.Field(name: "withPatch", args: [#("patch", types.GString(patch))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Retrieves this directory with the given Git-compatible patch file applied.
pub fn with_patch_file(parent: t.Directory, patch patch: t.File) -> t.Directory {
let field = types.Field(name: "withPatchFile", args: [#("patch", types.GDeferred(patch.op))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Return a snapshot with a symlink
pub fn with_symlink(parent: t.Directory, target target: String, link_name link_name: String) -> t.Directory {
let field = types.Field(name: "withSymlink", args: [#("target", types.GString(target)), #("linkName", types.GString(link_name))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Retrieves this directory with all file/dir timestamps set to the given time.
pub fn with_timestamps(parent: t.Directory, timestamp timestamp: Int) -> t.Directory {
let field = types.Field(name: "withTimestamps", args: [#("timestamp", types.GInt(timestamp))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Return a snapshot with a subdirectory removed
pub fn without_directory(parent: t.Directory, path path: String) -> t.Directory {
let field = types.Field(name: "withoutDirectory", args: [#("path", types.GString(path))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Return a snapshot with a file removed
pub fn without_file(parent: t.Directory, path path: String) -> t.Directory {
let field = types.Field(name: "withoutFile", args: [#("path", types.GString(path))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}
/// Return a snapshot with files removed
pub fn without_files(parent: t.Directory, paths paths: List(String)) -> t.Directory {
let field = types.Field(name: "withoutFiles", args: [#("paths", types.GList(list.map(paths, fn(x) { types.GString(x) })))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Directory(op: new_op)
}