diff --git a/Cargo.toml b/Cargo.toml index 660520f..e9c6517 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "uutils-args" version = "0.1.0" -edition = "2021" +edition = "2024" authors = ["Terts Diepraam"] license = "MIT" diff --git a/complete/Cargo.toml b/complete/Cargo.toml index 16c73d0..c9bae20 100644 --- a/complete/Cargo.toml +++ b/complete/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "uutils-args-complete" version = "0.1.0" -edition = "2021" +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" \ No newline at end of file +roff = "0.2.1" diff --git a/complete/src/bash.rs b/complete/src/bash.rs index 265c2c0..e72afad 100644 --- a/complete/src/bash.rs +++ b/complete/src/bash.rs @@ -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" + ) } } diff --git a/complete/src/lib.rs b/complete/src/lib.rs index 39cbd62..cfad348 100644 --- a/complete/src/lib.rs +++ b/complete/src/lib.rs @@ -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\"" + ), } } diff --git a/complete/src/man.rs b/complete/src/man.rs index 046cf08..0e0a38c 100644 --- a/complete/src/man.rs +++ b/complete/src/man.rs @@ -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(); diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 1e6b1a3..0a2f39c 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "uutils-args-derive" version = "0.1.0" -edition = "2021" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/derive/src/argument.rs b/derive/src/argument.rs index dec13c2..94b84eb 100644 --- a/derive/src/argument.rs +++ b/derive/src/argument.rs @@ -187,7 +187,7 @@ pub fn long_handling(args: &[Argument], help_flags: &Flags) -> TokenStream { ArgType::Option { flags, takes_value, - ref default, + default, hidden: _, } => (flags, takes_value, default), ArgType::Free { .. } => continue, diff --git a/derive/src/attributes.rs b/derive/src/attributes.rs index a517f14..da582f8 100644 --- a/derive/src/attributes.rs +++ b/derive/src/attributes.rs @@ -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::() { - value_attr.keys.push(litstr.value()); - } else { - let ident = s.parse::()?; - match ident.to_string().as_str() { - "value" => { - s.parse::()?; - let p = s.parse::()?; - value_attr.value = Some(p); + attr.parse_args_with(|s: ParseStream| { + loop { + if let Ok(litstr) = s.parse::() { + value_attr.keys.push(litstr.value()); + } else { + let ident = s.parse::()?; + match ident.to_string().as_str() { + "value" => { + s.parse::()?; + let p = s.parse::()?; + 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::()?; - if s.is_empty() { - return Ok(()); + if s.is_empty() { + return Ok(()); + } + s.parse::()?; + if s.is_empty() { + return Ok(()); + } } })?; @@ -244,7 +246,7 @@ fn assert_expr_is_array_of_litstr(expr: Expr, flag: &str) -> syn::Result syn::Result