spf13/hugo — pull request #435 by mohae (2014-08-23 21:18:18+00:00)
Title: added functionality to check the error message returned from Cobra, if a...

...ny. for uage message text. If its present, the usage message gets truncated and the resulting message is returned to be used for the rest of the error message. If the resulting error is blank, no error message is printed

This resolves issue 374, though it may not handle it in the best manner.

## Issue Summary
Duplicate usage message were being printed out when invalid flags were being passed to Hugo. Cobra would print out the command usage message for Hugo and return an error, with the usage message embedded in the error.

Because Hugo handles this as a CRITICAL error, it gets surfaced to std out, which results in the usage message being printed the second time.

## Solution:
If Cobra returns an error, the error message text is checked for the 'Usage for' string, which is the beginning of the usage text. If it exists in the error message, a split is done on that point and the 2nd element of the slice, which contains the usage message is discarded. The first slice element is trimmed of its Unicode spaces and returned.

If the returned string is not empty, not "", Hugo handles the resulting error message by issueing a CRITICAL log message. If the returned string is empty, no error message is logged as a log message of 'CRITICAL' with no additional message is not useful.

Tests were added to test the various split scenarios.