mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2024-11-25 16:32:42 +01:00
feat(sdk): with _opts methods
Now all opt values enter into a _opts function instead of the original. This avoids a lot of verbosity for both None in the case opts are unwanted, and Some() if they actually are. They are used like so: ```rust client.container().from("..."); client.container_opts(Some(ContainerOpts{ ... })) ``` Some from opts will be removed in a future commit/pr
This commit is contained in:
parent
02006d40fc
commit
9762da895a
@ -39,18 +39,44 @@ pub fn format_function(funcs: &CommonFunctions, field: &FullTypeFields) -> Optio
|
||||
.pipe(|t| &t.type_ref)
|
||||
.pipe(|t| render_output_type(funcs, t));
|
||||
|
||||
Some(quote! {
|
||||
$(signature)(
|
||||
$(args)
|
||||
) -> $(output_type) {
|
||||
let mut query = self.selection.select($(quoted(field.name.as_ref())));
|
||||
if let Some((args, true)) = args {
|
||||
let required_args = format_required_function_args(funcs, field);
|
||||
Some(quote! {
|
||||
$(&signature)(
|
||||
$(required_args)
|
||||
) -> $(output_type.as_ref()) {
|
||||
let mut query = self.selection.select($(quoted(field.name.as_ref())));
|
||||
|
||||
$(render_required_args(funcs, field))
|
||||
$(render_optional_args(funcs, field))
|
||||
$(render_required_args(funcs, field))
|
||||
|
||||
$(render_execution(funcs, field))
|
||||
}
|
||||
})
|
||||
$(render_execution(funcs, field))
|
||||
}
|
||||
|
||||
$(&signature)_opts(
|
||||
$args
|
||||
) -> $(output_type) {
|
||||
let mut query = self.selection.select($(quoted(field.name.as_ref())));
|
||||
|
||||
$(render_required_args(funcs, field))
|
||||
$(render_optional_args(funcs, field))
|
||||
|
||||
$(render_execution(funcs, field))
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Some(quote! {
|
||||
$(signature)(
|
||||
$(if let Some((args, _)) = args => $args)
|
||||
) -> $(output_type) {
|
||||
let mut query = self.selection.select($(quoted(field.name.as_ref())));
|
||||
|
||||
$(render_required_args(funcs, field))
|
||||
$(render_optional_args(funcs, field))
|
||||
|
||||
$(render_execution(funcs, field))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn render_required_args(_funcs: &CommonFunctions, field: &FullTypeFields) -> Option<rust::Tokens> {
|
||||
@ -215,7 +241,10 @@ fn render_execution(funcs: &CommonFunctions, field: &FullTypeFields) -> rust::To
|
||||
}
|
||||
}
|
||||
|
||||
fn format_function_args(funcs: &CommonFunctions, field: &FullTypeFields) -> Option<rust::Tokens> {
|
||||
fn format_function_args(
|
||||
funcs: &CommonFunctions,
|
||||
field: &FullTypeFields,
|
||||
) -> Option<(rust::Tokens, bool)> {
|
||||
if let Some(args) = field.args.as_ref() {
|
||||
let args = args
|
||||
.into_iter()
|
||||
@ -241,14 +270,51 @@ fn format_function_args(funcs: &CommonFunctions, field: &FullTypeFields) -> Opti
|
||||
};
|
||||
|
||||
if type_field_has_optional(field) {
|
||||
Some(quote! {
|
||||
$(required_args)
|
||||
opts: Option<$(field_options_struct_name(field))>
|
||||
})
|
||||
Some((
|
||||
quote! {
|
||||
$(required_args)
|
||||
opts: Option<$(field_options_struct_name(field))>
|
||||
},
|
||||
true,
|
||||
))
|
||||
} else {
|
||||
Some(required_args)
|
||||
Some((required_args, false))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn format_required_function_args(
|
||||
funcs: &CommonFunctions,
|
||||
field: &FullTypeFields,
|
||||
) -> Option<rust::Tokens> {
|
||||
if let Some(args) = field.args.as_ref() {
|
||||
let args = args
|
||||
.into_iter()
|
||||
.map(|a| {
|
||||
a.as_ref().and_then(|s| {
|
||||
if type_ref_is_optional(&s.input_value.type_) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let t = funcs.format_input_type(&s.input_value.type_);
|
||||
let n = format_struct_name(&s.input_value.name);
|
||||
|
||||
Some(quote! {
|
||||
$(n): $(t),
|
||||
})
|
||||
})
|
||||
})
|
||||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
let required_args = quote! {
|
||||
&self,
|
||||
$(for arg in args join ($['\r']) => $arg)
|
||||
};
|
||||
|
||||
Some(required_args)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use dagger_sdk::HostDirectoryOpts;
|
||||
fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
|
||||
let host_source_dir = client.host().directory(
|
||||
let host_source_dir = client.host().directory_opts(
|
||||
"examples/build-the-application/app",
|
||||
Some(HostDirectoryOpts {
|
||||
exclude: Some(vec!["node_modules".into(), "ci/".into()]),
|
||||
@ -12,23 +12,23 @@ fn main() -> eyre::Result<()> {
|
||||
);
|
||||
|
||||
let source = client
|
||||
.container(None)
|
||||
.container()
|
||||
.from("node:16")
|
||||
.with_mounted_directory("/src", host_source_dir.id()?);
|
||||
|
||||
let runner = source
|
||||
.with_workdir("/src")
|
||||
.with_exec(vec!["npm", "install"], None);
|
||||
.with_exec(vec!["npm", "install"]);
|
||||
|
||||
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"], None);
|
||||
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"]);
|
||||
|
||||
let build_dir = test
|
||||
.with_exec(vec!["npm", "run", "build"], None)
|
||||
.with_exec(vec!["npm", "run", "build"])
|
||||
.directory("./build");
|
||||
|
||||
let _ = build_dir.export("./build");
|
||||
|
||||
let entries = build_dir.entries(None);
|
||||
let entries = build_dir.entries();
|
||||
|
||||
println!("build dir contents: \n {:?}", entries);
|
||||
|
||||
|
@ -3,7 +3,7 @@ use rand::Rng;
|
||||
fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
|
||||
let host_source_dir = client.host().directory(
|
||||
let host_source_dir = client.host().directory_opts(
|
||||
"./examples/caching/app",
|
||||
Some(
|
||||
dagger_sdk::HostDirectoryOptsBuilder::default()
|
||||
@ -15,31 +15,28 @@ fn main() -> eyre::Result<()> {
|
||||
let node_cache = client.cache_volume("node").id()?;
|
||||
|
||||
let source = client
|
||||
.container(None)
|
||||
.container()
|
||||
.from("node:16")
|
||||
.with_mounted_directory("/src", host_source_dir.id()?)
|
||||
.with_mounted_cache("/src/node_modules", node_cache, None);
|
||||
.with_mounted_cache("/src/node_modules", node_cache);
|
||||
|
||||
let runner = source
|
||||
.with_workdir("/src")
|
||||
.with_exec(vec!["npm", "install"], None);
|
||||
.with_exec(vec!["npm", "install"]);
|
||||
|
||||
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"], None);
|
||||
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"]);
|
||||
|
||||
let build_dir = test
|
||||
.with_exec(vec!["npm", "run", "build"], None)
|
||||
.with_exec(vec!["npm", "run", "build"])
|
||||
.directory("./build");
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let ref_ = client
|
||||
.container(None)
|
||||
.container()
|
||||
.from("nginx")
|
||||
.with_directory("/usr/share/nginx/html", build_dir.id()?, None)
|
||||
.publish(
|
||||
format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()),
|
||||
None,
|
||||
)?;
|
||||
.with_directory("/usr/share/nginx/html", build_dir.id()?)
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
|
||||
|
||||
println!("published image to: {}", ref_);
|
||||
|
||||
|
@ -7,15 +7,12 @@ fn main() -> eyre::Result<()> {
|
||||
|
||||
let context_dir = client
|
||||
.host()
|
||||
.directory("./examples/existing-dockerfile/app", None);
|
||||
.directory("./examples/existing-dockerfile/app");
|
||||
|
||||
let ref_ = client
|
||||
.container(None)
|
||||
.build(context_dir.id()?, None)
|
||||
.publish(
|
||||
format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()),
|
||||
None,
|
||||
)?;
|
||||
.container()
|
||||
.build(context_dir.id()?)
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
|
||||
|
||||
println!("published image to: {}", ref_);
|
||||
|
||||
|
@ -2,9 +2,9 @@ fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
|
||||
let version = client
|
||||
.container(None)
|
||||
.container()
|
||||
.from("golang:1.19")
|
||||
.with_exec(vec!["go", "version".into()], None)
|
||||
.with_exec(vec!["go", "version".into()])
|
||||
.stdout()?;
|
||||
|
||||
println!("Hello from Dagger and {}", version.trim());
|
||||
|
@ -4,7 +4,7 @@ use rand::Rng;
|
||||
fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
|
||||
let host_source_dir = client.host().directory(
|
||||
let host_source_dir = client.host().directory_opts(
|
||||
"examples/publish-the-application/app",
|
||||
Some(HostDirectoryOpts {
|
||||
exclude: Some(vec!["node_modules", "ci/"]),
|
||||
@ -13,30 +13,27 @@ fn main() -> eyre::Result<()> {
|
||||
);
|
||||
|
||||
let source = client
|
||||
.container(None)
|
||||
.container()
|
||||
.from("node:16")
|
||||
.with_mounted_directory("/src", host_source_dir.id()?);
|
||||
|
||||
let runner = source
|
||||
.with_workdir("/src")
|
||||
.with_exec(vec!["npm", "install"], None);
|
||||
.with_exec(vec!["npm", "install"]);
|
||||
|
||||
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"], None);
|
||||
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"]);
|
||||
|
||||
let build_dir = test
|
||||
.with_exec(vec!["npm", "run", "build"], None)
|
||||
.with_exec(vec!["npm", "run", "build"])
|
||||
.directory("./build");
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let ref_ = client
|
||||
.container(None)
|
||||
.container()
|
||||
.from("nginx")
|
||||
.with_directory("/usr/share/nginx/html", build_dir.id()?, None)
|
||||
.publish(
|
||||
format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()),
|
||||
None,
|
||||
)?;
|
||||
.with_directory("/usr/share/nginx/html", build_dir.id()?)
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
|
||||
|
||||
println!("published image to: {}", ref_);
|
||||
|
||||
|
@ -5,7 +5,7 @@ fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
let output = "examples/publish-the-application/app/build";
|
||||
|
||||
let host_source_dir = client.host().directory(
|
||||
let host_source_dir = client.host().directory_opts(
|
||||
"examples/publish-the-application/app",
|
||||
Some(HostDirectoryOpts {
|
||||
exclude: Some(vec!["node_modules", "ci/"]),
|
||||
@ -14,35 +14,31 @@ fn main() -> eyre::Result<()> {
|
||||
);
|
||||
|
||||
let source = client
|
||||
.container(None)
|
||||
.container()
|
||||
.from("node:16")
|
||||
.with_mounted_directory("/src", host_source_dir.id()?);
|
||||
|
||||
let runner = source
|
||||
.with_workdir("/src")
|
||||
.with_exec(vec!["npm", "install"], None);
|
||||
.with_exec(vec!["npm", "install"]);
|
||||
|
||||
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"], None);
|
||||
let test = runner.with_exec(vec!["npm", "test", "--", "--watchAll=false"]);
|
||||
|
||||
let _ = test
|
||||
.with_exec(vec!["npm", "run", "build"], None)
|
||||
.with_exec(vec!["npm", "run", "build"])
|
||||
.directory("./build")
|
||||
.export(output);
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let ref_ = client
|
||||
.container(None)
|
||||
.container()
|
||||
.from("nginx")
|
||||
.with_directory(
|
||||
"/usr/share/nginx/html",
|
||||
client.host().directory(output, None).id()?,
|
||||
None,
|
||||
client.host().directory(output).id()?,
|
||||
)
|
||||
.publish(
|
||||
format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()),
|
||||
None,
|
||||
)?;
|
||||
.publish(format!("ttl.sh/hello-dagger-rs-{}:1h", rng.gen::<u64>()))?;
|
||||
|
||||
println!("published image to: {}", ref_);
|
||||
|
||||
|
@ -3,7 +3,7 @@ use dagger_sdk::HostDirectoryOpts;
|
||||
fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
|
||||
let host_source_dir = client.host().directory(
|
||||
let host_source_dir = client.host().directory_opts(
|
||||
"examples/test-the-application/app",
|
||||
Some(HostDirectoryOpts {
|
||||
exclude: Some(vec!["node_modules", "ci/"]),
|
||||
@ -12,16 +12,16 @@ fn main() -> eyre::Result<()> {
|
||||
);
|
||||
|
||||
let source = client
|
||||
.container(None)
|
||||
.container()
|
||||
.from("node:16")
|
||||
.with_mounted_directory("/src", host_source_dir.id()?);
|
||||
|
||||
let runner = source
|
||||
.with_workdir("/src")
|
||||
.with_exec(vec!["npm", "install"], None);
|
||||
.with_exec(vec!["npm", "install"]);
|
||||
|
||||
let out = runner
|
||||
.with_exec(vec!["npm", "test", "--", "--watchAll=false"], None)
|
||||
.with_exec(vec!["npm", "test", "--", "--watchAll=false"])
|
||||
.stderr()?;
|
||||
|
||||
println!("{}", out);
|
||||
|
@ -22,8 +22,8 @@ pub struct SecretId(String);
|
||||
pub struct SocketId(String);
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct BuildArg {
|
||||
pub name: String,
|
||||
pub value: String,
|
||||
pub name: String,
|
||||
}
|
||||
pub struct CacheVolume {
|
||||
pub proc: Arc<Child>,
|
||||
@ -125,7 +125,19 @@ pub struct ContainerWithNewFileOpts<'a> {
|
||||
}
|
||||
|
||||
impl Container {
|
||||
pub fn build(&self, context: DirectoryId, opts: Option<ContainerBuildOpts>) -> Container {
|
||||
pub fn build(&self, context: DirectoryId) -> Container {
|
||||
let mut query = self.selection.select("build");
|
||||
|
||||
query = query.arg("context", context);
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn build_opts(&self, context: DirectoryId, opts: Option<ContainerBuildOpts>) -> Container {
|
||||
let mut query = self.selection.select("build");
|
||||
|
||||
query = query.arg("context", context);
|
||||
@ -184,7 +196,17 @@ impl Container {
|
||||
conn: self.conn.clone(),
|
||||
}];
|
||||
}
|
||||
pub fn exec(&self, opts: Option<ContainerExecOpts>) -> Container {
|
||||
pub fn exec(&self) -> Container {
|
||||
let mut query = self.selection.select("exec");
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn exec_opts(&self, opts: Option<ContainerExecOpts>) -> Container {
|
||||
let mut query = self.selection.select("exec");
|
||||
|
||||
if let Some(opts) = opts {
|
||||
@ -219,7 +241,15 @@ impl Container {
|
||||
|
||||
query.execute(&graphql_client(&self.conn))
|
||||
}
|
||||
pub fn export(
|
||||
pub fn export(&self, path: impl Into<String>) -> eyre::Result<bool> {
|
||||
let mut query = self.selection.select("export");
|
||||
|
||||
query = query.arg("path", path.into());
|
||||
|
||||
query.execute(&graphql_client(&self.conn))
|
||||
}
|
||||
|
||||
pub fn export_opts(
|
||||
&self,
|
||||
path: impl Into<String>,
|
||||
opts: Option<ContainerExportOpts>,
|
||||
@ -292,7 +322,19 @@ impl Container {
|
||||
|
||||
query.execute(&graphql_client(&self.conn))
|
||||
}
|
||||
pub fn pipeline(
|
||||
pub fn pipeline(&self, name: impl Into<String>) -> Container {
|
||||
let mut query = self.selection.select("pipeline");
|
||||
|
||||
query = query.arg("name", name.into());
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn pipeline_opts(
|
||||
&self,
|
||||
name: impl Into<String>,
|
||||
opts: Option<ContainerPipelineOpts>,
|
||||
@ -317,7 +359,15 @@ impl Container {
|
||||
|
||||
query.execute(&graphql_client(&self.conn))
|
||||
}
|
||||
pub fn publish(
|
||||
pub fn publish(&self, address: impl Into<String>) -> eyre::Result<String> {
|
||||
let mut query = self.selection.select("publish");
|
||||
|
||||
query = query.arg("address", address.into());
|
||||
|
||||
query.execute(&graphql_client(&self.conn))
|
||||
}
|
||||
|
||||
pub fn publish_opts(
|
||||
&self,
|
||||
address: impl Into<String>,
|
||||
opts: Option<ContainerPublishOpts>,
|
||||
@ -357,7 +407,17 @@ impl Container {
|
||||
|
||||
query.execute(&graphql_client(&self.conn))
|
||||
}
|
||||
pub fn with_default_args(&self, opts: Option<ContainerWithDefaultArgsOpts>) -> Container {
|
||||
pub fn with_default_args(&self) -> Container {
|
||||
let mut query = self.selection.select("withDefaultArgs");
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn with_default_args_opts(&self, opts: Option<ContainerWithDefaultArgsOpts>) -> Container {
|
||||
let mut query = self.selection.select("withDefaultArgs");
|
||||
|
||||
if let Some(opts) = opts {
|
||||
@ -372,7 +432,20 @@ impl Container {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn with_directory(
|
||||
pub fn with_directory(&self, path: impl Into<String>, directory: DirectoryId) -> Container {
|
||||
let mut query = self.selection.select("withDirectory");
|
||||
|
||||
query = query.arg("path", path.into());
|
||||
query = query.arg("directory", directory);
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn with_directory_opts(
|
||||
&self,
|
||||
path: impl Into<String>,
|
||||
directory: DirectoryId,
|
||||
@ -427,7 +500,22 @@ impl Container {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn with_exec(
|
||||
pub fn with_exec(&self, args: Vec<impl Into<String>>) -> Container {
|
||||
let mut query = self.selection.select("withExec");
|
||||
|
||||
query = query.arg(
|
||||
"args",
|
||||
args.into_iter().map(|i| i.into()).collect::<Vec<String>>(),
|
||||
);
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn with_exec_opts(
|
||||
&self,
|
||||
args: Vec<impl Into<String>>,
|
||||
opts: Option<ContainerWithExecOpts>,
|
||||
@ -473,7 +561,20 @@ impl Container {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn with_file(
|
||||
pub fn with_file(&self, path: impl Into<String>, source: FileId) -> Container {
|
||||
let mut query = self.selection.select("withFile");
|
||||
|
||||
query = query.arg("path", path.into());
|
||||
query = query.arg("source", source);
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn with_file_opts(
|
||||
&self,
|
||||
path: impl Into<String>,
|
||||
source: FileId,
|
||||
@ -507,7 +608,20 @@ impl Container {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn with_mounted_cache(
|
||||
pub fn with_mounted_cache(&self, path: impl Into<String>, cache: CacheId) -> Container {
|
||||
let mut query = self.selection.select("withMountedCache");
|
||||
|
||||
query = query.arg("path", path.into());
|
||||
query = query.arg("cache", cache);
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn with_mounted_cache_opts(
|
||||
&self,
|
||||
path: impl Into<String>,
|
||||
cache: CacheId,
|
||||
@ -583,7 +697,19 @@ impl Container {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn with_new_file(
|
||||
pub fn with_new_file(&self, path: impl Into<String>) -> Container {
|
||||
let mut query = self.selection.select("withNewFile");
|
||||
|
||||
query = query.arg("path", path.into());
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn with_new_file_opts(
|
||||
&self,
|
||||
path: impl Into<String>,
|
||||
opts: Option<ContainerWithNewFileOpts>,
|
||||
@ -815,7 +941,17 @@ impl Directory {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn docker_build(&self, opts: Option<DirectoryDockerBuildOpts>) -> Container {
|
||||
pub fn docker_build(&self) -> Container {
|
||||
let mut query = self.selection.select("dockerBuild");
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn docker_build_opts(&self, opts: Option<DirectoryDockerBuildOpts>) -> Container {
|
||||
let mut query = self.selection.select("dockerBuild");
|
||||
|
||||
if let Some(opts) = opts {
|
||||
@ -839,7 +975,13 @@ impl Directory {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn entries(&self, opts: Option<DirectoryEntriesOpts>) -> eyre::Result<Vec<String>> {
|
||||
pub fn entries(&self) -> eyre::Result<Vec<String>> {
|
||||
let mut query = self.selection.select("entries");
|
||||
|
||||
query.execute(&graphql_client(&self.conn))
|
||||
}
|
||||
|
||||
pub fn entries_opts(&self, opts: Option<DirectoryEntriesOpts>) -> eyre::Result<Vec<String>> {
|
||||
let mut query = self.selection.select("entries");
|
||||
|
||||
if let Some(opts) = opts {
|
||||
@ -884,7 +1026,19 @@ impl Directory {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn pipeline(
|
||||
pub fn pipeline(&self, name: impl Into<String>) -> Directory {
|
||||
let mut query = self.selection.select("pipeline");
|
||||
|
||||
query = query.arg("name", name.into());
|
||||
|
||||
return Directory {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn pipeline_opts(
|
||||
&self,
|
||||
name: impl Into<String>,
|
||||
opts: Option<DirectoryPipelineOpts>,
|
||||
@ -904,7 +1058,20 @@ impl Directory {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn with_directory(
|
||||
pub fn with_directory(&self, path: impl Into<String>, directory: DirectoryId) -> Directory {
|
||||
let mut query = self.selection.select("withDirectory");
|
||||
|
||||
query = query.arg("path", path.into());
|
||||
query = query.arg("directory", directory);
|
||||
|
||||
return Directory {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn with_directory_opts(
|
||||
&self,
|
||||
path: impl Into<String>,
|
||||
directory: DirectoryId,
|
||||
@ -929,7 +1096,20 @@ impl Directory {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn with_file(
|
||||
pub fn with_file(&self, path: impl Into<String>, source: FileId) -> Directory {
|
||||
let mut query = self.selection.select("withFile");
|
||||
|
||||
query = query.arg("path", path.into());
|
||||
query = query.arg("source", source);
|
||||
|
||||
return Directory {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn with_file_opts(
|
||||
&self,
|
||||
path: impl Into<String>,
|
||||
source: FileId,
|
||||
@ -951,7 +1131,19 @@ impl Directory {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn with_new_directory(
|
||||
pub fn with_new_directory(&self, path: impl Into<String>) -> Directory {
|
||||
let mut query = self.selection.select("withNewDirectory");
|
||||
|
||||
query = query.arg("path", path.into());
|
||||
|
||||
return Directory {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn with_new_directory_opts(
|
||||
&self,
|
||||
path: impl Into<String>,
|
||||
opts: Option<DirectoryWithNewDirectoryOpts>,
|
||||
@ -971,7 +1163,20 @@ impl Directory {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn with_new_file(
|
||||
pub fn with_new_file(&self, path: impl Into<String>, contents: impl Into<String>) -> Directory {
|
||||
let mut query = self.selection.select("withNewFile");
|
||||
|
||||
query = query.arg("path", path.into());
|
||||
query = query.arg("contents", contents.into());
|
||||
|
||||
return Directory {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn with_new_file_opts(
|
||||
&self,
|
||||
path: impl Into<String>,
|
||||
contents: impl Into<String>,
|
||||
@ -1115,7 +1320,17 @@ impl GitRef {
|
||||
|
||||
query.execute(&graphql_client(&self.conn))
|
||||
}
|
||||
pub fn tree(&self, opts: Option<GitRefTreeOpts>) -> Directory {
|
||||
pub fn tree(&self) -> Directory {
|
||||
let mut query = self.selection.select("tree");
|
||||
|
||||
return Directory {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn tree_opts(&self, opts: Option<GitRefTreeOpts>) -> Directory {
|
||||
let mut query = self.selection.select("tree");
|
||||
|
||||
if let Some(opts) = opts {
|
||||
@ -1207,7 +1422,23 @@ pub struct HostWorkdirOpts<'a> {
|
||||
}
|
||||
|
||||
impl Host {
|
||||
pub fn directory(&self, path: impl Into<String>, opts: Option<HostDirectoryOpts>) -> Directory {
|
||||
pub fn directory(&self, path: impl Into<String>) -> Directory {
|
||||
let mut query = self.selection.select("directory");
|
||||
|
||||
query = query.arg("path", path.into());
|
||||
|
||||
return Directory {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn directory_opts(
|
||||
&self,
|
||||
path: impl Into<String>,
|
||||
opts: Option<HostDirectoryOpts>,
|
||||
) -> Directory {
|
||||
let mut query = self.selection.select("directory");
|
||||
|
||||
query = query.arg("path", path.into());
|
||||
@ -1248,7 +1479,17 @@ impl Host {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn workdir(&self, opts: Option<HostWorkdirOpts>) -> Directory {
|
||||
pub fn workdir(&self) -> Directory {
|
||||
let mut query = self.selection.select("workdir");
|
||||
|
||||
return Directory {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn workdir_opts(&self, opts: Option<HostWorkdirOpts>) -> Directory {
|
||||
let mut query = self.selection.select("workdir");
|
||||
|
||||
if let Some(opts) = opts {
|
||||
@ -1399,7 +1640,17 @@ impl Query {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn container(&self, opts: Option<QueryContainerOpts>) -> Container {
|
||||
pub fn container(&self) -> Container {
|
||||
let mut query = self.selection.select("container");
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn container_opts(&self, opts: Option<QueryContainerOpts>) -> Container {
|
||||
let mut query = self.selection.select("container");
|
||||
|
||||
if let Some(opts) = opts {
|
||||
@ -1422,7 +1673,17 @@ impl Query {
|
||||
|
||||
query.execute(&graphql_client(&self.conn))
|
||||
}
|
||||
pub fn directory(&self, opts: Option<QueryDirectoryOpts>) -> Directory {
|
||||
pub fn directory(&self) -> Directory {
|
||||
let mut query = self.selection.select("directory");
|
||||
|
||||
return Directory {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn directory_opts(&self, opts: Option<QueryDirectoryOpts>) -> Directory {
|
||||
let mut query = self.selection.select("directory");
|
||||
|
||||
if let Some(opts) = opts {
|
||||
@ -1448,7 +1709,19 @@ impl Query {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn git(&self, url: impl Into<String>, opts: Option<QueryGitOpts>) -> GitRepository {
|
||||
pub fn git(&self, url: impl Into<String>) -> GitRepository {
|
||||
let mut query = self.selection.select("git");
|
||||
|
||||
query = query.arg("url", url.into());
|
||||
|
||||
return GitRepository {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn git_opts(&self, url: impl Into<String>, opts: Option<QueryGitOpts>) -> GitRepository {
|
||||
let mut query = self.selection.select("git");
|
||||
|
||||
query = query.arg("url", url.into());
|
||||
@ -1484,7 +1757,19 @@ impl Query {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn pipeline(&self, name: impl Into<String>, opts: Option<QueryPipelineOpts>) -> Query {
|
||||
pub fn pipeline(&self, name: impl Into<String>) -> Query {
|
||||
let mut query = self.selection.select("pipeline");
|
||||
|
||||
query = query.arg("name", name.into());
|
||||
|
||||
return Query {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn pipeline_opts(&self, name: impl Into<String>, opts: Option<QueryPipelineOpts>) -> Query {
|
||||
let mut query = self.selection.select("pipeline");
|
||||
|
||||
query = query.arg("name", name.into());
|
||||
@ -1522,7 +1807,17 @@ impl Query {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
pub fn socket(&self, opts: Option<QuerySocketOpts>) -> Socket {
|
||||
pub fn socket(&self) -> Socket {
|
||||
let mut query = self.selection.select("socket");
|
||||
|
||||
return Socket {
|
||||
proc: self.proc.clone(),
|
||||
selection: query,
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn socket_opts(&self, opts: Option<QuerySocketOpts>) -> Socket {
|
||||
let mut query = self.selection.select("socket");
|
||||
|
||||
if let Some(opts) = opts {
|
||||
|
@ -4,10 +4,10 @@ use dagger_sdk::{connect, ContainerExecOptsBuilder};
|
||||
fn test_example_container() {
|
||||
let client = connect().unwrap();
|
||||
|
||||
let alpine = client.container(None).from("alpine:3.16.2");
|
||||
let alpine = client.container().from("alpine:3.16.2");
|
||||
|
||||
let out = alpine
|
||||
.exec(Some(
|
||||
.exec_opts(Some(
|
||||
ContainerExecOptsBuilder::default()
|
||||
.args(vec!["cat", "/etc/alpine-release"])
|
||||
.build()
|
||||
|
Loading…
Reference in New Issue
Block a user