Skip to content

Commit

Permalink
FORGE-2279: Fixed shellified option name
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Oct 13, 2015
1 parent a29da5e commit 0041525
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,27 @@ public static String shellifyCommandName(String name)
*/
public static String shellifyOptionName(String name)
{
StringBuilder sb = new StringBuilder(shellifyName(name));
for (int i = 0; i < sb.length(); i++)
String shellName = shellifyName(name);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < shellName.length(); i++)
{
final char c = sb.charAt(i);
char c = shellName.charAt(i);
if (Character.isUpperCase(c))
{
sb.replace(i, i + 1, "-" + Character.toLowerCase(c));
if (i > 0)
{
char previousChar = shellName.charAt(i - 1);
char nextChar = (i + 1 < shellName.length()) ? shellName.charAt(i + 1) : '\0';
if (previousChar != '-' && (!Character.isUpperCase(previousChar) || Character.isLowerCase(nextChar)))
{
sb.append('-');
}
}
sb.append(Character.toLowerCase(c));
}
else
{
sb.append(c);
}
}
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,35 @@ public void testShellifyOptionName()
{
assertEquals("target-package", ShellUtil.shellifyOptionName("targetPackage"));
}

@Test
public void testShellifyOptionNameWithMultipleCapitalWords()
{
assertEquals("java-ee-version", ShellUtil.shellifyOptionName("javaEEVersion"));
}

@Test
public void testShellifyOptionNameMultipleWords()
{
assertEquals("ship-a-release", ShellUtil.shellifyOptionName("shipARelease"));
}

@Test
public void testShellifyOptionNameWithSingleSpace()
{
assertEquals("another-parameter", ShellUtil.shellifyOptionName("Another Parameter"));
}

@Test
public void testShellifyOptionNameWithMultipleSpaces()
{
assertEquals("java-ee-version", ShellUtil.shellifyOptionName("Java EE Version"));
}

@Test
public void testShellifyOptionNameEndingWithCapitals()
{
assertEquals("java-ee", ShellUtil.shellifyOptionName("javaEE"));
}

}

0 comments on commit 0041525

Please sign in to comment.