From bbb193d3870fb5b564b1189bc80d4df8b3f65280 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Wed, 16 Apr 2025 02:12:55 +0200 Subject: [PATCH] make 'complete' available to procmacro by conversion to module --- Cargo.toml | 8 +++---- complete/Cargo.toml | 11 --------- complete/LICENSE | 1 - derive/src/complete.rs | 28 ++++++++++++++-------- derive/src/lib.rs | 6 ++--- {complete/src => src/complete}/bash.rs | 4 ++-- {complete/src => src/complete}/fish.rs | 4 ++-- {complete/src => src/complete}/man.rs | 2 +- {complete/src => src/complete}/md.rs | 2 +- complete/src/lib.rs => src/complete/mod.rs | 0 {complete/src => src/complete}/nu.rs | 2 +- {complete/src => src/complete}/zsh.rs | 2 +- src/lib.rs | 5 ++-- src/value.rs | 4 ++-- 14 files changed, 38 insertions(+), 41 deletions(-) delete mode 100644 complete/Cargo.toml delete mode 120000 complete/LICENSE rename {complete/src => src/complete}/bash.rs (97%) rename {complete/src => src/complete}/fish.rs (97%) rename {complete/src => src/complete}/man.rs (97%) rename {complete/src => src/complete}/md.rs (97%) rename complete/src/lib.rs => src/complete/mod.rs (100%) rename {complete/src => src/complete}/nu.rs (97%) rename {complete/src => src/complete}/zsh.rs (98%) diff --git a/Cargo.toml b/Cargo.toml index 32a3905..6adaff6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,13 +10,13 @@ repository = "https://github.com/uutils/uutils-args" readme = "README.md" [dependencies] -uutils-args-derive = { version = "0.1.0", path = "derive" } -uutils-args-complete = { version = "0.1.0", path = "complete" } -strsim = "0.11.1" lexopt = "0.3.0" +roff = "0.2.1" +strsim = "0.11.1" +uutils-args-derive = { version = "0.1.0", path = "derive" } [features] parse-is-complete = [] [workspace] -members = ["derive", "complete"] +members = ["derive"] diff --git a/complete/Cargo.toml b/complete/Cargo.toml deleted file mode 100644 index c9bae20..0000000 --- a/complete/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "uutils-args-complete" -version = "0.1.0" -edition = "2024" -authors = ["Terts Diepraam"] -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -roff = "0.2.1" diff --git a/complete/LICENSE b/complete/LICENSE deleted file mode 120000 index ea5b606..0000000 --- a/complete/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE \ No newline at end of file diff --git a/derive/src/complete.rs b/derive/src/complete.rs index 10b9691..9e919d1 100644 --- a/derive/src/complete.rs +++ b/derive/src/complete.rs @@ -49,11 +49,15 @@ pub fn complete(args: &[Argument], file: &Option) -> TokenStream { .map(|Flag { flag, value }| { let flag = flag.to_string(); let value = match value { - Value::No => quote!(::uutils_args_complete::Value::No), - Value::Optional(name) => quote!(::uutils_args_complete::Value::Optional(#name)), - Value::Required(name) => quote!(::uutils_args_complete::Value::Required(#name)), + Value::No => quote!(::uutils_args::complete::Value::No), + Value::Optional(name) => { + quote!(::uutils_args::complete::Value::Optional(#name)) + } + Value::Required(name) => { + quote!(::uutils_args::complete::Value::Required(#name)) + } }; - quote!(::uutils_args_complete::Flag { + quote!(::uutils_args::complete::Flag { flag: #flag, value: #value }) @@ -64,11 +68,15 @@ pub fn complete(args: &[Argument], file: &Option) -> TokenStream { .iter() .map(|Flag { flag, value }| { let value = match value { - Value::No => quote!(::uutils_args_complete::Value::No), - Value::Optional(name) => quote!(::uutils_args_complete::Value::Optional(#name)), - Value::Required(name) => quote!(::uutils_args_complete::Value::Required(#name)), + Value::No => quote!(::uutils_args::complete::Value::No), + Value::Optional(name) => { + quote!(::uutils_args::complete::Value::Optional(#name)) + } + Value::Required(name) => { + quote!(::uutils_args::complete::Value::Required(#name)) + } }; - quote!(::uutils_args_complete::Flag { + quote!(::uutils_args::complete::Flag { flag: #flag, value: #value }) @@ -81,7 +89,7 @@ pub fn complete(args: &[Argument], file: &Option) -> TokenStream { }; arg_specs.push(quote!( - ::uutils_args_complete::Arg { + ::uutils_args::complete::Arg { short: vec![#(#short),*], long: vec![#(#long),*], help: #help, @@ -90,7 +98,7 @@ pub fn complete(args: &[Argument], file: &Option) -> TokenStream { )) } - quote!(::uutils_args_complete::Command { + quote!(::uutils_args::complete::Command { name: option_env!("CARGO_BIN_NAME").unwrap_or(env!("CARGO_PKG_NAME")), summary: #summary, after_options: #after_options, diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 5061a3e..73a08a2 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -117,7 +117,7 @@ pub fn arguments(input: TokenStream) -> TokenStream { #version_string } - fn complete() -> ::uutils_args_complete::Command<'static> { + fn complete() -> ::uutils_args::complete::Command<'static> { use ::uutils_args::Value; #complete_command } @@ -212,9 +212,9 @@ pub fn value(input: TokenStream) -> TokenStream { }) } - fn value_hint() -> ::uutils_args_complete::ValueHint { + fn value_hint() -> ::uutils_args::complete::ValueHint { let keys: [&str; #keys_len] = [#(#all_keys),*]; - ::uutils_args_complete::ValueHint::Strings( + ::uutils_args::complete::ValueHint::Strings( keys .into_iter() .map(ToString::to_string) diff --git a/complete/src/bash.rs b/src/complete/bash.rs similarity index 97% rename from complete/src/bash.rs rename to src/complete/bash.rs index e72afad..d69eb8b 100644 --- a/complete/src/bash.rs +++ b/src/complete/bash.rs @@ -1,7 +1,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use crate::{Command, Flag}; +use crate::complete::{Command, Flag}; /// Create completion script for `bash` /// @@ -35,7 +35,7 @@ pub fn render(c: &Command) -> String { #[cfg(test)] mod test { use super::render; - use crate::{Arg, Command, Flag, Value}; + use crate::complete::{Arg, Command, Flag, Value}; #[test] fn simple() { diff --git a/complete/src/fish.rs b/src/complete/fish.rs similarity index 97% rename from complete/src/fish.rs rename to src/complete/fish.rs index d6f0f66..d718e81 100644 --- a/complete/src/fish.rs +++ b/src/complete/fish.rs @@ -1,7 +1,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use crate::{Command, Flag, ValueHint}; +use crate::complete::{Command, Flag, ValueHint}; /// Create completion script for `fish` /// @@ -45,7 +45,7 @@ fn render_value_hint(value: &ValueHint) -> String { #[cfg(test)] mod test { use super::render; - use crate::{Arg, Command, Flag, Value, ValueHint}; + use crate::complete::{Arg, Command, Flag, Value, ValueHint}; #[test] fn short() { diff --git a/complete/src/man.rs b/src/complete/man.rs similarity index 97% rename from complete/src/man.rs rename to src/complete/man.rs index 0e0a38c..d4befed 100644 --- a/complete/src/man.rs +++ b/src/complete/man.rs @@ -1,7 +1,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use crate::{Command, Flag, Value}; +use crate::complete::{Command, Flag, Value}; use roff::{Roff, bold, italic, roman}; pub fn render(c: &Command) -> String { diff --git a/complete/src/md.rs b/src/complete/md.rs similarity index 97% rename from complete/src/md.rs rename to src/complete/md.rs index 1c2fa1b..883c5b5 100644 --- a/complete/src/md.rs +++ b/src/complete/md.rs @@ -1,7 +1,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use crate::{Command, Flag, Value}; +use crate::complete::{Command, Flag, Value}; /// Render command to a markdown file for mdbook pub fn render(c: &Command) -> String { diff --git a/complete/src/lib.rs b/src/complete/mod.rs similarity index 100% rename from complete/src/lib.rs rename to src/complete/mod.rs diff --git a/complete/src/nu.rs b/src/complete/nu.rs similarity index 97% rename from complete/src/nu.rs rename to src/complete/nu.rs index fb9016c..e7f0271 100644 --- a/complete/src/nu.rs +++ b/src/complete/nu.rs @@ -1,7 +1,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use crate::{Arg, Command, Flag, Value, ValueHint}; +use crate::complete::{Arg, Command, Flag, Value, ValueHint}; use std::fmt::Write; /// Create completion script for `nushell` diff --git a/complete/src/zsh.rs b/src/complete/zsh.rs similarity index 98% rename from complete/src/zsh.rs rename to src/complete/zsh.rs index 2b709f8..68f9d53 100644 --- a/complete/src/zsh.rs +++ b/src/complete/zsh.rs @@ -1,7 +1,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use crate::{Arg, Command, Flag, Value, ValueHint}; +use crate::complete::{Arg, Command, Flag, Value, ValueHint}; /// Create completion script for `zsh` pub fn render(c: &Command) -> String { diff --git a/src/lib.rs b/src/lib.rs index e2c9cce..5a0be4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ //! #![doc = include_str!("../README.md")] +pub mod complete; mod error; pub mod internal; pub mod positional; @@ -103,7 +104,7 @@ pub trait Arguments: Sized { Ok(()) } - fn complete() -> uutils_args_complete::Command<'static>; + fn complete() -> complete::Command<'static>; } /// An iterator over arguments. @@ -197,7 +198,7 @@ pub trait Options: Sized { } fn complete(shell: &str) -> String { - uutils_args_complete::render(&Arg::complete(), shell) + complete::render(&Arg::complete(), shell) } } diff --git a/src/value.rs b/src/value.rs index 2109a6a..c3efc1d 100644 --- a/src/value.rs +++ b/src/value.rs @@ -1,12 +1,12 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. +use crate::complete::ValueHint; use crate::error::{Error, ErrorKind}; use std::{ ffi::{OsStr, OsString}, path::PathBuf, }; -use uutils_args_complete::ValueHint; pub type ValueResult = Result>; @@ -95,7 +95,7 @@ where Ok(Some(T::from_value(value)?)) } - fn value_hint() -> uutils_args_complete::ValueHint { + fn value_hint() -> ValueHint { T::value_hint() } }