Current section
Files
Jump to
Current section
Files
src/dagger/dsl/file.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(
permissions: Option(Int),
offset_lines: Option(Int),
limit_lines: Option(Int),
exclude_metadata: Option(Bool),
allow_parent_dir_path: Option(Bool),
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),
paths: Option(List(String)),
globs: Option(List(String)),
all: Option(Bool),
first_from: Option(Int),
)
}
fn defaults() -> Opts {
Opts(
permissions: None,
offset_lines: None,
limit_lines: None,
exclude_metadata: None,
allow_parent_dir_path: None,
literal: None,
multiline: None,
dotall: None,
insensitive: None,
skip_ignored: None,
skip_hidden: None,
files_only: None,
limit: None,
paths: None,
globs: None,
all: None,
first_from: None,
)
}
pub fn none(opts: Opts) -> Opts {
opts
}
pub fn permissions(opts: Opts, val: Int) -> Opts {
Opts(..opts, permissions: Some(val))
}
pub fn offset_lines(opts: Opts, val: Int) -> Opts {
Opts(..opts, offset_lines: Some(val))
}
pub fn limit_lines(opts: Opts, val: Int) -> Opts {
Opts(..opts, limit_lines: Some(val))
}
pub fn exclude_metadata(opts: Opts, val: Bool) -> Opts {
Opts(..opts, exclude_metadata: Some(val))
}
pub fn allow_parent_dir_path(opts: Opts, val: Bool) -> Opts {
Opts(..opts, allow_parent_dir_path: 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 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 all(opts: Opts, val: Bool) -> Opts {
Opts(..opts, all: Some(val))
}
pub fn first_from(opts: Opts, val: Int) -> Opts {
Opts(..opts, first_from: Some(val))
}
fn encode_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 })
}
pub fn file(name name: String, contents contents: String, with with_fn: fn(Opts) -> Opts) -> t.File {
let opts = with_fn(defaults())
let field = types.Field(name: "file", args: list.append([#("name", types.GString(name)), #("contents", types.GString(contents))], encode_file(opts)), subfields: [])
t.File(op: types.Pure([field]))
}
/// Parse as an env file
pub fn as_env_file(parent: t.File) -> t.EnvFile {
let field = types.Field(name: "asEnvFile", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.EnvFile(op: new_op)
}
/// Parse the file contents as JSON.
pub fn as_j_s_o_n(parent: t.File) -> t.JSONValue {
let field = types.Field(name: "asJSON", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.JSONValue(op: new_op)
}
/// Change the owner of the file recursively.
pub fn chown(parent: t.File, owner owner: String) -> t.File {
let field = types.Field(name: "chown", args: [#("owner", types.GString(owner))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.File(op: new_op)
}
fn encode_contents(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.offset_lines {
Some(val) -> Ok(#("offsetLines", types.GInt(val)))
None -> Error(Nil)
},
case opts.limit_lines {
Some(val) -> Ok(#("limitLines", types.GInt(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Retrieves the contents of the file.
pub fn contents(parent: t.File, 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: "contents", args: encode_contents(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("contents")))
}
}
)
}
handler(interpreter.run(op, client))
}
fn encode_digest(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.exclude_metadata {
Some(val) -> Ok(#("excludeMetadata", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Return the file'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.File, 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: "digest", args: encode_digest(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("digest")))
}
}
)
}
handler(interpreter.run(op, client))
}
fn encode_export(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.allow_parent_dir_path {
Some(val) -> Ok(#("allowParentDirPath", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Writes the file to a file path on the host.
pub fn export(parent: t.File, 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))
}
/// A unique identifier for this File.
pub fn id(parent: t.File) -> t.File {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.File(op: new_op)
}
/// Retrieves the name of the file.
pub fn name(parent: t.File, 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.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)
},
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)
}
], 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.File, 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))
}
/// Retrieves the size of the file, in bytes.
pub fn size(parent: t.File, client client: Client, then handler: fn(Try(Int)) -> a) -> a {
let field = types.Field(name: "size", 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.int)) {
Ok(val) -> types.Pure(Ok(val))
Error(_) -> types.Pure(Error(types.DecodingError("size")))
}
}
)
}
handler(interpreter.run(op, client))
}
/// Return file status
pub fn stat(parent: t.File) -> t.Stat {
let field = types.Field(name: "stat", args: [], 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.File) -> t.File {
let field = types.Field(name: "sync", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.File(op: new_op)
}
/// Retrieves this file with its name set to the given name.
pub fn with_name(parent: t.File, name name: String) -> t.File {
let field = types.Field(name: "withName", args: [#("name", types.GString(name))], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.File(op: new_op)
}
fn encode_with_replaced(opts: Opts) -> List(#(String, types.Value)) {
list.filter_map([
case opts.all {
Some(val) -> Ok(#("all", types.GBool(val)))
None -> Error(Nil)
},
case opts.first_from {
Some(val) -> Ok(#("firstFrom", types.GInt(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Retrieves the file with content replaced with the given text.
/// If 'all' is true, all occurrences of the pattern will be replaced.
/// If 'firstAfter' is specified, only the first match starting at the specified line will be replaced.
/// If neither are specified, and there are multiple matches for the pattern, this will error.
/// If there are no matches for the pattern, this will error.
pub fn with_replaced(parent: t.File, search search: String, replacement replacement: String, with with_fn: fn(Opts) -> Opts) -> t.File {
let opts = with_fn(defaults())
let field = types.Field(name: "withReplaced", args: list.append([#("search", types.GString(search)), #("replacement", types.GString(replacement))], encode_with_replaced(opts)), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.File(op: new_op)
}
/// Retrieves this file with its created/modified timestamps set to the given time.
pub fn with_timestamps(parent: t.File, timestamp timestamp: Int) -> t.File {
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.File(op: new_op)
}