Commit c8aea55a authored by luz's avatar luz

p44utils: CmdLineApp::showUsage() now word-wraps description texts to...

p44utils: CmdLineApp::showUsage() now word-wraps description texts to MAX_LINELEN (100 for now) chars
parent 50416585
......@@ -259,7 +259,7 @@ public:
{ 'b', "enocean", true, "bridge;EnOcean modem serial port device or proxy host[:port]" },
{ 0, "enoceanreset", true, "pinspec;set I/O pin connected to EnOcean module reset" },
{ 0, "huelights", false, "enable support for hue LED lamps (via hue bridge)" },
{ 0, "hueapiurl", true, "hue API url; use hue bridge API at specific location (disables UPnP/SSDP search)" },
{ 0, "hueapiurl", true, "hue API url;use hue bridge API at specific location (disables UPnP/SSDP search)" },
#if !DISABLE_OLA
{ 0, "ola", false, "enable support for OLA (Open Lighting Architecture) server" },
#endif
......@@ -279,21 +279,21 @@ public:
{ 0 , "sparkcore", true, "sparkCoreID:authToken;add spark core based cloud device" },
{ 'g', "digitalio", true, "iospec:[!](button|light|relay);add static digital input or output device\n"
"Use ! for inverted polarity (default is noninverted input)\n"
"iospec is of form [bus.[device.]]pin:\n"
"- gpio.gpionumber : generic Linux GPIO\n"
#if !DISABLE_I2C
"- i2cN.DEVICE@i2caddr.pinNumber : numbered pin of device at i2caddr on i2c bus N\n"
" (supported for DEVICE : TCA9555, PCF8574)"
#endif
"iospec is of form [bus.[device.]]pin:"
"\n- gpio.gpionumber : generic Linux GPIO"
// #if !DISABLE_I2C
"\n- i2cN.DEVICE@i2caddr.pinNumber : numbered pin of device at i2caddr on i2c bus N "
"(supported for DEVICE : TCA9555, PCF8574)"
// #endif
},
{ 0 , "analogio", true, "iospec:(dimmer|rgbdimmer|valve);add static analog input or output device\n"
"iospec is of form [bus.[device.]]pin:\n"
"iospec is of form [bus.[device.]]pin:"
#if !DISABLE_I2C
"- i2cN.DEVICE@i2caddr.pinNumber : numbered pin of device at i2caddr on i2c bus N\n"
" (supported for DEVICE : PCA9685)"
"\n- i2cN.DEVICE@i2caddr.pinNumber : numbered pin of device at i2caddr on i2c bus N "
"(supported for DEVICE : PCA9685)"
#endif
},
{ 'k', "consoleio", true, "name[:(dimmer|button|valve)];add static debug device which reads and writes console\n"
{ 'k', "consoleio", true, "name[:(dimmer|button|valve)];add static debug device which reads and writes console "
"(for inputs: first char of name=action key)" },
{ 0 , "greenled", true, "pinspec;set I/O pin connected to green part of status LED" },
{ 0 , "redled", true, "pinspec;set I/O pin connected to red part of status LED" },
......
......@@ -201,6 +201,7 @@ void CmdLineApp::setCommandDescriptors(const char *aSynopsis, const CmdLineOptio
#define MAX_INDENT 40
#define MAX_LINELEN 100
void CmdLineApp::showUsage()
{
......@@ -242,6 +243,7 @@ void CmdLineApp::showUsage()
fprintf(stderr, "Options:\n");
optionDescP = optionDescriptors;
while (optionDescP && (optionDescP->longOptionName!=NULL || optionDescP->shortOptionChar!='\x00')) {
// fprintf(stderr, "\n");
const char *desc = optionDescP->optionDescription;
if (desc) {
ssize_t remaining = indent;
......@@ -284,20 +286,52 @@ void CmdLineApp::showUsage()
while (remaining-- > 0) fprintf(stderr, " ");
else
fprintf(stderr, " "); // just two spaces
// print option description, properly indented
// print option description, properly indented and word-wrapped
if (desc) {
ssize_t ll = MAX_LINELEN-indent;
ssize_t listindent = 0;
while (*desc) {
if (*desc=='\n') {
// next line
ssize_t l = 0;
ssize_t lastWs = -1;
// scan for list indent
if (*desc=='-') {
// next non-space is list indent
while (desc[++listindent]==' ');
}
// scan for end of text, last space or line end
const char *e = desc;
while (*e) {
if (*e==' ') lastWs = l;
else if (*e=='\n') {
// explicit line break
listindent = 0;
break;
}
// check line lenght
l++;
if (l>=ll) {
// line gets too long, break at previous space
if (lastWs>0) {
// reposition end
e = desc+lastWs;
}
break;
}
// next
e++;
}
// e now points to either LF, or breaking space, or NUL (end of text)
// - output chars between desc and e
while (desc<e) fprintf(stderr, "%c", *desc++);
// - if not end of text, insert line break and new indent
if (*desc) {
// there is a next line
fprintf(stderr, "\n");
// indent
remaining = indent;
remaining = indent+listindent;
while (remaining-- > 0) fprintf(stderr, " ");
desc++; // skip the LF or space that caused the line end
}
else {
fprintf(stderr, "%c", *desc);
}
desc++;
}
}
// end of option, next line
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment