diff --git a/src/include/pcp/pmapi.h b/src/include/pcp/pmapi.h index bd6c565..cdae0a3 100644 --- a/src/include/pcp/pmapi.h +++ b/src/include/pcp/pmapi.h @@ -608,6 +608,7 @@ extern char *pmGetConfig(const char *); #define PMAPI_OPTIONS "A:a:D:gh:n:O:p:S:s:T:t:VZ:z?" #define PMAPI_OPTIONS_HEADER(s) { "", 0, '-', 0, (s) } +#define PMAPI_OPTIONS_TEXT(s) { "", 0, '+', 0, (s) } #define PMAPI_OPTIONS_END { NULL, 0, 0, 0, NULL } #define PMOPT_ALIGN { "align", 1, 'A', "TIME", \ diff --git a/src/libpcp/src/getopt.c b/src/libpcp/src/getopt.c index 5f9d37b..032cdd9 100644 --- a/src/libpcp/src/getopt.c +++ b/src/libpcp/src/getopt.c @@ -759,6 +759,10 @@ pmUsageMessage(pmOptions *opts) pmprintf("\n%s:\n", option->message); continue; } + if (option->short_opt == '+') { /* descriptive text */ + pmprintf("%s\n", option->message); + continue; + } message = option->argname ? option->argname : "?"; if (option->long_opt && option->long_opt[0] != '\0') { diff --git a/src/python/pcp/pmapi.py b/src/python/pcp/pmapi.py index cd10988..42954b5 100644 --- a/src/python/pcp/pmapi.py +++ b/src/python/pcp/pmapi.py @@ -750,6 +750,10 @@ class pmOptions(object): """ Add a new section heading into the long option usage message """ return c_api.pmSetLongOptionHeader(heading) + def pmSetLongOptionDescription(self, text): + """ Add some descriptive text into the long option usage message """ + return c_api.pmSetLongOptionDescription(text) + def pmSetLongOptionAlign(self): """ Add support for -A/--align into PMAPI monitor tool """ return c_api.pmSetLongOptionAlign() diff --git a/src/python/pmapi.c b/src/python/pmapi.c index 5bc9f5f..74847ed 100644 --- a/src/python/pmapi.c +++ b/src/python/pmapi.c @@ -201,6 +201,27 @@ setLongOptionHeader(PyObject *self, PyObject *args, PyObject *keywords) } static PyObject * +setLongOptionDescription(PyObject *self, PyObject *args, PyObject *keywords) +{ + pmLongOptions text = PMAPI_OPTIONS_DESCRIPTION(""); + char *keyword_list[] = {"text", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, keywords, + "s:pmSetLongOptionDescription", keyword_list, + &text.message)) + return NULL; + if ((text.message = strdup(text.message)) == NULL) + return PyErr_NoMemory(); + + if (addLongOption(&text, 0) < 0) { + free((char *)text.message); + return PyErr_NoMemory(); + } + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * addLongOptionObject(pmLongOptions *option) { if (addLongOption(option, 1) < 0) @@ -873,6 +894,9 @@ static PyMethodDef methods[] = { { .ml_name = "pmSetLongOptionHeader", .ml_meth = (PyCFunction) setLongOptionHeader, .ml_flags = METH_VARARGS | METH_KEYWORDS }, + { .ml_name = "pmSetLongOptionDescription", + .ml_meth = (PyCFunction) setLongOptionDescription, + .ml_flags = METH_VARARGS | METH_KEYWORDS }, { .ml_name = "pmSetLongOption", .ml_meth = (PyCFunction) setLongOption, .ml_flags = METH_VARARGS | METH_KEYWORDS },