Skip to content

Commit 7a126b5

Browse files
committed
Adapt formatting
1 parent 6b2f3d5 commit 7a126b5

File tree

10 files changed

+59
-41
lines changed

10 files changed

+59
-41
lines changed

complete/src/bash.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ mod test {
6363
],
6464
..Command::default()
6565
};
66-
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")
66+
assert_eq!(
67+
render(&c),
68+
"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"
69+
)
6770
}
6871

6972
#[test]
@@ -79,6 +82,9 @@ mod test {
7982
}],
8083
..Command::default()
8184
};
82-
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")
85+
assert_eq!(
86+
render(&c),
87+
"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"
88+
)
8389
}
8490
}

complete/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ pub fn render(c: &Command, shell: &str) -> String {
7777
"nu" | "nushell" => nu::render(c),
7878
"man" => man::render(c),
7979
"bash" => bash::render(c),
80-
"sh" | "csh" | "elvish" | "powershell" => panic!("shell '{shell}' completion is not implemented yet!"),
81-
_ => panic!("unknown option '{shell}'! Expected one of: \"md\", \"fish\", \"zsh\", \"nu[shell]\", \"man\", \"sh\", \"bash\", \"csh\", \"elvish\", \"powershell\""),
80+
"sh" | "csh" | "elvish" | "powershell" => {
81+
panic!("shell '{shell}' completion is not implemented yet!")
82+
}
83+
_ => panic!(
84+
"unknown option '{shell}'! Expected one of: \"md\", \"fish\", \"zsh\", \"nu[shell]\", \"man\", \"sh\", \"bash\", \"csh\", \"elvish\", \"powershell\""
85+
),
8286
}
8387
}

complete/src/man.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// file that was distributed with this source code.
33

44
use crate::{Command, Flag, Value};
5-
use roff::{bold, italic, roman, Roff};
5+
use roff::{Roff, bold, italic, roman};
66

77
pub fn render(c: &Command) -> String {
88
let mut page = Roff::new();

derive/src/attributes.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// file that was distributed with this source code.
33

44
use syn::{
5-
meta::ParseNestedMeta, parse::ParseStream, Attribute, Expr, Ident, LitInt, LitStr, Token,
5+
Attribute, Expr, Ident, LitInt, LitStr, Token, meta::ParseNestedMeta, parse::ParseStream,
66
};
77

88
use crate::flags::Flags;
@@ -141,7 +141,7 @@ impl OptionAttr {
141141
return Err(syn::Error::new_spanned(
142142
ident,
143143
"unrecognized argument for option attribute",
144-
))
144+
));
145145
}
146146
}
147147
Ok(())
@@ -186,27 +186,29 @@ impl ValueAttr {
186186
return Ok(value_attr);
187187
}
188188

189-
attr.parse_args_with(|s: ParseStream| loop {
190-
if let Ok(litstr) = s.parse::<LitStr>() {
191-
value_attr.keys.push(litstr.value());
192-
} else {
193-
let ident = s.parse::<Ident>()?;
194-
match ident.to_string().as_str() {
195-
"value" => {
196-
s.parse::<Token![=]>()?;
197-
let p = s.parse::<Expr>()?;
198-
value_attr.value = Some(p);
189+
attr.parse_args_with(|s: ParseStream| {
190+
loop {
191+
if let Ok(litstr) = s.parse::<LitStr>() {
192+
value_attr.keys.push(litstr.value());
193+
} else {
194+
let ident = s.parse::<Ident>()?;
195+
match ident.to_string().as_str() {
196+
"value" => {
197+
s.parse::<Token![=]>()?;
198+
let p = s.parse::<Expr>()?;
199+
value_attr.value = Some(p);
200+
}
201+
_ => return Err(s.error("unrecognized keyword in value attribute")),
199202
}
200-
_ => return Err(s.error("unrecognized keyword in value attribute")),
201203
}
202-
}
203204

204-
if s.is_empty() {
205-
return Ok(());
206-
}
207-
s.parse::<Token![,]>()?;
208-
if s.is_empty() {
209-
return Ok(());
205+
if s.is_empty() {
206+
return Ok(());
207+
}
208+
s.parse::<Token![,]>()?;
209+
if s.is_empty() {
210+
return Ok(());
211+
}
210212
}
211213
})?;
212214

@@ -244,7 +246,7 @@ fn assert_expr_is_array_of_litstr(expr: Expr, flag: &str) -> syn::Result<Vec<Str
244246
return Err(syn::Error::new_spanned(
245247
expr,
246248
format!("Argument to `{flag}` must be an array"),
247-
))
249+
));
248250
}
249251
};
250252

@@ -259,7 +261,7 @@ fn assert_expr_is_array_of_litstr(expr: Expr, flag: &str) -> syn::Result<Vec<Str
259261
return Err(syn::Error::new_spanned(
260262
elem,
261263
format!("Argument to `{flag}` must be an array of string literals"),
262-
))
264+
));
263265
}
264266
};
265267
strings.push(val);

derive/src/flags.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ impl Flags {
6262
.strip_prefix('=')
6363
.and_then(|s| s.strip_suffix(']'))
6464
.unwrap();
65-
assert!(optional
66-
.chars()
67-
.all(|c: char| c.is_alphanumeric() || c == '-'));
65+
assert!(
66+
optional
67+
.chars()
68+
.all(|c: char| c.is_alphanumeric() || c == '-')
69+
);
6870
Value::Optional(optional.into())
6971
} else {
7072
panic!("Invalid long flag '{flag}'");
@@ -88,14 +90,18 @@ impl Flags {
8890
let value = if val.is_empty() {
8991
Value::No
9092
} else if let Some(optional) = val.strip_prefix('[').and_then(|s| s.strip_suffix(']')) {
91-
assert!(optional
92-
.chars()
93-
.all(|c: char| c.is_alphanumeric() || c == '-'));
93+
assert!(
94+
optional
95+
.chars()
96+
.all(|c: char| c.is_alphanumeric() || c == '-')
97+
);
9498
Value::Optional(optional.into())
9599
} else if let Some(required) = val.strip_prefix(' ') {
96-
assert!(required
97-
.chars()
98-
.all(|c: char| c.is_alphanumeric() || c == '-'));
100+
assert!(
101+
required
102+
.chars()
103+
.all(|c: char| c.is_alphanumeric() || c == '-')
104+
);
99105
Value::Required(required.into())
100106
} else {
101107
panic!("Invalid short flag '{flag}'")

derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use help::{help_handling, help_string, version_handling};
1919

2020
use proc_macro::TokenStream;
2121
use quote::quote;
22-
use syn::{parse_macro_input, Data::Enum, DeriveInput};
22+
use syn::{Data::Enum, DeriveInput, parse_macro_input};
2323

2424
/// Documentation for this can be found in `uutils_args`.
2525
#[proc_macro_derive(Arguments, attributes(arg, arguments))]

tests/coreutils/base32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::ffi::OsString;
22

33
use uutils_args::{
4-
positional::{Opt, Unpack},
54
Arguments, Options,
5+
positional::{Opt, Unpack},
66
};
77

88
#[derive(Clone, Arguments)]

tests/coreutils/basename.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::ffi::OsString;
22

33
use uutils_args::{
4-
positional::{Many1, Unpack},
54
Arguments, Options,
5+
positional::{Many1, Unpack},
66
};
77

88
#[derive(Clone, Arguments)]

tests/coreutils/mktemp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::{
44
};
55

66
use uutils_args::{
7-
positional::{Opt, Unpack},
87
Arguments, Options,
8+
positional::{Opt, Unpack},
99
};
1010

1111
#[derive(Clone, Arguments)]

tests/coreutils/shuf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{ffi::OsString, path::PathBuf};
22
use uutils_args::{
3-
positional::{Many0, Opt, Unpack},
43
Arguments, Options,
4+
positional::{Many0, Opt, Unpack},
55
};
66

77
#[derive(Clone, Arguments)]

0 commit comments

Comments
 (0)