-
Notifications
You must be signed in to change notification settings - Fork 14
Various fixes for usages derived from the @arg annotation. #188
base: main
Are you sure you want to change the base?
Conversation
90fd1e2
to
8bd62d0
Compare
Codecov Report
@@ Coverage Diff @@
## master #188 +/- ##
==========================================
- Coverage 91.75% 91.61% -0.14%
==========================================
Files 54 54
Lines 2159 2183 +24
Branches 196 140 -56
==========================================
+ Hits 1981 2000 +19
- Misses 178 183 +5
Continue to review full report at Codecov.
|
8bd62d0
to
81db51b
Compare
3ef4582
to
768aa76
Compare
Enforce if both 'flag' and 'name' are given in the `@arg` annotation, the length of 'flag' is less than or equal to the length of 'name'. It is ok if the length of 'name' derived from the constructor-parameter/field is less than the length of 'flag', and in this cause we'll print 'flag' second. Examples: 1. `@arg(flag="abc", name="a") val a: T` should be illegal 2. `@arg(flag="abc") val a: T` will have usage "-a T, --abc=T" Previously it would not check and print the following usages for 1-2 above: 1. "-abc T, --a=T". Note that specifying either "-abc T" or "--a T" wouldn't work. 2. "-abc T, -a=T". Note that specifying "-abc T" wouldn't work. Format a single-character flag correctly if specified in name or the variable/field is a single-character. - `@arg(name="a") val abc: T` will have usage "-a T". - `@arg val a: T` will have usage "-a T". Add a regression test for the 'name' field being camel case: - `@arg(name="aB") val a: T` will have usage "--aB=T". Fix the usage for multi-character flag arguments. For example, if `@arg(flag="abc") val abcd: T` then the usage will be "--abc=T, --abcd=T"; it was previously "-abc T, --abcd=T". Make it ok for the 'flag' and derived 'name' are the same, but only print out one: `@arg(flag="a") val a: T` will be "-a T". Updated the documentation for ArgAnnotation for all the above.
768aa76
to
9ec712d
Compare
Can we talk a little bit about the desired behaviour here? I read through your comment and some of the tests to make sure I understood, and I think I now do. There are a few things that I'm not sure about:
Mostly I would just like the end result to be that there's a very simple and intuitive transformation between what you right in a class and what the command line expects, and this adds a lot of extra rules like if the flag is multi-character, if the flag is longer than the field name, etc. that are not so intuitive to anyone else. |
I think the solution we can agree upon is making Next, I think I want a short name (or alternate name) in addition to a single character than flag, since I may want to be able to use |
@nh13 I think your last suggestion is good. Move flag to be |
The fixes are described in the second commit message pasted here:
Various fixes for usages derived from the
@arg
annotation.Enforce if both 'flag' and 'name' are given in the
@arg
annotation, thelength of 'flag' is less than or equal to the length of 'name'. It is ok
if the length of 'name' derived from the constructor-parameter/field is
less than the length of 'flag', and in this cause we'll print 'flag'
second. Examples:
@arg(flag="abc", name="a") val a: T
should be illegal@arg(flag="abc") val a: T
will have usage "-a T, --abc=T"Previously it would not check and print the following usages for 1-2
above:
wouldn't work.
Format a single-character flag correctly if specified in name or the
variable/field is a single-character.
@arg(name="a") val abc: T
will have usage "-a T".@arg val a: T
will have usage "-a T".Add a regression test for the 'name' field being camel case:
@arg(name="aB") val a: T
will have usage "--aB=T".Fix the usage for multi-character flag arguments. For example, if
@arg(flag="abc") val abcd: T
then the usage will be"--abc=T, --abcd=T"; it was previously "-abc T, --abcd=T".
Make it ok for the 'flag' and derived 'name' are the same, but only
print out one:
@arg(flag="a") val a: T
will be "-a T".Updated the documentation for ArgAnnotation for all the above.