Current section
Files
Jump to
Current section
Files
src/dagger/dsl/address.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(
exclude: Option(List(String)),
include: Option(List(String)),
gitignore: Option(Bool),
no_cache: Option(Bool),
)
}
fn defaults() -> Opts {
Opts(
exclude: None,
include: None,
gitignore: None,
no_cache: None,
)
}
pub fn none(opts: Opts) -> Opts {
opts
}
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 no_cache(opts: Opts, val: Bool) -> Opts {
Opts(..opts, no_cache: Some(val))
}
pub fn address(value value: String) -> t.Address {
let field = types.Field(name: "address", args: [#("value", types.GString(value))], subfields: [])
t.Address(op: types.Pure([field]))
}
/// Load a container from the address.
pub fn container(parent: t.Address) -> t.Container {
let field = types.Field(name: "container", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Container(op: new_op)
}
fn encode_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.no_cache {
Some(val) -> Ok(#("noCache", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Load a directory from the address.
pub fn directory(parent: t.Address, with with_fn: fn(Opts) -> Opts) -> t.Directory {
let opts = with_fn(defaults())
let field = types.Field(name: "directory", args: encode_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_file(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.no_cache {
Some(val) -> Ok(#("noCache", types.GBool(val)))
None -> Error(Nil)
}
], fn(x) { x })
}
/// Load a file from the address.
pub fn file(parent: t.Address, with with_fn: fn(Opts) -> Opts) -> t.File {
let opts = with_fn(defaults())
let field = types.Field(name: "file", args: encode_file(opts), subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.File(op: new_op)
}
/// Load a git ref (branch, tag or commit) from the address.
pub fn git_ref(parent: t.Address) -> t.GitRef {
let field = types.Field(name: "gitRef", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.GitRef(op: new_op)
}
/// Load a git repository from the address.
pub fn git_repository(parent: t.Address) -> t.GitRepository {
let field = types.Field(name: "gitRepository", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.GitRepository(op: new_op)
}
/// A unique identifier for this Address.
pub fn id(parent: t.Address) -> t.Address {
let field = types.Field(name: "id", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Address(op: new_op)
}
/// Load a secret from the address.
pub fn secret(parent: t.Address) -> t.Secret {
let field = types.Field(name: "secret", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Secret(op: new_op)
}
/// Load a service from the address.
pub fn service(parent: t.Address) -> t.Service {
let field = types.Field(name: "service", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Service(op: new_op)
}
/// Load a local socket from the address.
pub fn socket(parent: t.Address) -> t.Socket {
let field = types.Field(name: "socket", args: [], subfields: [])
let new_op = {
use q <- types.bind(parent.op)
types.Pure(list.append(q, [field]))
}
t.Socket(op: new_op)
}
/// The address value
pub fn value(parent: t.Address, client client: Client, then handler: fn(Try(String)) -> a) -> a {
let field = types.Field(name: "value", 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("value")))
}
}
)
}
handler(interpreter.run(op, client))
}