mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2025-12-29 03:01:03 +01:00
Compare commits
3 Commits
feat/fix-s
...
58de5386e2
| Author | SHA1 | Date | |
|---|---|---|---|
|
58de5386e2
|
|||
|
3453e8cac6
|
|||
|
d0483b0434
|
@@ -7,8 +7,11 @@ use super::{
|
|||||||
utility::{render_description_from_field, render_description_from_input_value},
|
utility::{render_description_from_field, render_description_from_input_value},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn render_fields(fields: &Vec<FullTypeFields>) -> eyre::Result<Option<rust::Tokens>> {
|
pub fn render_fields(
|
||||||
|
fields: &Vec<FullTypeFields>,
|
||||||
|
) -> eyre::Result<Option<(rust::Tokens, rust::Tokens)>> {
|
||||||
let mut collected_fields: Vec<rust::Tokens> = vec![];
|
let mut collected_fields: Vec<rust::Tokens> = vec![];
|
||||||
|
let mut collected_args: Vec<rust::Tokens> = vec![];
|
||||||
for field in fields.iter() {
|
for field in fields.iter() {
|
||||||
let name = field.name.as_ref().map(|n| n.to_case(Case::Snake)).unwrap();
|
let name = field.name.as_ref().map(|n| n.to_case(Case::Snake)).unwrap();
|
||||||
let output = render_field_output(field)?;
|
let output = render_field_output(field)?;
|
||||||
@@ -18,22 +21,23 @@ pub fn render_fields(fields: &Vec<FullTypeFields>) -> eyre::Result<Option<rust::
|
|||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut tkns = rust::Tokens::new();
|
|
||||||
|
|
||||||
if let Some(args) = args.as_ref() {
|
if let Some(args) = args.as_ref() {
|
||||||
tkns.append(quote! {
|
let mut args_tkns = rust::Tokens::new();
|
||||||
|
args_tkns.append(quote! {
|
||||||
$description
|
$description
|
||||||
pub struct $(&name)Args {
|
pub struct $(&field.name.as_ref().map(|n| n.to_case(Case::Pascal)).unwrap())Args {
|
||||||
$(&args.args)
|
$(&args.args)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tkns.push();
|
args_tkns.push();
|
||||||
}
|
|
||||||
|
|
||||||
|
collected_args.push(args_tkns);
|
||||||
|
}
|
||||||
|
let mut tkns = rust::Tokens::new();
|
||||||
tkns.append(quote! {
|
tkns.append(quote! {
|
||||||
pub fn $(&name)(
|
pub fn $(&name)(
|
||||||
&self,
|
&self,
|
||||||
$(if let Some(_) = args.as_ref() => args: $(&name)Args)
|
$(if let Some(_) = args.as_ref() => args: &$(&field.name.as_ref().map(|n| n.to_case(Case::Pascal)).unwrap())Args)
|
||||||
) -> $(&output) {
|
) -> $(&output) {
|
||||||
let query = self.selection.select($(field.name.as_ref().map(|n| format!("\"{}\"", n))));
|
let query = self.selection.select($(field.name.as_ref().map(|n| format!("\"{}\"", n))));
|
||||||
$(if let Some(_) = args.as_ref() => query.args(args);)
|
$(if let Some(_) = args.as_ref() => query.args(args);)
|
||||||
@@ -43,17 +47,20 @@ pub fn render_fields(fields: &Vec<FullTypeFields>) -> eyre::Result<Option<rust::
|
|||||||
proc: self.proc.clone(),
|
proc: self.proc.clone(),
|
||||||
selection: query,
|
selection: query,
|
||||||
}
|
}
|
||||||
|
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
collected_fields.push(tkns);
|
collected_fields.push(tkns);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some(quote! {
|
Ok(Some((
|
||||||
|
quote! {
|
||||||
|
$(for arg in collected_args => $arg $['\n'] )
|
||||||
|
},
|
||||||
|
quote! {
|
||||||
$(for field in collected_fields => $field $['\n'] )
|
$(for field in collected_fields => $field $['\n'] )
|
||||||
}))
|
},
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Arg {
|
struct Arg {
|
||||||
@@ -91,15 +98,9 @@ fn render_args(args: &[Option<FullTypeFieldsArgs>]) -> Option<CollectedArgs> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for arg in collected_args {
|
for arg in collected_args {
|
||||||
if let Some(desc) = arg.description {
|
|
||||||
if let Some(inner_desc) = collected_arg.description.as_mut() {
|
|
||||||
inner_desc.append(desc);
|
|
||||||
inner_desc.push();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
collected_arg.args.append(quote! {
|
collected_arg.args.append(quote! {
|
||||||
$(arg.name.to_case(Case::Snake)): $(arg.type_),
|
$(arg.description)
|
||||||
|
pub $(arg.name.to_case(Case::Snake)): $(arg.type_),
|
||||||
});
|
});
|
||||||
collected_arg.args.push();
|
collected_arg.args.push();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,14 +29,24 @@ impl Handler for Object {
|
|||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let child = rust::import("std::process", "Child");
|
||||||
|
let connect_params = rust::import("dagger_core::connect_params", "ConnectParams");
|
||||||
|
let selection = rust::import("crate::querybuilder", "Selection");
|
||||||
|
let arc = rust::import("std::sync", "Arc");
|
||||||
|
|
||||||
let out = quote! {
|
let out = quote! {
|
||||||
|
$(if fields.as_ref().is_some() => $(fields.as_ref().map(|f| &f.0)))
|
||||||
|
|
||||||
$(if description.is_some() => $description)
|
$(if description.is_some() => $description)
|
||||||
pub struct $name {
|
pub struct $name {
|
||||||
$(if input_fields.is_some() => $input_fields)
|
$(if input_fields.is_some() => $input_fields)
|
||||||
|
pub conn: $connect_params,
|
||||||
|
pub proc: $arc<$child>,
|
||||||
|
pub selection: $selection,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $name {
|
impl $name {
|
||||||
$(if fields.is_some() => $fields)
|
$(if fields.is_some() => $(fields.map(|f| f.1)))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -85,9 +95,18 @@ mod tests {
|
|||||||
enum_values: None,
|
enum_values: None,
|
||||||
possible_types: None,
|
possible_types: None,
|
||||||
};
|
};
|
||||||
let expected = r#"
|
let expected = r#"use crate::querybuilder::Selection;
|
||||||
|
use dagger_core::connect_params::ConnectParams;
|
||||||
|
use std::process::Child;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
|
||||||
/// A directory whose contents persists across sessions
|
/// A directory whose contents persists across sessions
|
||||||
pub struct CacheVolume {}
|
pub struct CacheVolume {
|
||||||
|
pub conn: ConnectParams,
|
||||||
|
pub proc: Arc<Child>,
|
||||||
|
pub selection: Selection,
|
||||||
|
}
|
||||||
|
|
||||||
impl CacheVolume {
|
impl CacheVolume {
|
||||||
pub fn id(
|
pub fn id(
|
||||||
@@ -114,27 +133,40 @@ impl CacheVolume {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_render_query_container() {
|
fn can_render_query_container() {
|
||||||
|
let description = "Loads a container from ID.\nNull ID returns an empty container (scratch).\nOptional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host.".into();
|
||||||
|
|
||||||
let t: FullType = FullType {
|
let t: FullType = FullType {
|
||||||
kind: Some(__TypeKind::OBJECT),
|
kind: Some(__TypeKind::OBJECT),
|
||||||
name: Some("Query".into()),
|
name: Some("Query".into()),
|
||||||
description: None,
|
description: None,
|
||||||
fields: Some(vec![FullTypeFields {
|
fields: Some(vec![FullTypeFields {
|
||||||
name: Some("container".into()),
|
name: Some("container".into()),
|
||||||
description: Some("Loads a container from ID.\nNull ID returns an empty container (scratch).\nOptional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host.".into()),
|
description: Some(description),
|
||||||
args: Some(
|
args: Some(vec![
|
||||||
vec![
|
Some(FullTypeFieldsArgs {
|
||||||
Some(
|
|
||||||
FullTypeFieldsArgs
|
|
||||||
{
|
|
||||||
input_value: InputValue { name: "id".into(), description: None, type_: TypeRef { kind: Some(__TypeKind::SCALAR), name: Some("ContainerID".into()), of_type: None }, default_value: None }
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Some(
|
|
||||||
FullTypeFieldsArgs {
|
|
||||||
input_value: InputValue {
|
input_value: InputValue {
|
||||||
name: "platform".into(), description: None, type_: TypeRef { kind: Some(__TypeKind::SCALAR), name: Some("Platform".into()), of_type: None },
|
name: "id".into(),
|
||||||
default_value: None }
|
description: None,
|
||||||
})
|
type_: TypeRef {
|
||||||
|
kind: Some(__TypeKind::SCALAR),
|
||||||
|
name: Some("ContainerID".into()),
|
||||||
|
of_type: None,
|
||||||
|
},
|
||||||
|
default_value: None,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
Some(FullTypeFieldsArgs {
|
||||||
|
input_value: InputValue {
|
||||||
|
name: "platform".into(),
|
||||||
|
description: None,
|
||||||
|
type_: TypeRef {
|
||||||
|
kind: Some(__TypeKind::SCALAR),
|
||||||
|
name: Some("Platform".into()),
|
||||||
|
of_type: None,
|
||||||
|
},
|
||||||
|
default_value: None,
|
||||||
|
},
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
type_: Some(FullTypeFieldsType {
|
type_: Some(FullTypeFieldsType {
|
||||||
type_ref: TypeRef {
|
type_ref: TypeRef {
|
||||||
@@ -149,14 +181,49 @@ impl CacheVolume {
|
|||||||
}),
|
}),
|
||||||
is_deprecated: Some(false),
|
is_deprecated: Some(false),
|
||||||
deprecation_reason: None,
|
deprecation_reason: None,
|
||||||
}
|
}]),
|
||||||
]),
|
|
||||||
input_fields: None,
|
input_fields: None,
|
||||||
interfaces: None,
|
interfaces: None,
|
||||||
enum_values: None,
|
enum_values: None,
|
||||||
possible_types: None,
|
possible_types: None,
|
||||||
};
|
};
|
||||||
let expected = r#"
|
let expected = r#"use crate::querybuilder::Selection;
|
||||||
|
use dagger_core::connect_params::ConnectParams;
|
||||||
|
use std::process::Child;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
|
||||||
|
/// Loads a container from ID.
|
||||||
|
/// Null ID returns an empty container (scratch).
|
||||||
|
/// Optional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host.
|
||||||
|
pub struct ContainerArgs {
|
||||||
|
pub id: Option<ContainerID>,
|
||||||
|
pub platform: Option<Platform>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Query {
|
||||||
|
pub conn: ConnectParams,
|
||||||
|
pub proc: Arc<Child>,
|
||||||
|
pub selection: Selection,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Query {
|
||||||
|
pub fn container(
|
||||||
|
&self,
|
||||||
|
args: &ContainerArgs
|
||||||
|
) -> CacheID {
|
||||||
|
let query = self.selection.select("container");
|
||||||
|
query.args(args);
|
||||||
|
|
||||||
|
CacheID {
|
||||||
|
conn: self.conn.clone(),
|
||||||
|
proc: self.proc.clone(),
|
||||||
|
selection: query,
|
||||||
|
}
|
||||||
|
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
"#;
|
"#;
|
||||||
let handler = Object {};
|
let handler = Object {};
|
||||||
let obj = handler.render(&t).unwrap();
|
let obj = handler.render(&t).unwrap();
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user