Adapt formatting

This commit is contained in:
Daniel Hofstetter
2025-04-01 11:19:52 +02:00
parent 6b2f3d5aa5
commit 7a126b5f45
10 changed files with 59 additions and 41 deletions
+8 -2
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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 -1
View File
@@ -1,8 +1,8 @@
use std::ffi::OsString;
use uutils_args::{
positional::{Opt, Unpack},
Arguments, Options,
positional::{Opt, Unpack},
};
#[derive(Clone, Arguments)]
+1 -1
View File
@@ -1,8 +1,8 @@
use std::ffi::OsString;
use uutils_args::{
positional::{Many1, Unpack},
Arguments, Options,
positional::{Many1, Unpack},
};
#[derive(Clone, Arguments)]
+1 -1
View File
@@ -4,8 +4,8 @@ use std::{
};
use uutils_args::{
positional::{Opt, Unpack},
Arguments, Options,
positional::{Opt, Unpack},
};
#[derive(Clone, Arguments)]
+1 -1
View File
@@ -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)]