(&self, ctx: &mut ValidationContext, _: &())
| 17 | type ContextData = (); |
| 18 | |
| 19 | fn validate(&self, ctx: &mut ValidationContext, _: &()) { |
| 20 | check_name_field(ctx, "name", &self.name, matches!(self.kind, CommandType::Chat)); |
| 21 | |
| 22 | if matches!(self.kind, CommandType::Chat) { |
| 23 | check_description_field(ctx, "description", &self.description); |
| 24 | } else if !self.description.is_empty() { |
| 25 | ctx.push_field_error( |
| 26 | "description", |
| 27 | "description has to be empty for user and message commands".to_string(), |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | if let Some(group) = &self.group { |
| 32 | check_name_field(ctx, "group", group, true); |
| 33 | } |
| 34 | |
| 35 | if let Some(group) = &self.sub_group { |
| 36 | check_name_field(ctx, "sub_group", group, true); |
| 37 | } |
| 38 | |
| 39 | if self.options.len() > 25 { |
| 40 | ctx.push_field_error("options", "max 25 options".to_string()); |
| 41 | } |
| 42 | |
| 43 | let mut found_optional = false; |
| 44 | for option in &self.options { |
| 45 | ctx.push_field("options".to_string()); |
| 46 | option.validate(ctx, &()); |
| 47 | ctx.pop_field(); |
| 48 | |
| 49 | if !option.required { |
| 50 | found_optional = true; |
| 51 | } else if found_optional { |
| 52 | ctx.push_field_error("options", "optional options has to be last".to_string()); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | impl Validator for CommandOption { |
nothing calls this directly
no test coverage detected