|
| 1 | +use darling::{Error, FromAttributes, FromMeta, Result, util::Flag}; |
| 2 | +use syn::Path; |
| 3 | + |
| 4 | +#[derive(Debug, FromAttributes)] |
| 5 | +#[darling(attributes(versioned), and_then = ContainerAttributes::validate)] |
| 6 | +pub struct ContainerAttributes { |
| 7 | + #[darling(rename = "crd")] |
| 8 | + pub crd_arguments: Option<StructCrdArguments>, |
| 9 | + |
| 10 | + #[darling(default)] |
| 11 | + pub skip: ContainerSkipArguments, |
| 12 | +} |
| 13 | + |
| 14 | +impl ContainerAttributes { |
| 15 | + fn validate(self) -> Result<Self> { |
| 16 | + if self.crd_arguments.is_some() |
| 17 | + && (self.skip.object_from.is_present() |
| 18 | + || self.skip.merged_crd.is_present() |
| 19 | + || self.skip.try_convert.is_present()) |
| 20 | + { |
| 21 | + return Err(Error::custom("spec sub structs can only use skip(from)")); |
| 22 | + } |
| 23 | + |
| 24 | + Ok(self) |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +#[derive(Debug, Default, FromMeta)] |
| 29 | +pub struct ContainerSkipArguments { |
| 30 | + pub from: Flag, |
| 31 | + pub object_from: Flag, |
| 32 | + pub merged_crd: Flag, |
| 33 | + pub try_convert: Flag, |
| 34 | +} |
| 35 | + |
| 36 | +/// This struct contains supported CRD arguments. |
| 37 | +/// |
| 38 | +/// The arguments are passed through to the `#[kube]` attribute. More details can be found in the |
| 39 | +/// official docs: <https://docs.rs/kube/latest/kube/derive.CustomResource.html>. |
| 40 | +/// |
| 41 | +/// Supported arguments are: |
| 42 | +/// |
| 43 | +/// - `group`: Set the group of the CR object, usually the domain of the company. |
| 44 | +/// This argument is Required. |
| 45 | +/// - `kind`: Override the kind field of the CR object. This defaults to the struct |
| 46 | +/// name (without the 'Spec' suffix). |
| 47 | +/// - `singular`: Set the singular name of the CR object. |
| 48 | +/// - `plural`: Set the plural name of the CR object. |
| 49 | +/// - `namespaced`: Indicate that this is a namespaced scoped resource rather than a |
| 50 | +/// cluster scoped resource. |
| 51 | +/// - `crates`: Override specific crates. |
| 52 | +/// - `status`: Set the specified struct as the status subresource. |
| 53 | +/// - `shortname`: Set a shortname for the CR object. This can be specified multiple |
| 54 | +/// times. |
| 55 | +/// - `skip`: Controls skipping parts of the generation. |
| 56 | +#[derive(Clone, Debug, FromMeta)] |
| 57 | +pub struct StructCrdArguments { |
| 58 | + pub group: String, |
| 59 | + pub kind: Option<String>, |
| 60 | + pub singular: Option<String>, |
| 61 | + pub plural: Option<String>, |
| 62 | + pub namespaced: Flag, |
| 63 | + // root |
| 64 | + pub status: Option<Path>, |
| 65 | + // derive |
| 66 | + // schema |
| 67 | + // scale |
| 68 | + // printcolumn |
| 69 | + #[darling(multiple, rename = "shortname")] |
| 70 | + pub shortnames: Vec<String>, |
| 71 | + // category |
| 72 | + // selectable |
| 73 | + // doc |
| 74 | + // annotation |
| 75 | + // label |
| 76 | +} |
0 commit comments