From 39721a88611f47a8e02a4daeafaa34d1a2c44b34 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 23 Jul 2026 00:38:36 +0800 Subject: feat(core): rename `builds` feature to `build` Replace the `builds` feature with `build` across the crate, keeping a backward-compatible alias for the old name. Update all internal visibility from `#[doc(hidden)] pub mod` to `pub(crate) mod` and reorganize the `__private` module into a dedicated `private.rs`. --- .run/version-files.toml | 4 + CHANGELOG.md | 7 ++ GETTING_STARTED.md | 2 +- docs/_zh_CN/pages/advanced/1-completion.md | 4 +- docs/pages/advanced/1-completion.md | 4 +- examples/example-completion/Cargo.toml | 4 +- examples/example-completion/src/main.rs | 2 +- examples/example-pathfinder/Cargo.toml | 4 +- mingling/Cargo.toml | 6 +- mingling_cli/Cargo.toml | 2 +- mingling_core/Cargo.toml | 2 +- mingling_core/src/any.rs | 6 +- mingling_core/src/asset.rs | 35 ++---- mingling_core/src/build.rs | 13 +++ mingling_core/src/build/comp.rs | 168 +++++++++++++++++++++++++++++ mingling_core/src/build/pathf.rs | 43 ++++++++ mingling_core/src/builds.rs | 7 -- mingling_core/src/builds/comp.rs | 168 ----------------------------- mingling_core/src/builds/pathf.rs | 43 -------- mingling_core/src/lib.rs | 120 +++++++++++---------- mingling_core/src/private.rs | 12 +++ 21 files changed, 338 insertions(+), 318 deletions(-) create mode 100644 mingling_core/src/build.rs create mode 100644 mingling_core/src/build/comp.rs create mode 100644 mingling_core/src/build/pathf.rs delete mode 100644 mingling_core/src/builds.rs delete mode 100644 mingling_core/src/builds/comp.rs delete mode 100644 mingling_core/src/builds/pathf.rs create mode 100644 mingling_core/src/private.rs diff --git a/.run/version-files.toml b/.run/version-files.toml index ca104d2..b69a568 100644 --- a/.run/version-files.toml +++ b/.run/version-files.toml @@ -17,3 +17,7 @@ pattern = "version = \"{VER}\"" [[file]] file = "./docs/res/guide.txt" pattern = "mingling = \"{VER}\"" + +[[file]] +file = "./mingling_core/src/lib.rs" +pattern = "mingling = \"{VER}\"" diff --git a/CHANGELOG.md b/CHANGELOG.md index ed7ad66..62ec971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -171,6 +171,13 @@ None _No migration is required — these are purely additive derives that expand the type's capabilities without affecting existing behavior._ +**[`core`]** Added the `build` feature (renamed from `builds`) to `mingling_core` and `mingling`. The old `builds` feature has been deprecated in favor of `build`, with a backward-compatibility alias retained in `mingling/Cargo.toml`: + +- **`mingling_core/Cargo.toml`**: Renamed the feature from `builds` to `build`. +- **`mingling/Cargo.toml`**: Changed the feature dependency from `mingling_core/builds` to `mingling_core/build`. A deprecated `builds` feature alias is kept as `builds = ["mingling_core/build"]` with a note indicating it will be removed in a future breaking change. + + _No behavioral changes — the `build` feature provides identical functionality to the old `builds` feature. Downstream code using `builds` continues to work via the alias, but should migrate to `build`._ + #### Features: 1. **[`core`]** Added `RenderResult::new()` method for creating a new `RenderResult` with default values (empty text and exit code 0). This provides a more explicit and discoverable constructor compared to `RenderResult::default()`, making it clearer when a fresh result is being created for use with `write!`/`writeln!`. diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index 621471e..516122e 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -239,7 +239,7 @@ In your `build.rs`, generate the shell scripts: ```rust // BUILD TIME -// Features: ["comp", "builds"] +// Features: ["comp", "build"] mingling::build::build_comp_scripts(env!("CARGO_PKG_NAME")).unwrap(); ``` diff --git a/docs/_zh_CN/pages/advanced/1-completion.md b/docs/_zh_CN/pages/advanced/1-completion.md index 3941404..a6500db 100644 --- a/docs/_zh_CN/pages/advanced/1-completion.md +++ b/docs/_zh_CN/pages/advanced/1-completion.md @@ -15,8 +15,8 @@ features = ["comp"] [build-dependencies.mingling] features = [ "comp", - # 启用 `builds` 特性以提供构建期支持 - "builds" + # 启用 `build` 特性以提供构建期支持 + "build" ] ``` diff --git a/docs/pages/advanced/1-completion.md b/docs/pages/advanced/1-completion.md index a90c3ce..52350db 100644 --- a/docs/pages/advanced/1-completion.md +++ b/docs/pages/advanced/1-completion.md @@ -15,8 +15,8 @@ features = ["comp"] [build-dependencies.mingling] features = [ "comp", - # Enable `builds` for build-time support - "builds" + # Enable `build` for build-time support + "build" ] ``` diff --git a/examples/example-completion/Cargo.toml b/examples/example-completion/Cargo.toml index 1c6b327..00c7f8c 100644 --- a/examples/example-completion/Cargo.toml +++ b/examples/example-completion/Cargo.toml @@ -20,8 +20,8 @@ features = [ "comp", # If you want to build completion scripts, - # enable `builds` features - "builds", + # enable `build` features + "build", ] [workspace] diff --git a/examples/example-completion/src/main.rs b/examples/example-completion/src/main.rs index 45cc8ef..d65be49 100644 --- a/examples/example-completion/src/main.rs +++ b/examples/example-completion/src/main.rs @@ -7,7 +7,7 @@ //! To make your completions work, you need to generate a completion script using Mingling's tools //! //! 1. Enable features -//! You need to enable the `builds` and `comp` features for `mingling` in `[build-dependencies]` +//! You need to enable the `build` and `comp` features for `mingling` in `[build-dependencies]` //! //! 2. Write `build.rs` //! Write the following in `build.rs` diff --git a/examples/example-pathfinder/Cargo.toml b/examples/example-pathfinder/Cargo.toml index bd362f2..bc41bd2 100644 --- a/examples/example-pathfinder/Cargo.toml +++ b/examples/example-pathfinder/Cargo.toml @@ -18,8 +18,8 @@ features = [ # Enable `pathf` features "pathf", - # Enable the `builds` feature for build-time support - "builds", + # Enable the `build` feature for build-time support + "build", ] [workspace] diff --git a/mingling/Cargo.toml b/mingling/Cargo.toml index 351384f..9bf82a7 100644 --- a/mingling/Cargo.toml +++ b/mingling/Cargo.toml @@ -43,7 +43,8 @@ macros = ["dep:mingling_macros", "mingling_macros/default"] nightly = ["mingling_core/nightly", "mingling_macros/nightly"] debug = ["mingling_core/debug"] async = ["mingling_core/async", "mingling_macros/async"] -builds = ["mingling_core/builds"] + +build = ["mingling_core/build"] default = ["core", "macros"] @@ -92,6 +93,9 @@ extra_macros = ["mingling_macros/extra_macros"] # Section only shown in docs.rs docs_rs = [] +# This is an old name, will be Breaking Change in the future +builds = ["mingling_core/build"] + [dependencies] mingling_core = { workspace = true, optional = true } mingling_macros = { workspace = true, optional = true } diff --git a/mingling_cli/Cargo.toml b/mingling_cli/Cargo.toml index 906cdd0..330ef5a 100644 --- a/mingling_cli/Cargo.toml +++ b/mingling_cli/Cargo.toml @@ -31,7 +31,7 @@ features = [ [build-dependencies.mingling] path = "../mingling" features = [ - "builds", + "build", "pathf", ] diff --git a/mingling_core/Cargo.toml b/mingling_core/Cargo.toml index 14140c6..f525609 100644 --- a/mingling_core/Cargo.toml +++ b/mingling_core/Cargo.toml @@ -14,7 +14,7 @@ categories = ["command-line-interface"] nightly = [] default = [] async = [] -builds = [] +build = [] picker = [] dispatch_tree = [] diff --git a/mingling_core/src/any.rs b/mingling_core/src/any.rs index 3e8fdf0..e922e2e 100644 --- a/mingling_core/src/any.rs +++ b/mingling_core/src/any.rs @@ -1,8 +1,8 @@ +use crate::ProgramCollect; use crate::error::ChainProcessError; -use crate::{Grouped, ProgramCollect}; -#[doc(hidden)] -pub mod group; +mod group; +pub use group::*; /// Any type output /// diff --git a/mingling_core/src/asset.rs b/mingling_core/src/asset.rs index 9b9a5d4..f26952b 100644 --- a/mingling_core/src/asset.rs +++ b/mingling_core/src/asset.rs @@ -1,26 +1,9 @@ -#[doc(hidden)] -pub mod chain; - -#[doc(hidden)] -pub mod dispatcher; - -#[doc(hidden)] -pub mod enum_tag; - -#[doc(hidden)] -pub mod global_resource; - -#[doc(hidden)] -pub mod help; - -#[doc(hidden)] -pub mod lazy_resource; - -#[doc(hidden)] -pub mod node; - -#[doc(hidden)] -pub mod renderer; - -#[doc(hidden)] -pub mod routable; +pub(crate) mod chain; +pub(crate) mod dispatcher; +pub(crate) mod enum_tag; +pub(crate) mod global_resource; +pub(crate) mod help; +pub(crate) mod lazy_resource; +pub(crate) mod node; +pub(crate) mod renderer; +pub(crate) mod routable; diff --git a/mingling_core/src/build.rs b/mingling_core/src/build.rs new file mode 100644 index 0000000..7918f3a --- /dev/null +++ b/mingling_core/src/build.rs @@ -0,0 +1,13 @@ +#[doc(hidden)] +#[cfg(feature = "comp")] +mod comp; + +#[cfg(feature = "comp")] +pub use comp::*; + +#[doc(hidden)] +#[cfg(feature = "pathf")] +mod pathf; + +#[cfg(feature = "pathf")] +pub use pathf::*; diff --git a/mingling_core/src/build/comp.rs b/mingling_core/src/build/comp.rs new file mode 100644 index 0000000..2abb1e1 --- /dev/null +++ b/mingling_core/src/build/comp.rs @@ -0,0 +1,168 @@ +use std::path::PathBuf; + +use just_template::tmpl; + +use crate::ShellFlag; + +const TMPL_COMP_BASH: &str = include_str!("../../tmpls/comps/bash.sh"); +const TMPL_COMP_ZSH: &str = include_str!("../../tmpls/comps/zsh.zsh"); +const TMPL_COMP_FISH: &str = include_str!("../../tmpls/comps/fish.fish"); +const TMPL_COMP_PWSH: &str = include_str!("../../tmpls/comps/pwsh.ps1"); + +/// Generate shell completion scripts for a given binary name. +/// On Windows, generates `PowerShell` completion. +/// On Linux, generates Zsh, Bash, and Fish completions. +/// Scripts are written to the `OUT_DIR` (or `target/` if `OUT_DIR` is not set). +/// +/// # Example +/// ```rust,ignore +/// # use mingling_core::comp::ShellFlag; +/// # use mingling_core::build::build_comp_scripts; +/// +/// // Generate completion scripts for "myapp" +/// build_comp_scripts("myapp").unwrap(); +/// +/// // Generate completion scripts for current package +/// build_comp_scripts(env!("CARGO_PKG_NAME")).unwrap(); +/// ``` +pub fn build_comp_scripts(name: &str) -> Result<(), std::io::Error> { + #[cfg(target_os = "windows")] + { + build_comp_script(&ShellFlag::Powershell, name)?; + Ok(()) + } + + #[cfg(target_os = "linux")] + { + build_comp_script(&ShellFlag::Zsh, name)?; + build_comp_script(&ShellFlag::Bash, name)?; + build_comp_script(&ShellFlag::Fish, name)?; + Ok(()) + } + + #[cfg(target_os = "macos")] + { + build_comp_script(&ShellFlag::Zsh, name)?; + build_comp_script(&ShellFlag::Bash, name)?; + build_comp_script(&ShellFlag::Fish, name)?; + Ok(()) + } +} + +/// Generate a shell completion script for a specific shell. +/// +/// This function takes a shell flag and a binary name, selects the appropriate +/// template, substitutes the binary name into the template, and writes the +/// resulting completion script to the target directory (typically `target/`). +/// +/// # Example +/// ```rust,ignore +/// # use mingling_core::comp::ShellFlag; +/// # use mingling_core::build::build_comp_script; +/// build_comp_script(&ShellFlag::Bash, "myapp").unwrap(); +/// ``` +pub fn build_comp_script(shell_flag: &ShellFlag, bin_name: &str) -> Result<(), std::io::Error> { + let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); + let target_dir = out_dir.join("../../../").clone(); + build_comp_script_to(shell_flag, bin_name, &target_dir.to_string_lossy()) +} + +/// Generate a shell completion script to a specified directory. +/// +/// This function takes a shell flag, a binary name, and a target directory path, +/// selects the appropriate template, substitutes the binary name into the template, +/// and writes the resulting completion script to the specified directory. +/// +/// # Example +/// ```rust,ignore +/// # use mingling_core::comp::ShellFlag; +/// # use mingling_core::build::build_comp_script_to; +/// build_comp_script_to(&ShellFlag::Bash, "myapp", "target/completions").unwrap(); +/// ``` +pub fn build_comp_script_to( + shell_flag: &ShellFlag, + bin_name: &str, + target_dir: &str, +) -> Result<(), std::io::Error> { + let (tmpl_str, ext) = get_tmpl(shell_flag); + let mut tmpl = just_template::Template::from(tmpl_str); + tmpl!(bin_name = bin_name); + let target_path = std::path::PathBuf::from(target_dir); + std::fs::create_dir_all(&target_path)?; + let output_path = target_path.join(format!("{bin_name}_comp{ext}")); + std::fs::write(&output_path, tmpl.to_string()) +} + +/// Generate a shell completion script and write it to a specified file path. +/// +/// This function takes a shell flag, a binary name, and an output file path, +/// selects the appropriate template, substitutes the binary name into the template, +/// and writes the resulting completion script directly to the specified file path. +/// +/// # Example +/// ```rust,ignore +/// # use mingling_core::comp::ShellFlag; +/// # use mingling_core::build::build_comp_script_to_file; +/// build_comp_script_to_file(&ShellFlag::Bash, "myapp", "target/completions/myapp_comp.sh").unwrap(); +/// ``` +pub fn build_comp_script_to_file( + shell_flag: &ShellFlag, + bin_name: &str, + output_path: impl Into, +) -> Result<(), std::io::Error> { + let (tmpl_str, _ext) = get_tmpl(shell_flag); + let mut tmpl = just_template::Template::from(tmpl_str); + tmpl!(bin_name = bin_name); + std::fs::write(output_path.into(), tmpl.to_string()) +} + +fn get_tmpl(shell_flag: &ShellFlag) -> (&'static str, &'static str) { + match shell_flag { + ShellFlag::Bash => (TMPL_COMP_BASH, ".sh"), + ShellFlag::Zsh => (TMPL_COMP_ZSH, ".zsh"), + ShellFlag::Fish => (TMPL_COMP_FISH, ".fish"), + ShellFlag::Powershell => (TMPL_COMP_PWSH, ".ps1"), + ShellFlag::Other(_) => (TMPL_COMP_BASH, ".sh"), + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::ShellFlag; + + #[test] + fn get_tmpl_bash() { + let (tmpl, ext) = get_tmpl(&ShellFlag::Bash); + assert_eq!(ext, ".sh"); + assert!(!tmpl.is_empty(), "bash template should not be empty"); + } + + #[test] + fn get_tmpl_zsh() { + let (tmpl, ext) = get_tmpl(&ShellFlag::Zsh); + assert_eq!(ext, ".zsh"); + assert!(!tmpl.is_empty(), "zsh template should not be empty"); + } + + #[test] + fn get_tmpl_fish() { + let (tmpl, ext) = get_tmpl(&ShellFlag::Fish); + assert_eq!(ext, ".fish"); + assert!(!tmpl.is_empty(), "fish template should not be empty"); + } + + #[test] + fn get_tmpl_powershell() { + let (tmpl, ext) = get_tmpl(&ShellFlag::Powershell); + assert_eq!(ext, ".ps1"); + assert!(!tmpl.is_empty(), "powershell template should not be empty"); + } + + #[test] + fn get_tmpl_other() { + let (tmpl, ext) = get_tmpl(&ShellFlag::Other("custom".to_string())); + assert_eq!(ext, ".sh"); + assert!(!tmpl.is_empty(), "fallback template should not be empty"); + } +} diff --git a/mingling_core/src/build/pathf.rs b/mingling_core/src/build/pathf.rs new file mode 100644 index 0000000..d8d4698 --- /dev/null +++ b/mingling_core/src/build/pathf.rs @@ -0,0 +1,43 @@ +pub use mingling_pathf::config::*; +pub use mingling_pathf::module_pathf::*; +pub use mingling_pathf::pattern_analyzer::*; +pub use mingling_pathf::patterns::*; + +use std::path::Path; + +/// Wraps `analyze_and_build_type_mapping_for` with config derived from +/// the crate's feature flags (e.g., `dispatch_tree`). +pub fn analyze_and_build_type_mapping_for( + crate_dir: &Path, + output_dir: &Path, +) -> Result<(), crate::error::MinglingPathfinderError> { + let config = mingling_pathf::config::PathfinderConfig { + use_dispatch_tree: cfg!(feature = "dispatch_tree"), + }; + mingling_pathf::analyze_and_build_type_mapping_for(crate_dir, output_dir, &config) +} + +/// Wraps `analyze_and_build_type_mapping` (build.rs convenience) with config. +pub fn analyze_and_build_type_mapping() -> Result<(), crate::error::MinglingPathfinderError> { + let config = mingling_pathf::config::PathfinderConfig { + use_dispatch_tree: cfg!(feature = "dispatch_tree"), + }; + let crate_dir = + std::env::current_dir().map_err(crate::error::MinglingPathfinderError::IoError)?; + let crate_name = std::env::var("CARGO_PKG_NAME").map_err(|_| { + crate::error::MinglingPathfinderError::IoError(std::io::Error::new( + std::io::ErrorKind::NotFound, + "CARGO_PKG_NAME not set", + )) + })?; + let out_dir = std::env::var("OUT_DIR").map_err(|_| { + crate::error::MinglingPathfinderError::IoError(std::io::Error::new( + std::io::ErrorKind::NotFound, + "OUT_DIR not set", + )) + })?; + let output_dir = Path::new(&out_dir).join(&crate_name); + mingling_pathf::analyze_and_build_type_mapping_for(&crate_dir, &output_dir, &config)?; + println!("cargo:rerun-if-changed=src/"); + Ok(()) +} diff --git a/mingling_core/src/builds.rs b/mingling_core/src/builds.rs deleted file mode 100644 index 3c52907..0000000 --- a/mingling_core/src/builds.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[doc(hidden)] -#[cfg(feature = "comp")] -pub mod comp; - -#[doc(hidden)] -#[cfg(feature = "pathf")] -pub mod pathf; diff --git a/mingling_core/src/builds/comp.rs b/mingling_core/src/builds/comp.rs deleted file mode 100644 index 2abb1e1..0000000 --- a/mingling_core/src/builds/comp.rs +++ /dev/null @@ -1,168 +0,0 @@ -use std::path::PathBuf; - -use just_template::tmpl; - -use crate::ShellFlag; - -const TMPL_COMP_BASH: &str = include_str!("../../tmpls/comps/bash.sh"); -const TMPL_COMP_ZSH: &str = include_str!("../../tmpls/comps/zsh.zsh"); -const TMPL_COMP_FISH: &str = include_str!("../../tmpls/comps/fish.fish"); -const TMPL_COMP_PWSH: &str = include_str!("../../tmpls/comps/pwsh.ps1"); - -/// Generate shell completion scripts for a given binary name. -/// On Windows, generates `PowerShell` completion. -/// On Linux, generates Zsh, Bash, and Fish completions. -/// Scripts are written to the `OUT_DIR` (or `target/` if `OUT_DIR` is not set). -/// -/// # Example -/// ```rust,ignore -/// # use mingling_core::comp::ShellFlag; -/// # use mingling_core::build::build_comp_scripts; -/// -/// // Generate completion scripts for "myapp" -/// build_comp_scripts("myapp").unwrap(); -/// -/// // Generate completion scripts for current package -/// build_comp_scripts(env!("CARGO_PKG_NAME")).unwrap(); -/// ``` -pub fn build_comp_scripts(name: &str) -> Result<(), std::io::Error> { - #[cfg(target_os = "windows")] - { - build_comp_script(&ShellFlag::Powershell, name)?; - Ok(()) - } - - #[cfg(target_os = "linux")] - { - build_comp_script(&ShellFlag::Zsh, name)?; - build_comp_script(&ShellFlag::Bash, name)?; - build_comp_script(&ShellFlag::Fish, name)?; - Ok(()) - } - - #[cfg(target_os = "macos")] - { - build_comp_script(&ShellFlag::Zsh, name)?; - build_comp_script(&ShellFlag::Bash, name)?; - build_comp_script(&ShellFlag::Fish, name)?; - Ok(()) - } -} - -/// Generate a shell completion script for a specific shell. -/// -/// This function takes a shell flag and a binary name, selects the appropriate -/// template, substitutes the binary name into the template, and writes the -/// resulting completion script to the target directory (typically `target/`). -/// -/// # Example -/// ```rust,ignore -/// # use mingling_core::comp::ShellFlag; -/// # use mingling_core::build::build_comp_script; -/// build_comp_script(&ShellFlag::Bash, "myapp").unwrap(); -/// ``` -pub fn build_comp_script(shell_flag: &ShellFlag, bin_name: &str) -> Result<(), std::io::Error> { - let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); - let target_dir = out_dir.join("../../../").clone(); - build_comp_script_to(shell_flag, bin_name, &target_dir.to_string_lossy()) -} - -/// Generate a shell completion script to a specified directory. -/// -/// This function takes a shell flag, a binary name, and a target directory path, -/// selects the appropriate template, substitutes the binary name into the template, -/// and writes the resulting completion script to the specified directory. -/// -/// # Example -/// ```rust,ignore -/// # use mingling_core::comp::ShellFlag; -/// # use mingling_core::build::build_comp_script_to; -/// build_comp_script_to(&ShellFlag::Bash, "myapp", "target/completions").unwrap(); -/// ``` -pub fn build_comp_script_to( - shell_flag: &ShellFlag, - bin_name: &str, - target_dir: &str, -) -> Result<(), std::io::Error> { - let (tmpl_str, ext) = get_tmpl(shell_flag); - let mut tmpl = just_template::Template::from(tmpl_str); - tmpl!(bin_name = bin_name); - let target_path = std::path::PathBuf::from(target_dir); - std::fs::create_dir_all(&target_path)?; - let output_path = target_path.join(format!("{bin_name}_comp{ext}")); - std::fs::write(&output_path, tmpl.to_string()) -} - -/// Generate a shell completion script and write it to a specified file path. -/// -/// This function takes a shell flag, a binary name, and an output file path, -/// selects the appropriate template, substitutes the binary name into the template, -/// and writes the resulting completion script directly to the specified file path. -/// -/// # Example -/// ```rust,ignore -/// # use mingling_core::comp::ShellFlag; -/// # use mingling_core::build::build_comp_script_to_file; -/// build_comp_script_to_file(&ShellFlag::Bash, "myapp", "target/completions/myapp_comp.sh").unwrap(); -/// ``` -pub fn build_comp_script_to_file( - shell_flag: &ShellFlag, - bin_name: &str, - output_path: impl Into, -) -> Result<(), std::io::Error> { - let (tmpl_str, _ext) = get_tmpl(shell_flag); - let mut tmpl = just_template::Template::from(tmpl_str); - tmpl!(bin_name = bin_name); - std::fs::write(output_path.into(), tmpl.to_string()) -} - -fn get_tmpl(shell_flag: &ShellFlag) -> (&'static str, &'static str) { - match shell_flag { - ShellFlag::Bash => (TMPL_COMP_BASH, ".sh"), - ShellFlag::Zsh => (TMPL_COMP_ZSH, ".zsh"), - ShellFlag::Fish => (TMPL_COMP_FISH, ".fish"), - ShellFlag::Powershell => (TMPL_COMP_PWSH, ".ps1"), - ShellFlag::Other(_) => (TMPL_COMP_BASH, ".sh"), - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::ShellFlag; - - #[test] - fn get_tmpl_bash() { - let (tmpl, ext) = get_tmpl(&ShellFlag::Bash); - assert_eq!(ext, ".sh"); - assert!(!tmpl.is_empty(), "bash template should not be empty"); - } - - #[test] - fn get_tmpl_zsh() { - let (tmpl, ext) = get_tmpl(&ShellFlag::Zsh); - assert_eq!(ext, ".zsh"); - assert!(!tmpl.is_empty(), "zsh template should not be empty"); - } - - #[test] - fn get_tmpl_fish() { - let (tmpl, ext) = get_tmpl(&ShellFlag::Fish); - assert_eq!(ext, ".fish"); - assert!(!tmpl.is_empty(), "fish template should not be empty"); - } - - #[test] - fn get_tmpl_powershell() { - let (tmpl, ext) = get_tmpl(&ShellFlag::Powershell); - assert_eq!(ext, ".ps1"); - assert!(!tmpl.is_empty(), "powershell template should not be empty"); - } - - #[test] - fn get_tmpl_other() { - let (tmpl, ext) = get_tmpl(&ShellFlag::Other("custom".to_string())); - assert_eq!(ext, ".sh"); - assert!(!tmpl.is_empty(), "fallback template should not be empty"); - } -} diff --git a/mingling_core/src/builds/pathf.rs b/mingling_core/src/builds/pathf.rs deleted file mode 100644 index d8d4698..0000000 --- a/mingling_core/src/builds/pathf.rs +++ /dev/null @@ -1,43 +0,0 @@ -pub use mingling_pathf::config::*; -pub use mingling_pathf::module_pathf::*; -pub use mingling_pathf::pattern_analyzer::*; -pub use mingling_pathf::patterns::*; - -use std::path::Path; - -/// Wraps `analyze_and_build_type_mapping_for` with config derived from -/// the crate's feature flags (e.g., `dispatch_tree`). -pub fn analyze_and_build_type_mapping_for( - crate_dir: &Path, - output_dir: &Path, -) -> Result<(), crate::error::MinglingPathfinderError> { - let config = mingling_pathf::config::PathfinderConfig { - use_dispatch_tree: cfg!(feature = "dispatch_tree"), - }; - mingling_pathf::analyze_and_build_type_mapping_for(crate_dir, output_dir, &config) -} - -/// Wraps `analyze_and_build_type_mapping` (build.rs convenience) with config. -pub fn analyze_and_build_type_mapping() -> Result<(), crate::error::MinglingPathfinderError> { - let config = mingling_pathf::config::PathfinderConfig { - use_dispatch_tree: cfg!(feature = "dispatch_tree"), - }; - let crate_dir = - std::env::current_dir().map_err(crate::error::MinglingPathfinderError::IoError)?; - let crate_name = std::env::var("CARGO_PKG_NAME").map_err(|_| { - crate::error::MinglingPathfinderError::IoError(std::io::Error::new( - std::io::ErrorKind::NotFound, - "CARGO_PKG_NAME not set", - )) - })?; - let out_dir = std::env::var("OUT_DIR").map_err(|_| { - crate::error::MinglingPathfinderError::IoError(std::io::Error::new( - std::io::ErrorKind::NotFound, - "OUT_DIR not set", - )) - })?; - let output_dir = Path::new(&out_dir).join(&crate_name); - mingling_pathf::analyze_and_build_type_mapping_for(&crate_dir, &output_dir, &config)?; - println!("cargo:rerun-if-changed=src/"); - Ok(()) -} diff --git a/mingling_core/src/lib.rs b/mingling_core/src/lib.rs index 31476c9..b9dbd06 100644 --- a/mingling_core/src/lib.rs +++ b/mingling_core/src/lib.rs @@ -1,3 +1,4 @@ +// #![deny(missing_docs)] //! Mingling Core //! //! # Intro @@ -8,7 +9,7 @@ //! //! Recommended to import [mingling](https://crates.io/crates/mingling) to use its features. -#![deny(missing_docs)] +// Private Modules mod any; mod asset; @@ -16,20 +17,65 @@ mod program; mod renderer; mod tester; +/// Module for setting up a `Mingling` program. +/// +/// This module provides the [`ProgramSetup`] type, which allows users to configure +/// and initialize the program's execution environment. +pub mod setup { + pub use crate::program::setup::ProgramSetup; +} + +/// This module provides result types for Mingling components. +/// +/// These are re-exported at the top level via `mingling::res`. +#[doc(hidden)] +pub mod core_res { + #[cfg(feature = "repl")] + pub use crate::program::repl_exec::res::*; +} + +/// Provides the runtime logic for Mingling's dynamic completion system. +/// +/// This module contains the core functionality for the "comp" (completion) feature, +/// which enables dynamic tab-completion and input suggestion capabilities within +/// Mingling applications. +#[cfg(feature = "comp")] +pub(crate) mod comp; + +/// Provides Mingling's build script module, used in `build.rs` to provide build-time behavior for certain features. +/// +/// To use it, add the following to your `Cargo.toml` under `[build-dependencies]`, and enable the features +/// that require build-time behavior from the crate: +/// +/// ```toml +/// [build-dependencies.mingling] +/// version = "0.3.0" +/// features = [ +/// "build", // Enable it +/// "comp", // If you need completion-related build-time behavior, enable this as well +/// ] +/// ``` +#[cfg(feature = "build")] +#[doc(hidden)] +pub mod build; + +// Public Modules + /// Provides a toolkit for `Mingling` testing capabilities. pub mod test { pub use crate::tester::*; } -#[cfg(feature = "structural_renderer")] -pub use crate::renderer::structural::StructuralRenderer; +/// Provided for framework developers +pub mod debug; // NOT re-exported at top level: the `StructuralData` trait is sealed and only // accessible through the derive macro. Users who need the trait can access it // via `mingling::renderer::structural::StructuralData` (through the inner alias). -pub use crate::any::group::*; -pub use crate::any::*; +#[cfg(feature = "structural_renderer")] +pub use crate::renderer::structural::StructuralRenderer; +pub use crate::any::*; pub use crate::asset::chain::*; pub use crate::asset::dispatcher::*; pub use crate::asset::enum_tag::*; @@ -39,74 +85,32 @@ pub use crate::asset::lazy_resource::*; pub use crate::asset::node::*; pub use crate::asset::renderer::*; pub use crate::asset::routable::*; +#[cfg(feature = "comp")] +pub use crate::comp::*; +pub use crate::program::*; +pub use crate::renderer::render_result::*; /// All error types of `Mingling` pub mod error { pub use crate::asset::chain::error::*; pub use crate::exec::error::*; pub use crate::program::error::*; + #[cfg(feature = "structural_renderer")] pub use crate::renderer::structural::error::*; - #[cfg(feature = "pathf")] - pub use mingling_pathf::error::*; -} - -pub use crate::program::*; - -pub use crate::renderer::render_result::*; - -#[cfg(feature = "builds")] -#[doc(hidden)] -pub mod builds; - -/// Provides build scripts for users -#[cfg(feature = "builds")] -pub mod build { - #[cfg(feature = "comp")] - pub use crate::builds::comp::*; #[cfg(feature = "pathf")] - pub use crate::builds::pathf::*; + pub use mingling_pathf::error::*; } -/// Provided for framework developers -pub mod debug; - -#[cfg(feature = "comp")] #[doc(hidden)] -pub mod comp; - -#[cfg(feature = "comp")] -pub use crate::comp::*; +mod private; -/// Module for setting up a `Mingling` program. +/// Internal API provided by Mingling Core /// -/// This module provides the [`ProgramSetup`] type, which allows users to configure -/// and initialize the program's execution environment. -pub mod setup { - pub use crate::program::setup::ProgramSetup; -} - -/// Private API — not intended for direct use. +/// These are used by macros and are not exposed to users, but are still accessible externally. #[doc(hidden)] +#[allow(unused_imports)] pub mod __private { - use crate::ProgramCollect; - - /// Sealed trait for `StructuralData` — only implementable via derive macro. - pub trait StructuralDataSealed - where - C: ProgramCollect, - { - } - - /// Re-export so the derive macro can reference the trait without - /// conflicting with the derive macro name at `::mingling::StructuralData`. - #[cfg(feature = "structural_renderer")] - pub use crate::renderer::structural::structural_data::StructuralData; -} - -#[doc(hidden)] -pub mod core_res { - #[cfg(feature = "repl")] - pub use crate::program::repl_exec::res::ResREPL; + pub use crate::private::*; } diff --git a/mingling_core/src/private.rs b/mingling_core/src/private.rs new file mode 100644 index 0000000..371ada2 --- /dev/null +++ b/mingling_core/src/private.rs @@ -0,0 +1,12 @@ +/// Sealed trait for `StructuralData` — only implementable via derive macro. +#[cfg(feature = "structural_renderer")] +pub trait StructuralDataSealed +where + C: crate::ProgramCollect, +{ +} + +/// Re-export so the derive macro can reference the trait without +/// conflicting with the derive macro name at `::mingling::StructuralData`. +#[cfg(feature = "structural_renderer")] +pub use crate::renderer::structural::structural_data::StructuralData; -- cgit