You've already forked uutils-args
mirror of
https://github.com/uutils/uutils-args.git
synced 2026-06-10 16:13:08 -07:00
make 'complete' available to procmacro by conversion to module
This commit is contained in:
+4
-4
@@ -10,13 +10,13 @@ repository = "https://github.com/uutils/uutils-args"
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
[dependencies]
|
[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"
|
lexopt = "0.3.0"
|
||||||
|
roff = "0.2.1"
|
||||||
|
strsim = "0.11.1"
|
||||||
|
uutils-args-derive = { version = "0.1.0", path = "derive" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
parse-is-complete = []
|
parse-is-complete = []
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["derive", "complete"]
|
members = ["derive"]
|
||||||
|
|||||||
@@ -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"
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../LICENSE
|
|
||||||
+18
-10
@@ -49,11 +49,15 @@ pub fn complete(args: &[Argument], file: &Option<String>) -> TokenStream {
|
|||||||
.map(|Flag { flag, value }| {
|
.map(|Flag { flag, value }| {
|
||||||
let flag = flag.to_string();
|
let flag = flag.to_string();
|
||||||
let value = match value {
|
let value = match value {
|
||||||
Value::No => quote!(::uutils_args_complete::Value::No),
|
Value::No => quote!(::uutils_args::complete::Value::No),
|
||||||
Value::Optional(name) => quote!(::uutils_args_complete::Value::Optional(#name)),
|
Value::Optional(name) => {
|
||||||
Value::Required(name) => quote!(::uutils_args_complete::Value::Required(#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,
|
flag: #flag,
|
||||||
value: #value
|
value: #value
|
||||||
})
|
})
|
||||||
@@ -64,11 +68,15 @@ pub fn complete(args: &[Argument], file: &Option<String>) -> TokenStream {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|Flag { flag, value }| {
|
.map(|Flag { flag, value }| {
|
||||||
let value = match value {
|
let value = match value {
|
||||||
Value::No => quote!(::uutils_args_complete::Value::No),
|
Value::No => quote!(::uutils_args::complete::Value::No),
|
||||||
Value::Optional(name) => quote!(::uutils_args_complete::Value::Optional(#name)),
|
Value::Optional(name) => {
|
||||||
Value::Required(name) => quote!(::uutils_args_complete::Value::Required(#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,
|
flag: #flag,
|
||||||
value: #value
|
value: #value
|
||||||
})
|
})
|
||||||
@@ -81,7 +89,7 @@ pub fn complete(args: &[Argument], file: &Option<String>) -> TokenStream {
|
|||||||
};
|
};
|
||||||
|
|
||||||
arg_specs.push(quote!(
|
arg_specs.push(quote!(
|
||||||
::uutils_args_complete::Arg {
|
::uutils_args::complete::Arg {
|
||||||
short: vec![#(#short),*],
|
short: vec![#(#short),*],
|
||||||
long: vec![#(#long),*],
|
long: vec![#(#long),*],
|
||||||
help: #help,
|
help: #help,
|
||||||
@@ -90,7 +98,7 @@ pub fn complete(args: &[Argument], file: &Option<String>) -> TokenStream {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
quote!(::uutils_args_complete::Command {
|
quote!(::uutils_args::complete::Command {
|
||||||
name: option_env!("CARGO_BIN_NAME").unwrap_or(env!("CARGO_PKG_NAME")),
|
name: option_env!("CARGO_BIN_NAME").unwrap_or(env!("CARGO_PKG_NAME")),
|
||||||
summary: #summary,
|
summary: #summary,
|
||||||
after_options: #after_options,
|
after_options: #after_options,
|
||||||
|
|||||||
+3
-3
@@ -117,7 +117,7 @@ pub fn arguments(input: TokenStream) -> TokenStream {
|
|||||||
#version_string
|
#version_string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete() -> ::uutils_args_complete::Command<'static> {
|
fn complete() -> ::uutils_args::complete::Command<'static> {
|
||||||
use ::uutils_args::Value;
|
use ::uutils_args::Value;
|
||||||
#complete_command
|
#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),*];
|
let keys: [&str; #keys_len] = [#(#all_keys),*];
|
||||||
::uutils_args_complete::ValueHint::Strings(
|
::uutils_args::complete::ValueHint::Strings(
|
||||||
keys
|
keys
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(ToString::to_string)
|
.map(ToString::to_string)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
use crate::{Command, Flag};
|
use crate::complete::{Command, Flag};
|
||||||
|
|
||||||
/// Create completion script for `bash`
|
/// Create completion script for `bash`
|
||||||
///
|
///
|
||||||
@@ -35,7 +35,7 @@ pub fn render(c: &Command) -> String {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::render;
|
use super::render;
|
||||||
use crate::{Arg, Command, Flag, Value};
|
use crate::complete::{Arg, Command, Flag, Value};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple() {
|
fn simple() {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
use crate::{Command, Flag, ValueHint};
|
use crate::complete::{Command, Flag, ValueHint};
|
||||||
|
|
||||||
/// Create completion script for `fish`
|
/// Create completion script for `fish`
|
||||||
///
|
///
|
||||||
@@ -45,7 +45,7 @@ fn render_value_hint(value: &ValueHint) -> String {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::render;
|
use super::render;
|
||||||
use crate::{Arg, Command, Flag, Value, ValueHint};
|
use crate::complete::{Arg, Command, Flag, Value, ValueHint};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn short() {
|
fn short() {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// 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};
|
use roff::{Roff, bold, italic, roman};
|
||||||
|
|
||||||
pub fn render(c: &Command) -> String {
|
pub fn render(c: &Command) -> String {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// 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
|
/// Render command to a markdown file for mdbook
|
||||||
pub fn render(c: &Command) -> String {
|
pub fn render(c: &Command) -> String {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// 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;
|
use std::fmt::Write;
|
||||||
|
|
||||||
/// Create completion script for `nushell`
|
/// Create completion script for `nushell`
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// 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`
|
/// Create completion script for `zsh`
|
||||||
pub fn render(c: &Command) -> String {
|
pub fn render(c: &Command) -> String {
|
||||||
+3
-2
@@ -9,6 +9,7 @@
|
|||||||
//!
|
//!
|
||||||
#![doc = include_str!("../README.md")]
|
#![doc = include_str!("../README.md")]
|
||||||
|
|
||||||
|
pub mod complete;
|
||||||
mod error;
|
mod error;
|
||||||
pub mod internal;
|
pub mod internal;
|
||||||
pub mod positional;
|
pub mod positional;
|
||||||
@@ -103,7 +104,7 @@ pub trait Arguments: Sized {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete() -> uutils_args_complete::Command<'static>;
|
fn complete() -> complete::Command<'static>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator over arguments.
|
/// An iterator over arguments.
|
||||||
@@ -197,7 +198,7 @@ pub trait Options<Arg: Arguments>: Sized {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn complete(shell: &str) -> String {
|
fn complete(shell: &str) -> String {
|
||||||
uutils_args_complete::render(&Arg::complete(), shell)
|
complete::render(&Arg::complete(), shell)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
|
use crate::complete::ValueHint;
|
||||||
use crate::error::{Error, ErrorKind};
|
use crate::error::{Error, ErrorKind};
|
||||||
use std::{
|
use std::{
|
||||||
ffi::{OsStr, OsString},
|
ffi::{OsStr, OsString},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
use uutils_args_complete::ValueHint;
|
|
||||||
|
|
||||||
pub type ValueResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;
|
pub type ValueResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ where
|
|||||||
Ok(Some(T::from_value(value)?))
|
Ok(Some(T::from_value(value)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn value_hint() -> uutils_args_complete::ValueHint {
|
fn value_hint() -> ValueHint {
|
||||||
T::value_hint()
|
T::value_hint()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user