Support label with @Option

- Add `label` field into `@Option`. This sets option label if
  `label` field has any text.
- Fixes #732
This commit is contained in:
Janne Valkealahti
2023-05-01 17:11:03 +01:00
parent 755cf66350
commit a0ad3ad797
5 changed files with 57 additions and 11 deletions

View File

@@ -7,15 +7,21 @@ what a default `help` command outputs. Within a command documentation
a type of an option is documented but this is not always super useful. Thus
you may want to give better descriptive word for an option.
====
[source, java, indent=0]
NOTE: Label is not supported with `legacy annotation`.
[source,java,indent=0,role="primary"]
.Programmatic
----
include::{snippets}/OptionSnippets.java[tag=option-registration-label]
include::{snippets}/OptionSnippets.java[tag=option-label-programmatic]
----
[source,java,indent=0,role="secondary"]
.Annotation
----
include::{snippets}/OptionSnippets.java[tag=option-label-annotation]
----
====
Defining label is then shown in `help`.
====
[source, bash]
----

View File

@@ -372,6 +372,13 @@ public class OptionSnippets {
}
// end::option-default-annotation[]
// tag::option-label-annotation[]
void labelOption(
@Option(label = "MYLABEL") String arg
) {
}
// end::option-label-annotation[]
}
static class Registration {
@@ -436,5 +443,15 @@ public class OptionSnippets {
}
// end::option-default-programmatic[]
// tag::option-label-programmatic[]
CommandRegistration labelOption() {
return CommandRegistration.builder()
.withOption()
.longNames("arg")
.label("MYLABEL")
.and()
.build();
}
// end::option-label-programmatic[]
}
}