include!(concat!(env!("OUT_DIR"), "/schema_sections.rs"));
pub fn is_valid_section(name: &str) -> bool {
SCHEMA_SECTIONS.iter().any(|(n, _)| *n == name)
}
pub fn section_description(name: &str) -> Option<&'static str> {
SCHEMA_SECTIONS
.iter()
.find(|(n, _)| *n == name)
.map(|(_, desc)| *desc)
}
pub fn is_valid_entry(name: &str) -> bool {
SCHEMA_ENTRIES.iter().any(|(n, _, _)| *n == name)
}
pub fn entry_description(name: &str) -> Option<&'static str> {
SCHEMA_ENTRIES
.iter()
.find(|(n, _, _)| *n == name)
.map(|(_, desc, _)| *desc)
}
pub fn entry_type(name: &str) -> Option<SchemaType> {
SCHEMA_ENTRIES
.iter()
.find(|(n, _, _)| *n == name)
.map(|(_, _, t)| *t)
}
pub fn is_valid_setting(name: &str) -> bool {
SCHEMA_SETTINGS.iter().any(|(n, _, _)| *n == name)
}
pub fn setting_description(name: &str) -> Option<&'static str> {
SCHEMA_SETTINGS
.iter()
.find(|(n, _, _)| *n == name)
.map(|(_, desc, _)| *desc)
}
pub fn setting_type(name: &str) -> Option<SchemaType> {
SCHEMA_SETTINGS
.iter()
.find(|(n, _, _)| *n == name)
.map(|(_, _, t)| *t)
}
pub fn is_common_hook(name: &str) -> bool {
SCHEMA_HOOKS.iter().any(|(n, _)| *n == name)
}
pub fn hook_description(name: &str) -> Option<&'static str> {
SCHEMA_HOOKS
.iter()
.find(|(n, _)| *n == name)
.map(|(_, desc)| *desc)
}
pub fn is_valid_task_config(name: &str) -> bool {
SCHEMA_TASK_CONFIG.iter().any(|(n, _, _)| *n == name)
}
pub fn task_config_description(name: &str) -> Option<&'static str> {
SCHEMA_TASK_CONFIG
.iter()
.find(|(n, _, _)| *n == name)
.map(|(_, desc, _)| *desc)
}
pub fn task_config_type(name: &str) -> Option<SchemaType> {
SCHEMA_TASK_CONFIG
.iter()
.find(|(n, _, _)| *n == name)
.map(|(_, _, t)| *t)
}
pub fn is_valid_monorepo(name: &str) -> bool {
SCHEMA_MONOREPO.iter().any(|(n, _, _)| *n == name)
}
pub fn monorepo_description(name: &str) -> Option<&'static str> {
SCHEMA_MONOREPO
.iter()
.find(|(n, _, _)| *n == name)
.map(|(_, desc, _)| *desc)
}
pub fn monorepo_type(name: &str) -> Option<SchemaType> {
SCHEMA_MONOREPO
.iter()
.find(|(n, _, _)| *n == name)
.map(|(_, _, t)| *t)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_valid_sections() {
assert!(is_valid_section("tools"));
assert!(is_valid_section("env"));
assert!(is_valid_section("tasks"));
assert!(is_valid_section("settings"));
assert!(!is_valid_section("invalid_section"));
assert!(!is_valid_section("min_version"));
}
#[test]
fn test_section_descriptions() {
assert!(section_description("tools").is_some());
assert!(section_description("invalid").is_none());
}
#[test]
fn test_valid_entries() {
assert!(is_valid_entry("min_version"));
assert!(!is_valid_entry("tools"));
}
#[test]
fn test_entry_descriptions() {
assert!(entry_description("min_version").is_some());
assert!(entry_description("invalid").is_none());
}
#[test]
fn test_entry_types() {
assert_eq!(entry_type("redactions"), Some(SchemaType::Array));
assert_eq!(entry_type("monorepo_root"), Some(SchemaType::Boolean));
}
#[test]
fn test_valid_settings() {
assert!(is_valid_setting("experimental"));
assert!(is_valid_setting("color"));
assert!(is_valid_setting("aqua.baked_registry"));
assert!(!is_valid_setting("invalid_setting"));
}
#[test]
fn test_setting_descriptions() {
assert!(setting_description("experimental").is_some());
assert!(setting_description("invalid").is_none());
}
#[test]
fn test_setting_types() {
assert_eq!(setting_type("quiet"), Some(SchemaType::Boolean));
assert_eq!(setting_type("jobs"), Some(SchemaType::Number));
}
#[test]
fn test_common_hooks() {
assert!(is_common_hook("enter"));
assert!(is_common_hook("leave"));
assert!(is_common_hook("cd"));
assert!(!is_common_hook("my_custom_hook"));
}
#[test]
fn test_hook_descriptions() {
assert!(hook_description("enter").is_some());
assert!(hook_description("invalid").is_none());
}
#[test]
fn test_valid_task_config() {
assert!(is_valid_task_config("dir"));
assert!(is_valid_task_config("includes"));
assert!(!is_valid_task_config("invalid"));
}
#[test]
fn test_task_config_descriptions() {
assert!(task_config_description("dir").is_some());
assert!(task_config_description("invalid").is_none());
}
#[test]
fn test_valid_monorepo() {
assert!(is_valid_monorepo("config_roots"));
assert!(!is_valid_monorepo("invalid"));
}
#[test]
fn test_monorepo_descriptions() {
assert!(monorepo_description("config_roots").is_some());
assert!(monorepo_description("invalid").is_none());
}
}