File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
main/java/org/springframework/shell/core
command/annotation/support
test/java/org/springframework/shell/core Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,16 @@ public Command getObject() {
8282 description = description .isEmpty () ? "N/A" : description ;
8383 String help = command .help ();
8484 String group = command .group ();
85- group = group .isEmpty () ? this .method .getDeclaringClass ().getSimpleName () + " Commands" : group ;
85+ if (group .isEmpty ()) {
86+ String simpleName = Utils .splitCamelCase (this .method .getDeclaringClass ().getSimpleName ());
87+ if (!simpleName .endsWith (" Commands" )) {
88+ group = simpleName + " Commands" ;
89+ }
90+ else {
91+ group = simpleName ;
92+ }
93+
94+ }
8695 boolean hidden = command .hidden ();
8796 String [] aliases = command .alias ();
8897 String availabilityProviderBeanName = command .availabilityProvider ();
Original file line number Diff line number Diff line change 3030import org .springframework .shell .core .command .CommandRegistry ;
3131import org .springframework .shell .core .command .ExitStatus ;
3232import org .springframework .util .Assert ;
33+ import org .springframework .util .StringUtils ;
3334
3435/**
3536 * Some text utilities.
3940 */
4041public class Utils {
4142
43+ /**
44+ * Split a CamelCase class name into separate words. Used to derive command group
45+ * names. For example, "MyCommands" becomes "My Commands".
46+ * @param className the simple class name
47+ * @return the split string
48+ */
49+ public static String splitCamelCase (String className ) {
50+ String [] tokens = className .split ("(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])" );
51+ return StringUtils .arrayToDelimitedString (tokens , " " );
52+ }
53+
4254 /**
4355 * Turn CamelCaseText into gnu-style-lowercase.
4456 */
Original file line number Diff line number Diff line change 3333 */
3434class UtilsTests {
3535
36+ @ Test
37+ void testSplitCamelCase () {
38+ assertThat (Utils .splitCamelCase ("MyCommands" )).isEqualTo ("My Commands" );
39+ assertThat (Utils .splitCamelCase ("MyAppCommands" )).isEqualTo ("My App Commands" );
40+ }
41+
3642 @ Test
3743 public void testUnCamelify () throws Exception {
3844 assertThat (Utils .unCamelify ("HelloWorld" )).isEqualTo ("hello-world" );
You can’t perform that action at this time.
0 commit comments