You've already forked uutils-args
mirror of
https://github.com/uutils/uutils-args.git
synced 2026-06-10 16:13:08 -07:00
Adapt formatting
This commit is contained in:
@@ -63,7 +63,10 @@ mod test {
|
||||
],
|
||||
..Command::default()
|
||||
};
|
||||
assert_eq!(render(&c), "complete -F _comp_uu_foo 'foo';_comp_uu_foo(){ local cur;_init_completion||return;COMPREPLY=();if [[ \"$cur\" != \"-*\" ]]; then _filedir;fi;COMPREPLY+=($(compgen -W \"-a --all -x \" -- \"$cur\"));}\n")
|
||||
assert_eq!(
|
||||
render(&c),
|
||||
"complete -F _comp_uu_foo 'foo';_comp_uu_foo(){ local cur;_init_completion||return;COMPREPLY=();if [[ \"$cur\" != \"-*\" ]]; then _filedir;fi;COMPREPLY+=($(compgen -W \"-a --all -x \" -- \"$cur\"));}\n"
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -79,6 +82,9 @@ mod test {
|
||||
}],
|
||||
..Command::default()
|
||||
};
|
||||
assert_eq!(render(&c), "complete -F _comp_uu_bracket '[';_comp_uu_bracket(){ local cur;_init_completion||return;COMPREPLY=();if [[ \"$cur\" != \"-*\" ]]; then _filedir;fi;COMPREPLY+=($(compgen -W \"-x \" -- \"$cur\"));}\n")
|
||||
assert_eq!(
|
||||
render(&c),
|
||||
"complete -F _comp_uu_bracket '[';_comp_uu_bracket(){ local cur;_init_completion||return;COMPREPLY=();if [[ \"$cur\" != \"-*\" ]]; then _filedir;fi;COMPREPLY+=($(compgen -W \"-x \" -- \"$cur\"));}\n"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -77,7 +77,11 @@ pub fn render(c: &Command, shell: &str) -> String {
|
||||
"nu" | "nushell" => nu::render(c),
|
||||
"man" => man::render(c),
|
||||
"bash" => bash::render(c),
|
||||
"sh" | "csh" | "elvish" | "powershell" => panic!("shell '{shell}' completion is not implemented yet!"),
|
||||
_ => panic!("unknown option '{shell}'! Expected one of: \"md\", \"fish\", \"zsh\", \"nu[shell]\", \"man\", \"sh\", \"bash\", \"csh\", \"elvish\", \"powershell\""),
|
||||
"sh" | "csh" | "elvish" | "powershell" => {
|
||||
panic!("shell '{shell}' completion is not implemented yet!")
|
||||
}
|
||||
_ => panic!(
|
||||
"unknown option '{shell}'! Expected one of: \"md\", \"fish\", \"zsh\", \"nu[shell]\", \"man\", \"sh\", \"bash\", \"csh\", \"elvish\", \"powershell\""
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
// file that was distributed with this source code.
|
||||
|
||||
use crate::{Command, Flag, Value};
|
||||
use roff::{bold, italic, roman, Roff};
|
||||
use roff::{Roff, bold, italic, roman};
|
||||
|
||||
pub fn render(c: &Command) -> String {
|
||||
let mut page = Roff::new();
|
||||
|
||||
+24
-22
@@ -2,7 +2,7 @@
|
||||
// file that was distributed with this source code.
|
||||
|
||||
use syn::{
|
||||
meta::ParseNestedMeta, parse::ParseStream, Attribute, Expr, Ident, LitInt, LitStr, Token,
|
||||
Attribute, Expr, Ident, LitInt, LitStr, Token, meta::ParseNestedMeta, parse::ParseStream,
|
||||
};
|
||||
|
||||
use crate::flags::Flags;
|
||||
@@ -141,7 +141,7 @@ impl OptionAttr {
|
||||
return Err(syn::Error::new_spanned(
|
||||
ident,
|
||||
"unrecognized argument for option attribute",
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -186,27 +186,29 @@ impl ValueAttr {
|
||||
return Ok(value_attr);
|
||||
}
|
||||
|
||||
attr.parse_args_with(|s: ParseStream| loop {
|
||||
if let Ok(litstr) = s.parse::<LitStr>() {
|
||||
value_attr.keys.push(litstr.value());
|
||||
} else {
|
||||
let ident = s.parse::<Ident>()?;
|
||||
match ident.to_string().as_str() {
|
||||
"value" => {
|
||||
s.parse::<Token![=]>()?;
|
||||
let p = s.parse::<Expr>()?;
|
||||
value_attr.value = Some(p);
|
||||
attr.parse_args_with(|s: ParseStream| {
|
||||
loop {
|
||||
if let Ok(litstr) = s.parse::<LitStr>() {
|
||||
value_attr.keys.push(litstr.value());
|
||||
} else {
|
||||
let ident = s.parse::<Ident>()?;
|
||||
match ident.to_string().as_str() {
|
||||
"value" => {
|
||||
s.parse::<Token![=]>()?;
|
||||
let p = s.parse::<Expr>()?;
|
||||
value_attr.value = Some(p);
|
||||
}
|
||||
_ => return Err(s.error("unrecognized keyword in value attribute")),
|
||||
}
|
||||
_ => return Err(s.error("unrecognized keyword in value attribute")),
|
||||
}
|
||||
}
|
||||
|
||||
if s.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
s.parse::<Token![,]>()?;
|
||||
if s.is_empty() {
|
||||
return Ok(());
|
||||
if s.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
s.parse::<Token![,]>()?;
|
||||
if s.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
||||
@@ -244,7 +246,7 @@ fn assert_expr_is_array_of_litstr(expr: Expr, flag: &str) -> syn::Result<Vec<Str
|
||||
return Err(syn::Error::new_spanned(
|
||||
expr,
|
||||
format!("Argument to `{flag}` must be an array"),
|
||||
))
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -259,7 +261,7 @@ fn assert_expr_is_array_of_litstr(expr: Expr, flag: &str) -> syn::Result<Vec<Str
|
||||
return Err(syn::Error::new_spanned(
|
||||
elem,
|
||||
format!("Argument to `{flag}` must be an array of string literals"),
|
||||
))
|
||||
));
|
||||
}
|
||||
};
|
||||
strings.push(val);
|
||||
|
||||
+15
-9
@@ -62,9 +62,11 @@ impl Flags {
|
||||
.strip_prefix('=')
|
||||
.and_then(|s| s.strip_suffix(']'))
|
||||
.unwrap();
|
||||
assert!(optional
|
||||
.chars()
|
||||
.all(|c: char| c.is_alphanumeric() || c == '-'));
|
||||
assert!(
|
||||
optional
|
||||
.chars()
|
||||
.all(|c: char| c.is_alphanumeric() || c == '-')
|
||||
);
|
||||
Value::Optional(optional.into())
|
||||
} else {
|
||||
panic!("Invalid long flag '{flag}'");
|
||||
@@ -88,14 +90,18 @@ impl Flags {
|
||||
let value = if val.is_empty() {
|
||||
Value::No
|
||||
} else if let Some(optional) = val.strip_prefix('[').and_then(|s| s.strip_suffix(']')) {
|
||||
assert!(optional
|
||||
.chars()
|
||||
.all(|c: char| c.is_alphanumeric() || c == '-'));
|
||||
assert!(
|
||||
optional
|
||||
.chars()
|
||||
.all(|c: char| c.is_alphanumeric() || c == '-')
|
||||
);
|
||||
Value::Optional(optional.into())
|
||||
} else if let Some(required) = val.strip_prefix(' ') {
|
||||
assert!(required
|
||||
.chars()
|
||||
.all(|c: char| c.is_alphanumeric() || c == '-'));
|
||||
assert!(
|
||||
required
|
||||
.chars()
|
||||
.all(|c: char| c.is_alphanumeric() || c == '-')
|
||||
);
|
||||
Value::Required(required.into())
|
||||
} else {
|
||||
panic!("Invalid short flag '{flag}'")
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ use help::{help_handling, help_string, version_handling};
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{parse_macro_input, Data::Enum, DeriveInput};
|
||||
use syn::{Data::Enum, DeriveInput, parse_macro_input};
|
||||
|
||||
/// Documentation for this can be found in `uutils_args`.
|
||||
#[proc_macro_derive(Arguments, attributes(arg, arguments))]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::ffi::OsString;
|
||||
|
||||
use uutils_args::{
|
||||
positional::{Opt, Unpack},
|
||||
Arguments, Options,
|
||||
positional::{Opt, Unpack},
|
||||
};
|
||||
|
||||
#[derive(Clone, Arguments)]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::ffi::OsString;
|
||||
|
||||
use uutils_args::{
|
||||
positional::{Many1, Unpack},
|
||||
Arguments, Options,
|
||||
positional::{Many1, Unpack},
|
||||
};
|
||||
|
||||
#[derive(Clone, Arguments)]
|
||||
|
||||
@@ -4,8 +4,8 @@ use std::{
|
||||
};
|
||||
|
||||
use uutils_args::{
|
||||
positional::{Opt, Unpack},
|
||||
Arguments, Options,
|
||||
positional::{Opt, Unpack},
|
||||
};
|
||||
|
||||
#[derive(Clone, Arguments)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{ffi::OsString, path::PathBuf};
|
||||
use uutils_args::{
|
||||
positional::{Many0, Opt, Unpack},
|
||||
Arguments, Options,
|
||||
positional::{Many0, Opt, Unpack},
|
||||
};
|
||||
|
||||
#[derive(Clone, Arguments)]
|
||||
|
||||
Reference in New Issue
Block a user