Repository: google/argh (rust)

Issue:
Suggestion: `#[argh(rename = "name")]`
Problem: Often, fields that are option members have long (descriptive) names that make sense in the source code, but are too long to type for cli options. 
The attribute `short = 'x'` can only take single chars, so that can't be used to shorten them.

Solution: Adding a way to rename cli option members using `#[argh(rename = "name")]`.
Similar to `#[serde(rename = "name")]`.


Pull request description:
Make positional arg honor arg_name
Closes #28 

----

Question. How do I run the integration tests in `./tests`? `cargo test` won't run them. I had to move it into argh package so cargo test runs them.

On related note, does this mean that the CI https://github.com/google/argh/blob/master/.github/workflows/rust.yml#L17 does not run those tests?


Patch:
diff --git a/argh_derive/src/help.rs b/argh_derive/src/help.rs
index 82bfc47..9a2c5b9 100644
--- a/argh_derive/src/help.rs
+++ b/argh_derive/src/help.rs
@@ -11,6 +11,7 @@ use {
     argh_shared::INDENT,
     proc_macro2::{Span, TokenStream},
     quote::quote,
+    syn::LitStr,
 };
 
 const SECTION_SEPARATOR: &str = "\n\n";
@@ -126,7 +127,9 @@ fn positional_usage(out: &mut String, field: &StructField<'_>) {
         out.push('[');
     }
     out.push('<');
-    out.push_str(&field.name.to_string());
+    let name =
+        field.attrs.arg_name.as_ref().map(LitStr::value).unwrap_or_else(|| field.name.to_string());
+    out.push_str(&name);
     if field.optionality == Optionality::Repeating {
         out.push_str("...");
     }


Test patch:
diff --git a/tests/lib.rs b/argh/tests/lib.rs
similarity index 98%
rename from tests/lib.rs
rename to argh/tests/lib.rs
index 9369bad..963540e 100644
--- a/tests/lib.rs
+++ b/argh/tests/lib.rs
@@ -872,6 +872,27 @@ Notes:
 Error codes:
   2 The blade is too dull.
   3 Out of fuel.
+"###,
+        );
+    }
+
+    #[allow(dead_code)]
+    #[derive(argh::FromArgs)]
+    /// Destroy the contents of <file>.
+    struct WithArgName {
+        #[argh(positional, arg_name = "name")]
+        username: String,
+    }
+
+    #[test]
+    fn with_arg_name() {
+        assert_help_string::<WithArgName>(
+            r###"Usage: test_arg_0 <name>
+
+Destroy the contents of <file>.
+
+Options:
+  --help            display usage information
 "###,
         );
     }