let env_setup = import "./fragments/environment-setup.ncl" in { name = "conditional_demo", description = "Complete demonstration of conditional field visibility", elements = [ # COMPARISON OPERATORS { type = "select", name = "database_driver", prompt = "Select database driver", required = true, options = [ { value = "sqlite", label = "SQLite (embedded)" }, { value = "mysql", label = "MySQL" }, { value = "postgresql", label = "PostgreSQL" }, ] }, # Equality (==) { type = "text", name = "mysql_config", prompt = "MySQL connection string", placeholder = "mysql://localhost:3306/db", when = "database_driver == mysql" }, # Inequality (!=) { type = "section", name = "server_warning", content = "⚠️ You selected a server-based database. Ensure the server is running.", when = "database_driver != sqlite" }, # NUMERIC COMPARISONS { type = "text", name = "server_port", prompt = "Server port", required = true, default = "8080" }, # Greater than (>) { type = "section", name = "high_port_warning", content = "⚠️ Port > 10000 is uncommon. Double-check your configuration.", when = "server_port > 10000" }, # Less than (<) { type = "section", name = "privileged_port_warning", content = "⚠️ Port < 1024 requires root/admin privileges.", when = "server_port < 1024" }, # Greater than or equal (>=) { type = "section", name = "standard_port_notice", content = "✓ Using standard user port range (>= 1024)", when = "server_port >= 1024" }, # Less than or equal (<=) { type = "section", name = "low_port_range", content = "Using low port range (<= 5000)", when = "server_port <= 5000" }, # STRING OPERATORS { type = "text", name = "project_url", prompt = "Project repository URL", placeholder = "https://github.com/user/repo" }, # startswith { type = "section", name = "https_notice", content = "✓ Secure HTTPS URL detected", when = "project_url startswith https" }, # endswith { type = "text", name = "github_specific", prompt = "GitHub Actions enabled?", when = "project_url endswith github.com" }, # contains { type = "confirm", name = "gitlab_ci", prompt = "Enable GitLab CI integration?", when = "project_url contains gitlab" }, # ARRAY MEMBERSHIP (in) { type = "multiselect", name = "detected_languages", prompt = "Which languages are used in your project?", display_mode = "grid", options = [ { value = "rust", label = "🦀 Rust" }, { value = "python", label = "🐍 Python" }, { value = "javascript", label = "📜 JavaScript" }, { value = "go", label = "🐹 Go" }, ] }, # Array membership check { type = "select", name = "rust_toolchain", prompt = "Rust toolchain version", when = "rust in detected_languages", options = [ { value = "stable", label = "Stable" }, { value = "nightly", label = "Nightly" }, { value = "beta", label = "Beta" }, ] }, { type = "confirm", name = "python_venv", prompt = "Use Python virtual environment?", default = true, when = "python in detected_languages" }, { type = "select", name = "nodejs_version", prompt = "Node.js version", when = "javascript in detected_languages", options = [ { value = "18", label = "Node.js 18 LTS" }, { value = "20", label = "Node.js 20 LTS" }, { value = "latest", label = "Latest" }, ] }, # FILE SYSTEM CONDITIONS { type = "section", name = "dockerfile_exists_notice", content = "✓ Dockerfile found in current directory", when = "file_exists(Dockerfile)" }, { type = "confirm", name = "create_dockerfile", prompt = "No Dockerfile found. Create one?", default = true, when = "!file_exists(Dockerfile)" }, { type = "confirm", name = "use_existing_config", prompt = "Existing .env file found. Use existing configuration?", when = "file_exists(.env)" }, ] # env_setup group when = "!file_exists(.env)" — fragment has per-element conditions, inline as-is @ env_setup.elements @ [ # COMBINED CONDITIONS { type = "section", name = "rust_docker_setup", content = "🦀 Rust + Docker detected. Consider using rust:alpine base image.", when = "rust in detected_languages" }, { type = "section", name = "production_ready_check", content = "✅ Production-ready configuration detected (HTTPS + standard port)", when = "server_port >= 1024" }, ], }