diff options
Diffstat (limited to 'mingling_core')
| -rw-r--r-- | mingling_core/Cargo.toml | 9 | ||||
| -rw-r--r-- | mingling_core/src/build.rs | 28 | ||||
| -rw-r--r-- | mingling_core/src/build/comp.rs | 183 | ||||
| -rw-r--r-- | mingling_core/src/build/pathf.rs | 98 | ||||
| -rw-r--r-- | mingling_core/src/docs/build.md | 57 | ||||
| -rw-r--r-- | mingling_core/src/lib.rs | 7 | ||||
| -rw-r--r-- | mingling_core/tests/test-all/Cargo.lock | 99 | ||||
| -rw-r--r-- | mingling_core/tests/test-all/Cargo.toml | 1 | ||||
| -rw-r--r-- | mingling_core/tests/test-comp/Cargo.lock | 102 | ||||
| -rw-r--r-- | mingling_core/tests/test-comp/Cargo.toml | 2 | ||||
| -rw-r--r-- | mingling_core/tmpls/comps/bash.sh | 67 | ||||
| -rw-r--r-- | mingling_core/tmpls/comps/fish.fish | 120 | ||||
| -rw-r--r-- | mingling_core/tmpls/comps/pwsh.ps1 | 136 | ||||
| -rw-r--r-- | mingling_core/tmpls/comps/zsh.zsh | 71 |
14 files changed, 195 insertions, 785 deletions
diff --git a/mingling_core/Cargo.toml b/mingling_core/Cargo.toml index aecf476..989abe4 100644 --- a/mingling_core/Cargo.toml +++ b/mingling_core/Cargo.toml @@ -14,7 +14,6 @@ categories = ["command-line-interface"] nightly = [] default = [] async = [] -build = [] picker = [] structural_renderer = ["dep:serde"] @@ -26,18 +25,12 @@ toml_serde_fmt = ["dep:toml"] repl = [] clap = [] -comp = ["dep:just_template"] +comp = [] debug = ["dep:log", "dep:env_logger"] -pathf = ["dep:mingling_pathf"] [dependencies] -mingling_pathf = { workspace = true, optional = true } - just_fmt.workspace = true -# comp -just_template = { workspace = true, optional = true } - # structural_renderer serde = { workspace = true, optional = true } ron = { workspace = true, optional = true } diff --git a/mingling_core/src/build.rs b/mingling_core/src/build.rs deleted file mode 100644 index 213d529..0000000 --- a/mingling_core/src/build.rs +++ /dev/null @@ -1,28 +0,0 @@ -#[doc(hidden)] -#[cfg(feature = "comp")] -mod comp; - -#[cfg(feature = "comp")] -mod comp_re_export { - pub use super::comp::build_comp_script; - pub use super::comp::build_comp_script_to; - pub use super::comp::build_comp_script_to_file; - pub use super::comp::build_comp_scripts; -} - -#[cfg(feature = "comp")] -pub use comp_re_export::*; - -#[doc(hidden)] -#[cfg(feature = "pathf")] -mod pathf; - -#[cfg(feature = "pathf")] -mod pathf_re_export { - pub use super::pathf::analyze; - pub use super::pathf::analyze_and_build_type_mapping; - pub use super::pathf::analyze_and_build_type_mapping_for; -} - -#[cfg(feature = "pathf")] -pub use pathf_re_export::*; diff --git a/mingling_core/src/build/comp.rs b/mingling_core/src/build/comp.rs deleted file mode 100644 index d6bb34f..0000000 --- a/mingling_core/src/build/comp.rs +++ /dev/null @@ -1,183 +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 -/// ``` -/// # #[cfg(all(feature = "build", feature = "comp"))] { -/// # temp_env::with_var("OUT_DIR", Some(".temp/target/test/out/"), || { -/// # use mingling_core::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 -/// ``` -/// # #[cfg(all(feature = "build", feature = "comp"))] { -/// # temp_env::with_var("OUT_DIR", Some(".temp/target/test/out/"), || { -/// # use mingling_core::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("../../../"); - 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 -/// ``` -/// # #[cfg(all(feature = "build", feature = "comp"))] { -/// # temp_env::with_var("OUT_DIR", Some(".temp/target/test/out/"), || { -/// # use mingling_core::ShellFlag; -/// # use mingling_core::build::build_comp_script_to; -/// build_comp_script_to(&ShellFlag::Bash, "myapp", ".temp/target/test/out/").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 -/// ``` -/// # #[cfg(all(feature = "build", feature = "comp"))] { -/// # temp_env::with_var("OUT_DIR", Some(".temp/target/test/out/"), || { -/// # use mingling_core::ShellFlag; -/// # use mingling_core::build::build_comp_script_to_file; -/// build_comp_script_to_file(&ShellFlag::Bash, "myapp", ".temp/target/test/out/myapp.comp.sh").unwrap(); -/// # }); -/// # } -/// ``` -pub fn build_comp_script_to_file( - shell_flag: &ShellFlag, - bin_name: &str, - output_path: impl Into<PathBuf>, -) -> 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()) -} - -const fn get_tmpl(shell_flag: &ShellFlag) -> (&'static str, &'static str) { - match shell_flag { - ShellFlag::Bash | ShellFlag::Other(_) => (TMPL_COMP_BASH, ".sh"), - ShellFlag::Zsh => (TMPL_COMP_ZSH, ".zsh"), - ShellFlag::Fish => (TMPL_COMP_FISH, ".fish"), - ShellFlag::Powershell => (TMPL_COMP_PWSH, ".ps1"), - } -} - -#[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 deleted file mode 100644 index 4b8af1b..0000000 --- a/mingling_core/src/build/pathf.rs +++ /dev/null @@ -1,98 +0,0 @@ -#![allow(unused_imports)] - -pub use mingling_pathf::module_pathf::*; -pub use mingling_pathf::pattern_analyzer::*; -pub use mingling_pathf::patterns::*; - -use std::path::Path; - -/// Analyzes and builds a type mapping for a specific crate. -/// -/// Accepts `crate_dir` and `output_dir`, and invokes `pathf` to build the type mapping. -/// -/// # Arguments -/// -/// - `crate_dir`: Root directory of the crate's source code to analyze (usually `CARGO_MANIFEST_DIR`). -/// - `output_dir`: Output directory for generated artifacts (type mapping data). -/// -/// # Returns -/// -/// - On success: returns `Ok(())`; -/// - On failure: returns the corresponding `MinglingPathfinderError`. -/// -/// # Example -/// -/// ``` -/// # #[cfg(all(feature = "build", feature = "pathf"))] { -/// use mingling_core::build::analyze_and_build_type_mapping_for; -/// use std::path::Path; -/// -/// let crate_dir = Path::new("."); -/// let output_dir = Path::new(".temp/target/out"); -/// analyze_and_build_type_mapping_for(crate_dir, output_dir).expect("analysis failed"); -/// # } -/// ``` -pub fn analyze_and_build_type_mapping_for( - crate_dir: &Path, - output_dir: &Path, -) -> Result<(), crate::error::MinglingPathfinderError> { - mingling_pathf::analyze_and_build_type_mapping_for(crate_dir, output_dir) -} - -/// # Analyzes and builds a type mapping -/// -/// This function reads the current crate directory (`CARGO_PKG_NAME`) and output directory (`OUT_DIR`) -/// from environment variables, automatically combines them into the target output path, and invokes -/// the underlying analysis logic. Suitable for use in `build.rs`. -/// -/// It also sends the `cargo:rerun-if-changed=src/` directive to Cargo so that a rebuild is -/// automatically triggered when source code changes. -/// -/// # Prerequisites -/// -/// This function depends on the following environment variables, which are typically set -/// automatically during a Cargo build: -/// -/// - `CARGO_PKG_NAME`: Name of the current crate. -/// - `OUT_DIR`: Build output directory provided by Cargo. -/// -/// If these variables are missing, a corresponding [`MinglingPathfinderError`](crate::error::MinglingPathfinderError) -/// is returned. -/// -/// # Returns -/// -/// Returns `Ok(())` on success; returns a corresponding -/// [`MinglingPathfinderError`](crate::error::MinglingPathfinderError) on failure. -/// -/// # Example -/// -/// ``` -/// # #[cfg(all(feature = "build", feature = "pathf"))] { -/// use mingling_core::build::analyze_and_build_type_mapping; -/// -/// fn main() { -/// analyze_and_build_type_mapping().expect("failed to build type mapping"); -/// } -/// # } -/// ``` - -pub fn analyze_and_build_type_mapping() -> Result<(), crate::error::MinglingPathfinderError> { - 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)?; - println!("cargo:rerun-if-changed=src/"); - Ok(()) -} diff --git a/mingling_core/src/docs/build.md b/mingling_core/src/docs/build.md deleted file mode 100644 index 6f9285a..0000000 --- a/mingling_core/src/docs/build.md +++ /dev/null @@ -1,57 +0,0 @@ -Provide Mingling's build script module for build-time behavior of specific features in `build.rs`. - -To use it, add a dependency on mingling under `[build-dependencies]` in `Cargo.toml`, and enable the relevant features: - -## Build-Time Related Features - -| Name | Purpose | -| ---------------- | ------------------------------------------------------------------------------------------------- | -| `build` | Master switch for build-time features | -| `build_advanced` | Master switch for build-time features, paired with the `advanced` feature | -| `build_full` | Master switch for build-time features, paired with the `full` feature | -| `comp` | Completion script builder; both sides must enable it, generates cross-platform completion scripts | -| `pathf` | Type path analyzer; both sides must enable it, generates type mapping tables | -| `dispatch_tree` | Compile-time dispatch tree; when `pathf` is a build-time dependency, | -| | and `dispatch_tree` (included in `advanced` or `full`) is enabled, both sides should enable it | - -```toml -# Cargo.toml -[dependencies.mingling] -features = [ - "advanced", # Enable `advanced` if using it -] - -[build-dependencies.mingling] -features = [ - "build_advanced" # This side should enable `build_advanced` -] -``` - -## `build.rs` Templates - -You can use the following template to write `build.rs` to quickly gain the build-time capabilities of `comp` and `pathf`: - -```rust,ignore -// build.rs -fn main() { - build_scripts(); - build_pathf_mapping(); -} - -/// Generate completion scripts -fn build_scripts() { - // `env!("CARGO_PKG_NAME")` equals the crate name, which matches the binary name. - // If your binary name differs from the crate name, specify it explicitly. - mingling::build::build_comp_scripts( - // Your binary name: - env!("CARGO_PKG_NAME"), - ) - .unwrap(); -} - -fn build_pathf_mapping() { - // Build pathf type mapping to ensure that the enabled `pathf` feature - // can correctly scan macros in the project - mingling::build::analyze_and_build_type_mapping().unwrap(); -} -``` diff --git a/mingling_core/src/lib.rs b/mingling_core/src/lib.rs index 2aa2ce1..1d26ebb 100644 --- a/mingling_core/src/lib.rs +++ b/mingling_core/src/lib.rs @@ -46,10 +46,6 @@ pub mod core_res { #[cfg(feature = "comp")] pub(crate) mod comp; -#[cfg(feature = "build")] -#[doc = include_str!("docs/build.md")] -pub mod build; - // Public Modules /// Provides a toolkit for `Mingling` testing capabilities. @@ -90,9 +86,6 @@ pub mod error { #[cfg(feature = "structural_renderer")] pub use crate::renderer::structural::error::*; - - #[cfg(feature = "pathf")] - pub use mingling_pathf::error::*; } #[doc(hidden)] diff --git a/mingling_core/tests/test-all/Cargo.lock b/mingling_core/tests/test-all/Cargo.lock index d239541..79202f9 100644 --- a/mingling_core/tests/test-all/Cargo.lock +++ b/mingling_core/tests/test-all/Cargo.lock @@ -16,7 +16,7 @@ version = "0.2.0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.118", ] [[package]] @@ -35,6 +35,39 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] +name = "camino" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb1307f12aa967b5a58416e87b3653360e0fd614a016b6e970db08fecbb1b80d" +dependencies = [ + "serde_core", +] + +[[package]] +name = "cargo-platform" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0061da739915fae12ea00e16397555ed4371a6bb285431aab930f61b0aa4ba" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "cargo_metadata" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef987d17b0a113becdd19d3d0022d04d7ef41f9efe4f3fb63ac44ba61df3ade9" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + +[[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -108,7 +141,7 @@ checksum = "1471eb68722ecefeb71debdde2859e8725341f171d3f42b3a98a0862ad19416e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.118", ] [[package]] @@ -140,7 +173,7 @@ checksum = "eca871cea620b07bd2e6da0c883891a25bead698c43a9ab64b0fd663a7a78d5f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.118", "toml 0.8.23", ] @@ -159,7 +192,6 @@ name = "mingling_core" version = "0.5.0" dependencies = [ "just_fmt 0.2.0", - "just_template", "might_be_async", "ron", "serde", @@ -173,9 +205,21 @@ name = "mingling_macros" version = "0.5.0" dependencies = [ "just_fmt 0.2.0", + "just_template", + "mingling_pathf", "proc-macro2", "quote", - "syn", + "syn 2.0.118", +] + +[[package]] +name = "mingling_pathf" +version = "0.5.0" +dependencies = [ + "cargo_metadata", + "just_fmt 0.2.0", + "proc-macro2", + "syn 2.0.118", ] [[package]] @@ -278,6 +322,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] name = "serde" version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -304,7 +358,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.118", ] [[package]] @@ -389,6 +443,17 @@ dependencies = [ ] [[package]] +name = "syn" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] name = "test-all" version = "0.1.0" dependencies = [ @@ -398,6 +463,26 @@ dependencies = [ ] [[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] name = "tokio" version = "1.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -422,7 +507,7 @@ checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.118", ] [[package]] diff --git a/mingling_core/tests/test-all/Cargo.toml b/mingling_core/tests/test-all/Cargo.toml index df2efdb..7f50f2f 100644 --- a/mingling_core/tests/test-all/Cargo.toml +++ b/mingling_core/tests/test-all/Cargo.toml @@ -10,7 +10,6 @@ publish = false mingling = { path = "../../../mingling", features = [ "structural_renderer_full", "comp", - "builds", "repl", "dispatch_tree", "picker", diff --git a/mingling_core/tests/test-comp/Cargo.lock b/mingling_core/tests/test-comp/Cargo.lock index 1a37590..199c76e 100644 --- a/mingling_core/tests/test-comp/Cargo.lock +++ b/mingling_core/tests/test-comp/Cargo.lock @@ -3,6 +3,39 @@ version = 4 [[package]] +name = "camino" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb1307f12aa967b5a58416e87b3653360e0fd614a016b6e970db08fecbb1b80d" +dependencies = [ + "serde_core", +] + +[[package]] +name = "cargo-platform" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0061da739915fae12ea00e16397555ed4371a6bb285431aab930f61b0aa4ba" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "cargo_metadata" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef987d17b0a113becdd19d3d0022d04d7ef41f9efe4f3fb63ac44ba61df3ade9" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + +[[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -25,6 +58,12 @@ dependencies = [ ] [[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] name = "just_fmt" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -88,7 +127,6 @@ name = "mingling_core" version = "0.5.0" dependencies = [ "just_fmt 0.2.0", - "just_template", "might_be_async", ] @@ -97,12 +135,24 @@ name = "mingling_macros" version = "0.5.0" dependencies = [ "just_fmt 0.2.0", + "just_template", + "mingling_pathf", "proc-macro2", "quote", "syn 2.0.118", ] [[package]] +name = "mingling_pathf" +version = "0.5.0" +dependencies = [ + "cargo_metadata", + "just_fmt 0.2.0", + "proc-macro2", + "syn 2.0.118", +] + +[[package]] name = "proc-macro2" version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -121,12 +171,23 @@ dependencies = [ ] [[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] name = "serde" version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" dependencies = [ "serde_core", + "serde_derive", ] [[package]] @@ -150,6 +211,19 @@ dependencies = [ ] [[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] name = "serde_spanned" version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -188,6 +262,26 @@ dependencies = [ ] [[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] name = "toml" version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -242,3 +336,9 @@ checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" dependencies = [ "memchr", ] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/mingling_core/tests/test-comp/Cargo.toml b/mingling_core/tests/test-comp/Cargo.toml index 9ceca3e..789e172 100644 --- a/mingling_core/tests/test-comp/Cargo.toml +++ b/mingling_core/tests/test-comp/Cargo.toml @@ -7,4 +7,4 @@ publish = false [workspace] [dependencies] -mingling = { path = "../../../mingling", features = ["comp", "builds"] } +mingling = { path = "../../../mingling", features = ["comp"] } diff --git a/mingling_core/tmpls/comps/bash.sh b/mingling_core/tmpls/comps/bash.sh deleted file mode 100644 index edec28d..0000000 --- a/mingling_core/tmpls/comps/bash.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env bash -_<<<bin_name>>>_bash_completion() { - local line="${COMP_LINE:0:COMP_POINT}" - local cur="${line##* }" - local prev="" - local word_index=1 - - local before="${line:0:$(( ${#line} - ${#cur} ))}" - local -a before_words - if [[ -n "$before" ]]; then - read -ra before_words <<< "$before" - word_index=$(( ${#before_words[@]} + 1 )) - if [[ $word_index -gt 1 ]]; then - prev="${before_words[${#before_words[@]}-1]}" - fi - fi - - local args=() - args+=(-f "${COMP_LINE//-/^}") - args+=(-C "$COMP_POINT") - args+=(-w "${cur//-/^}") - args+=(-p "${prev//-/^}") - args+=(-c "${COMP_WORDS[0]//-/^}") - args+=(-i "$word_index") - args+=(-F "bash") - - for word in "${COMP_WORDS[@]}"; do - args+=(-a "${word//-/^}") - done - - local suggestions - if suggestions=$(<<<bin_name>>> __comp "${args[@]}" 2>/dev/null); then - if [ $? -eq 0 ]; then - if [ "$suggestions" = "_file_" ]; then - compopt -o default - COMPREPLY=() - return - fi - - if [ -n "$suggestions" ]; then - local -a all_suggestions filtered - mapfile -t all_suggestions < <(printf '%s\n' "$suggestions") - - for suggestion in "${all_suggestions[@]}"; do - [ -z "$cur" ] || [[ "$suggestion" == "$cur"* ]] && filtered+=("$suggestion") - done - - if [ ${#filtered[@]} -gt 0 ]; then - COMPREPLY=("${filtered[@]}") - if [[ "$cur" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then - local colon_prefix="${cur%"${cur##*:}"}" - local -a ltrimmed=() - for suggestion in "${COMPREPLY[@]}"; do - ltrimmed+=("${suggestion#"$colon_prefix"}") - done - COMPREPLY=("${ltrimmed[@]}") - fi - fi - return - fi - fi - fi - - COMPREPLY=() -} - -complete -F _<<<bin_name>>>_bash_completion <<<bin_name>>> diff --git a/mingling_core/tmpls/comps/fish.fish b/mingling_core/tmpls/comps/fish.fish deleted file mode 100644 index 64b4ed3..0000000 --- a/mingling_core/tmpls/comps/fish.fish +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env fish -function __<<<bin_name>>>_fish_complete - set -l cmdline (commandline -opc) - set -l buffer (commandline -b) - set -l cursor (commandline -C) - set -l current_token (commandline -ct) - - set -l current_word "" - set -l previous_word "" - set -l word_index 0 - set -l char_count 0 - - set -l found false - if test -n "$current_token" - for i in (seq (count $cmdline)) - if test "$cmdline[$i]" = "$current_token" - set word_index $i - set current_word $current_token - if test $i -gt 1 - set previous_word $cmdline[(math $i - 1)] - end - set found true - break - end - end - end - - if not $found - for i in (seq (count $cmdline)) - set word $cmdline[$i] - if test $i -gt 1 - set char_count (math $char_count + 1) - end - set char_count (math $char_count + (string length -- "$word")) - - if test $cursor -le $char_count - set word_index $i - set current_word $word - if test $i -gt 1 - set previous_word $cmdline[(math $i - 1)] - end - break - end - end - end - - if test $word_index -eq 0 -a (count $cmdline) -gt 0 - set word_index (count $cmdline) - if test -n "$current_token" -a "$current_token" != "$cmdline[-1]" - set current_word $current_token - else - set current_word "" - end - set previous_word $cmdline[-1] - end - - if test $word_index -gt (count $cmdline) - set word_index (count $cmdline) - end - - set -l buffer_replaced (string replace -a "-" "^" -- "$buffer") - set -l current_word_replaced (string replace -a "-" "^" -- "$current_word") - set -l previous_word_replaced (string replace -a "-" "^" -- "$previous_word") - - set -l args - set -a args -f "$buffer_replaced" -C "$cursor" -w "$current_word_replaced" -p "$previous_word_replaced" - - if test (count $cmdline) -gt 0 - set -a args -c "$cmdline[1]" - else - set -a args -c "" - end - - set -a args -i "$word_index" - - if test (count $cmdline) -gt 0 - set -l all_words_replaced - for word in $cmdline - set -a all_words_replaced (string replace -a "-" "^" -- "$word") - end - - if test -n "$current_token" -a "$current_word" = "$current_token" - set -l found_in_cmdline false - for word in $cmdline - if test "$word" = "$current_token" - set found_in_cmdline true - break - end - end - if not $found_in_cmdline -a $word_index -eq (math (count $cmdline) + 1) - set -a all_words_replaced (string replace -a "-" "^" -- "$current_token") - end - end - - set -a args -a $all_words_replaced - else - set -a args -a "" - end - - set -a args -F "fish" - - set -l output - if not <<<bin_name>>> __comp $args 2>/dev/null | read -z output - return - end - - set -l trimmed_output (string trim -- "$output") - if test "$trimmed_output" = "_file_" - __fish_complete_path "$current_word" - return 0 - else if test -n "$trimmed_output" - string split -n \n -- "$output" | while read -l line - test -n "$line" && echo "$line" - end - return 0 - end - return 1 -end - -complete -c <<<bin_name>>> -a '(__<<<bin_name>>>_fish_complete)' -f diff --git a/mingling_core/tmpls/comps/pwsh.ps1 b/mingling_core/tmpls/comps/pwsh.ps1 deleted file mode 100644 index d72a027..0000000 --- a/mingling_core/tmpls/comps/pwsh.ps1 +++ /dev/null @@ -1,136 +0,0 @@ -# PowerShell completion script for <<<bin_name>>> -Register-ArgumentCompleter -Native -CommandName '<<<bin_name>>>' -ScriptBlock { - param($wordToComplete, $commandAst, $cursorPosition) - - $line = $commandAst.ToString() - - $elements = @() - if ($commandAst.CommandElements.Count -gt 0) { - $elements = $commandAst.CommandElements | ForEach-Object { $_.Value } - } - - $commandName = if ($elements.Count -gt 0) { $elements[0] } else { "" } - - $currentWord = $wordToComplete - $previousWord = "" - $wordIndex = 0 - - $found = $false - for ($i = 0; $i -lt $elements.Count; $i++) { - if ($elements[$i] -eq $currentWord) { - $wordIndex = $i + 1 - if ($i -gt 0) { - $previousWord = $elements[$i - 1] - } - $found = $true - break - } - } - - if (-not $found) { - $wordIndex = $elements.Count + 1 - if ($elements.Count -gt 0) { - $previousWord = $elements[-1] - } - } - - $args = @( - "-C", $cursorPosition.ToString() - "-i", $wordIndex.ToString() - "-F", "Powershell" - ) - - if ($line) { - $args += "-f" - $args += ($line -replace '-', '^') - } - if ($currentWord) { - $args += "-w" - $args += ($currentWord -replace '-', '^') - } - if ($previousWord) { - $args += "-p" - $args += ($previousWord -replace '-', '^') - } - if ($commandName) { - $args += "-c" - $args += ($commandName -replace '-', '^') - } - - foreach ($element in $elements) { - if ($element) { - $args += "-a" - $args += ($element -replace '-', '^') - } - } - - $originalEncoding = [Console]::OutputEncoding - $originalPSEncoding = $OutputEncoding - [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 - $OutputEncoding = [System.Text.Encoding]::UTF8 - - $output = & <<<bin_name>>> __comp $args 2>&1 - - [Console]::OutputEncoding = $originalEncoding - $OutputEncoding = $originalPSEncoding - - $output = $output -replace "`r`n", "`n" -replace "`r", "`n" - - if (-not $output) { - return @() - } - - $lines = $output -split "`n" - - if ($lines.Count -eq 0) { - return @() - } - - $firstLine = $lines[0].Trim() - - if ($firstLine -eq "_file_") { - if ($lines.Count -gt 1) { - $fileSuggestions = $lines[1..($lines.Count-1)] - } else { - $fileSuggestions = @() - } - - $completionResults = @() - $fileSuggestions | ForEach-Object { - $path = $_ - $isDirectory = $path.EndsWith([System.IO.Path]::DirectorySeparatorChar) -or $path.EndsWith('/') - $completionType = if ($isDirectory) { 'ProviderContainer' } else { 'ProviderItem' } - $completionResults += [System.Management.Automation.CompletionResult]::new($path, $path, $completionType, $path) - } - - return $completionResults - } else { - $completionResults = @() - - foreach ($line in $lines) { - $trimmedLine = $line.Trim() - - if ($trimmedLine -match '^([^$]+)\$\((.+)\)$') { - $text = $matches[1] - $description = $matches[2] - $completionResults += [System.Management.Automation.CompletionResult]::new( - $text, - $text, - 'ParameterValue', - $description - ) - } else { - $text = $trimmedLine - $resultType = if ($text.StartsWith('-')) { 'ParameterName' } else { 'ParameterValue' } - $completionResults += [System.Management.Automation.CompletionResult]::new( - $text, - $text, - $resultType, - $text - ) - } - } - - return $completionResults - } -} diff --git a/mingling_core/tmpls/comps/zsh.zsh b/mingling_core/tmpls/comps/zsh.zsh deleted file mode 100644 index 7cf5f7b..0000000 --- a/mingling_core/tmpls/comps/zsh.zsh +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env zsh -_<<<bin_name>>>_completion() { - local -a args - local suggestions - - local buffer="$BUFFER" - local cursor="$CURSOR" - local current_word="${words[$CURRENT]}" - local previous_word="" - local command_name="${words[1]}" - local word_index="$CURRENT" - - if [[ $CURRENT -gt 1 ]]; then - previous_word="${words[$((CURRENT-1))]}" - fi - - args=( - -f "${buffer//-/^}" - -C "$cursor" - -w "${current_word//-/^}" - -p "${previous_word//-/^}" - -c "$command_name" - -i "$word_index" - -a "${(@)words//-/^}" - -F "zsh" - ) - - suggestions=$(<<<bin_name>>> __comp "${args[@]}" 2>/dev/null) - - if [[ $? -eq 0 ]] && [[ -n "$suggestions" ]]; then - local -a completions - completions=(${(f)suggestions}) - - if [[ "${completions[1]}" == "_file_" ]]; then - shift completions - _files - else - local -a parsed_completions - for item in "${completions[@]}"; do - if [[ "$item" =~ '^([^$]+)\$\((.+)\)$' ]]; then - parsed_completions+=("${match[1]//:/\\:}:${match[2]}") - else - parsed_completions+=("${item//:/\\:}") - fi - done - - if (( $+functions[_describe] )); then - _describe '<<<bin_name>>> commands' parsed_completions - else - local -a simple_completions - for item in "${completions[@]}"; do - if [[ "$item" =~ '^([^$]+)\$\((.+)\)$' ]]; then - simple_completions+=("${match[1]}") - else - simple_completions+=("$item") - fi - done - compadd -a simple_completions - fi - fi - fi -} - -if (( $+functions[compdef] )); then - compdef _<<<bin_name>>>_completion <<<bin_name>>> - if [[ $? -ne 0 ]]; then - compctl -K _<<<bin_name>>>_completion <<<bin_name>>> - fi -else - compctl -K _<<<bin_name>>>_completion <<<bin_name>>> -fi |
