boolean shortOption = finalToken.matches("^-[^\\-]+$")
&& (finalToken.length() > 1);
finalToken = finalToken.replaceFirst("^[-]+", "");
for (Entry<OptionMetadata, Object> entry : valueMap.entrySet())
{
OptionMetadata option = entry.getKey();
if (entry.getValue() == null)
{
tailOptionValued = false;
}
if (((option.getShortName().equals(finalToken) && shortOption) || option.getName().equals(
finalToken)))
{
state.setOption(option);
}
}
if (tailOptionValued)
{
for (OptionMetadata option : options)
{
if (option.isNamed())
{
if (((option.getShortName().equals(finalToken) && shortOption) || option.getName().equals(
finalToken)) && valueMap.containsKey(option))
{
if (!state.isFinalTokenComplete())
{
results.add(" ");
}
break;
}
if (option.getName().startsWith(finalToken) && !valueMap.containsKey(option))
{
results.add("--" + option.getName() + " ");
}
}
}
}
if (!results.isEmpty())
{
tokens.remove();
}
/*
* If we haven't gotten any suggestions yet, then we just need to add everything we haven't seen yet. First
* time - just the required options.
*/
if (results.isEmpty() && tailOptionValued)
{
for (OptionMetadata option : options)
{
if (option.isNamed() && !valueMap.containsKey(option))
{
if (option.isRequired() || state.isDuplicateBuffer())
results.add("--" + option.getName() + " ");
}
}
}
}