diff --git a/crates/dagger-codegen/src/rust/templates/enum_tmpl.rs b/crates/dagger-codegen/src/rust/templates/enum_tmpl.rs index e0df6c9..965ca9a 100644 --- a/crates/dagger-codegen/src/rust/templates/enum_tmpl.rs +++ b/crates/dagger-codegen/src/rust/templates/enum_tmpl.rs @@ -1,6 +1,7 @@ use dagger_core::introspection::FullType; use genco::prelude::rust; use genco::quote; +use itertools::Itertools; fn render_enum_values(values: &FullType) -> Option { let values = values @@ -10,6 +11,7 @@ fn render_enum_values(values: &FullType) -> Option { .map(|values| { values .into_iter() + .sorted_by_key(|a| &a.name) .map(|val| quote! { $(val.name.as_ref()), }) }) .flatten() diff --git a/crates/dagger-sdk/src/gen.rs b/crates/dagger-sdk/src/gen.rs index 85ad27b..696ffe7 100644 --- a/crates/dagger-sdk/src/gen.rs +++ b/crates/dagger-sdk/src/gen.rs @@ -106,8 +106,8 @@ impl Into for String { } #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] pub struct BuildArg { - pub name: String, pub value: String, + pub name: String, } #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] pub struct PipelineLabel { @@ -122,8 +122,10 @@ pub struct CacheVolume { } impl CacheVolume { - pub async fn id(&self) -> eyre::Result { - let query = self.selection.select("id"); + pub async fn id( + &self, + ) -> eyre::Result { + let mut query = self.selection.select("id"); query.execute(&graphql_client(&self.conn)).await } @@ -137,6 +139,7 @@ pub struct Container { #[derive(Builder, Debug, PartialEq)] pub struct ContainerBuildOpts<'a> { + /// Path to the Dockerfile to use. /// Default: './Dockerfile'. #[builder(setter(into, strip_option), default)] @@ -150,6 +153,7 @@ pub struct ContainerBuildOpts<'a> { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerEndpointOpts<'a> { + /// The exposed port number for the endpoint #[builder(setter(into, strip_option), default)] pub port: Option, @@ -159,6 +163,7 @@ pub struct ContainerEndpointOpts<'a> { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerExecOpts<'a> { + /// Command to run instead of the container's default command (e.g., ["run", "main.go"]). #[builder(setter(into, strip_option), default)] pub args: Option>, @@ -179,6 +184,7 @@ pub struct ContainerExecOpts<'a> { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerExportOpts { + /// Identifiers for other platform specific containers. /// Used for multi-platform image. #[builder(setter(into, strip_option), default)] @@ -186,6 +192,7 @@ pub struct ContainerExportOpts { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerPipelineOpts<'a> { + /// Pipeline description. #[builder(setter(into, strip_option), default)] pub description: Option<&'a str>, @@ -195,6 +202,7 @@ pub struct ContainerPipelineOpts<'a> { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerPublishOpts { + /// Identifiers for other platform specific containers. /// Used for multi-platform image. #[builder(setter(into, strip_option), default)] @@ -202,12 +210,14 @@ pub struct ContainerPublishOpts { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithDefaultArgsOpts<'a> { + /// Arguments to prepend to future executions (e.g., ["-v", "--no-cache"]). #[builder(setter(into, strip_option), default)] pub args: Option>, } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithDirectoryOpts<'a> { + /// Patterns to exclude in the written directory (e.g., ["node_modules/**", ".gitignore", ".git/"]). #[builder(setter(into, strip_option), default)] pub exclude: Option>, @@ -217,6 +227,7 @@ pub struct ContainerWithDirectoryOpts<'a> { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithExecOpts<'a> { + /// Content to write to the command's standard input before closing (e.g., "Hello world"). #[builder(setter(into, strip_option), default)] pub stdin: Option<&'a str>, @@ -240,6 +251,7 @@ pub struct ContainerWithExecOpts<'a> { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithExposedPortOpts<'a> { + /// Transport layer network protocol #[builder(setter(into, strip_option), default)] pub protocol: Option, @@ -249,6 +261,7 @@ pub struct ContainerWithExposedPortOpts<'a> { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithFileOpts { + /// Permission given to the copied file (e.g., 0600). /// Default: 0644. #[builder(setter(into, strip_option), default)] @@ -256,6 +269,7 @@ pub struct ContainerWithFileOpts { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithMountedCacheOpts { + /// Identifier of the directory to use as the cache volume's root. #[builder(setter(into, strip_option), default)] pub source: Option, @@ -265,6 +279,7 @@ pub struct ContainerWithMountedCacheOpts { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithNewFileOpts<'a> { + /// Content of the file to write (e.g., "Hello world!"). #[builder(setter(into, strip_option), default)] pub contents: Option<&'a str>, @@ -275,6 +290,7 @@ pub struct ContainerWithNewFileOpts<'a> { } #[derive(Builder, Debug, PartialEq)] pub struct ContainerWithoutExposedPortOpts { + /// Port protocol to unexpose #[builder(setter(into, strip_option), default)] pub protocol: Option, @@ -282,12 +298,15 @@ pub struct ContainerWithoutExposedPortOpts { impl Container { /// Initializes this container from a Dockerfile build. - /// + /// /// # Arguments - /// + /// /// * `context` - Directory context used by the Dockerfile. /// * `opt` - optional argument, see inner type for documentation, use _opts to use - pub fn build(&self, context: DirectoryId) -> Container { + pub fn build( + &self, + context: DirectoryId, + ) -> Container { let mut query = self.selection.select("build"); query = query.arg("context", context); @@ -296,16 +315,20 @@ impl Container { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), - }; + } } /// Initializes this container from a Dockerfile build. - /// + /// /// # Arguments - /// + /// /// * `context` - Directory context used by the Dockerfile. /// * `opt` - optional argument, see inner type for documentation, use _opts to use - pub fn build_opts<'a>(&self, context: DirectoryId, opts: ContainerBuildOpts<'a>) -> Container { + pub fn build_opts<'a>( + &self, + context: DirectoryId, + opts: ContainerBuildOpts<'a> + ) -> Container { let mut query = self.selection.select("build"); query = query.arg("context", context); @@ -323,21 +346,26 @@ impl Container { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), - }; + } } /// Retrieves default arguments for future commands. - pub async fn default_args(&self) -> eyre::Result> { - let query = self.selection.select("defaultArgs"); + pub async fn default_args( + &self, + ) -> eyre::Result> { + let mut query = self.selection.select("defaultArgs"); query.execute(&graphql_client(&self.conn)).await } /// Retrieves a directory at the given path. /// Mounts are included. - /// + /// /// # Arguments - /// + /// /// * `path` - The path of the directory to retrieve (e.g., "./src"). - pub fn directory(&self, path: impl Into) -> Directory { + pub fn directory( + &self, + path: impl Into, + ) -> Directory { let mut query = self.selection.select("directory"); query = query.arg("path", path.into()); @@ -346,18 +374,20 @@ impl Container { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), - }; + } } /// Retrieves an endpoint that clients can use to reach this container. /// If no port is specified, the first exposed port is used. If none exist an error is returned. /// If a scheme is specified, a URL is returned. Otherwise, a host:port pair is returned. /// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable. - /// + /// /// # Arguments - /// + /// /// * `opt` - optional argument, see inner type for documentation, use _opts to use - pub async fn endpoint(&self) -> eyre::Result { - let query = self.selection.select("endpoint"); + pub async fn endpoint( + &self, + ) -> eyre::Result { + let mut query = self.selection.select("endpoint"); query.execute(&graphql_client(&self.conn)).await } @@ -366,11 +396,14 @@ impl Container { /// If no port is specified, the first exposed port is used. If none exist an error is returned. /// If a scheme is specified, a URL is returned. Otherwise, a host:port pair is returned. /// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable. - /// + /// /// # Arguments - /// + /// /// * `opt` - optional argument, see inner type for documentation, use _opts to use - pub async fn endpoint_opts<'a>(&self, opts: ContainerEndpointOpts<'a>) -> eyre::Result { + pub async fn endpoint_opts<'a>( + &self, + opts: ContainerEndpointOpts<'a> + ) -> eyre::Result { let mut query = self.selection.select("endpoint"); if let Some(port) = opts.port { @@ -383,17 +416,22 @@ impl Container { query.execute(&graphql_client(&self.conn)).await } /// Retrieves entrypoint to be prepended to the arguments of all commands. - pub async fn entrypoint(&self) -> eyre::Result> { - let query = self.selection.select("entrypoint"); + pub async fn entrypoint( + &self, + ) -> eyre::Result> { + let mut query = self.selection.select("entrypoint"); query.execute(&graphql_client(&self.conn)).await } /// Retrieves the value of the specified environment variable. - /// + /// /// # Arguments - /// + /// /// * `name` - The name of the environment variable to retrieve (e.g., "PATH"). - pub async fn env_variable(&self, name: impl Into) -> eyre::Result { + pub async fn env_variable( + &self, + name: impl Into, + ) -> eyre::Result { let mut query = self.selection.select("envVariable"); query = query.arg("name", name.into()); @@ -401,36 +439,43 @@ impl Container { query.execute(&graphql_client(&self.conn)).await } /// Retrieves the list of environment variables passed to commands. - pub fn env_variables(&self) -> Vec { - let query = self.selection.select("envVariables"); + pub fn env_variables( + &self, + ) -> Vec { + let mut query = self.selection.select("envVariables"); return vec![EnvVariable { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), - }]; + }] } /// Retrieves this container after executing the specified command inside it. - /// + /// /// # Arguments - /// + /// /// * `opt` - optional argument, see inner type for documentation, use _opts to use - pub fn exec(&self) -> Container { - let query = self.selection.select("exec"); + pub fn exec( + &self, + ) -> Container { + let mut query = self.selection.select("exec"); return Container { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), - }; + } } /// Retrieves this container after executing the specified command inside it. - /// + /// /// # Arguments - /// + /// /// * `opt` - optional argument, see inner type for documentation, use _opts to use - pub fn exec_opts<'a>(&self, opts: ContainerExecOpts<'a>) -> Container { + pub fn exec_opts<'a>( + &self, + opts: ContainerExecOpts<'a> + ) -> Container { let mut query = self.selection.select("exec"); if let Some(args) = opts.args { @@ -446,35 +491,37 @@ impl Container { query = query.arg("redirectStderr", redirect_stderr); } if let Some(experimental_privileged_nesting) = opts.experimental_privileged_nesting { - query = query.arg( - "experimentalPrivilegedNesting", - experimental_privileged_nesting, - ); + query = query.arg("experimentalPrivilegedNesting", experimental_privileged_nesting); } return Container { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), - }; + } } /// Exit code of the last executed command. Zero means success. /// Errors if no command has been executed. - pub async fn exit_code(&self) -> eyre::Result { - let query = self.selection.select("exitCode"); + pub async fn exit_code( + &self, + ) -> eyre::Result { + let mut query = self.selection.select("exitCode"); query.execute(&graphql_client(&self.conn)).await } /// Writes the container as an OCI tarball to the destination file path on the host for the specified platform variants. /// Return true on success. /// It can also publishes platform variants. - /// + /// /// # Arguments - /// + /// /// * `path` - Host's destination path (e.g., "./tarball"). /// Path can be relative to the engine's workdir or absolute. /// * `opt` - optional argument, see inner type for documentation, use _opts to use - pub async fn export(&self, path: impl Into) -> eyre::Result { + pub async fn export( + &self, + path: impl Into, + ) -> eyre::Result { let mut query = self.selection.select("export"); query = query.arg("path", path.into()); @@ -485,16 +532,16 @@ impl Container { /// Writes the container as an OCI tarball to the destination file path on the host for the specified platform variants. /// Return true on success. /// It can also publishes platform variants. - /// + /// /// # Arguments - /// + /// /// * `path` - Host's destination path (e.g., "./tarball"). /// Path can be relative to the engine's workdir or absolute. /// * `opt` - optional argument, see inner type for documentation, use _opts to use pub async fn export_opts( &self, path: impl Into, - opts: ContainerExportOpts, + opts: ContainerExportOpts ) -> eyre::Result { let mut query = self.selection.select("export"); @@ -507,22 +554,27 @@ impl Container { } /// Retrieves the list of exposed ports. /// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable. - pub fn exposed_ports(&self) -> Vec { - let query = self.selection.select("exposedPorts"); + pub fn exposed_ports( + &self, + ) -> Vec { + let mut query = self.selection.select("exposedPorts"); return vec![Port { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), - }]; + }] } /// Retrieves a file at the given path. /// Mounts are included. - /// + /// /// # Arguments - /// + /// /// * `path` - The path of the file to retrieve (e.g., "./README.md"). - pub fn file(&self, path: impl Into) -> File { + pub fn file( + &self, + path: impl Into, + ) -> File { let mut query = self.selection.select("file"); query = query.arg("path", path.into()); @@ -531,16 +583,19 @@ impl Container { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), - }; + } } /// Initializes this container from a pulled base image. - /// + /// /// # Arguments - /// + /// /// * `address` - Image's address from its registry. - /// + /// /// Formatted as [host]/[user]/[repo]:[tag] (e.g., "docker.io/dagger/dagger:main"). - pub fn from(&self, address: impl Into) -> Container { + pub fn from( + &self, + address: impl Into, + ) -> Container { let mut query = self.selection.select("from"); query = query.arg("address", address.into()); @@ -549,39 +604,50 @@ impl Container { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), - }; + } } /// Retrieves this container's root filesystem. Mounts are not included. - pub fn fs(&self) -> Directory { - let query = self.selection.select("fs"); + pub fn fs( + &self, + ) -> Directory { + let mut query = self.selection.select("fs"); return Directory { proc: self.proc.clone(), selection: query, conn: self.conn.clone(), - }; + } } /// Retrieves a hostname which can be used by clients to reach this container. /// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable. - pub async fn hostname(&self) -> eyre::Result { - let query = self.selection.select("hostname"); + pub async fn hostname( + &self, + ) -> eyre::Result { + let mut query = self.selection.select("hostname"); query.execute(&graphql_client(&self.conn)).await } /// A unique identifier for this container. - pub async fn id(&self) -> eyre::Result { - let query = self.selection.select("id"); + pub async fn id( + &self, + ) -> eyre::Result { + let mut query = self.selection.select("id"); query.execute(&graphql_client(&self.conn)).await } /// The unique image reference which can only be retrieved immediately after the 'Container.From' call. - pub async fn image_ref(&self) -> eyre::Result { - let query = self.selection.select("imageRef"); + pub async fn image_ref( + &self, + ) -> eyre::Result { + let mut query = self.selection.select("imageRef"); query.execute(&graphql_client(&self.conn)).await } /// Retrieves the value of the specified label. - pub async fn label(&self, name: impl Into) -> eyre::Result { + pub async fn label( + &self, + name: impl Into, + ) -> eyre::Result { let mut query = self.selection.select("label"); query = query.arg("name", name.into()); @@ -589,28 +655,35 @@ impl Container { query.execute(&graphql_client(&self.conn)).await } /// Retrieves the list of labels passed to container. - pub fn labels(&self) -> Vec