Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call unraw() on idents #186

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions argh/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@ fn explicit_long_value_for_option() {
assert_eq!(cmd.x, 5);
}

#[test]
fn raw_identifier() {
#[derive(FromArgs, Debug)]
/// Short description
struct Cmd {
#[argh(switch)]
/// whether to move the file
r#move: bool,
}

let cmd = Cmd::from_args(&["cmdname"], &["--move"]).unwrap();
assert!(cmd.r#move);
}

/// Test that descriptions can start with an initialism despite
/// usually being required to start with a lowercase letter.
#[derive(FromArgs)]
Expand Down
4 changes: 3 additions & 1 deletion argh_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

use syn::ext::IdentExt as _;

/// Implementation of the `FromArgs` and `argh(...)` derive attributes.
///
/// For more thorough documentation, see the `argh` crate itself.
Expand Down Expand Up @@ -188,7 +190,7 @@ impl<'a> StructField<'a> {
let long_name = match kind {
FieldKind::Switch | FieldKind::Option => {
let long_name = attrs.long.as_ref().map(syn::LitStr::value).unwrap_or_else(|| {
let kebab_name = to_kebab_case(&name.to_string());
let kebab_name = to_kebab_case(&name.unraw().to_string());
check_long_name(errors, name, &kebab_name);
kebab_name
});
Expand Down