Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

elektraGetOptsHelpMessage docs/examples use 'opt/arg/name' instead of 'opt/arg/help' #4432

Closed
hannes99 opened this issue Aug 10, 2022 · 4 comments
Assignees

Comments

@hannes99
Copy link
Contributor

Steps to Reproduce the Problem

...
(ks, keyNew (baseKeyName "spec:/test/path", KEY_META, "description", "Some description",  \
                                            KEY_META, "opt", "p", \
                                            KEY_META, "opt/arg/name", "path", \
                                            KEY_META, "opt/long", "path", \
                                            KEY_META, "opt/arg", "required", KEY_END));  \
...
... elektraGetOpts (ks, argc, (const char **) argv, (const char **) environ, errorKey);
...
char * help = elektraGetOptsHelpMessage (errorKey, NULL, NULL);

The --help output ignores the specified opt/arg/name and always uses ARG instead.

Expected Result

OPTIONS
...
  -p path, --profile=path     Some description.
...

Actual Result

OPTIONS
...
  -p ARG, --profile=ARG       Some description.
...

@hannes99 hannes99 added the bug label Aug 10, 2022
@hannes99 hannes99 self-assigned this Aug 10, 2022
hannes99 added a commit to hannes99/libelektra that referenced this issue Aug 10, 2022
@kodebach
Copy link
Member

kodebach commented Aug 10, 2022

Could you try with opt/arg/help instead?

I think that's what is actually used. See

strncat (metaBuffer, "/arg/help", 11); // 11 = remaining space in metaBuffer
const char * argNameMeta = keyGetMetaString (key, metaBuffer);

optionData->argName = argNameMeta;

const char * argName = optionData->argName;

if (!hidden)
{
char * argString = "";
if (elektraStrCmp (hasArg, "required") == 0)
{
argString = argName == NULL ? "=ARG" : elektraFormat ("=%s", argName);
}
else if (elektraStrCmp (hasArg, "optional") == 0)
{
argString = argName == NULL ? "=[ARG]" : elektraFormat ("=[%s]", argName);
}
char * newLongOptLine = elektraFormat ("%s--%s%s, ", *longOptLine, longOpt, argString);
elektraFree (*longOptLine);
if (argName != NULL)
{
elektraFree (argString);
}
*longOptLine = newLongOptLine;
}

@hannes99
Copy link
Contributor Author

Actually, yes. I'll update the rm example in the tutorial[1], since /name is used there.

[1] https://www.libelektra.org/tutorials/command-line-options#examples

@hannes99
Copy link
Contributor Author

should I change the Issue title and description, or leave it?

@kodebach kodebach changed the title elektraGetOptsHelpMessage ignores set 'opt/arg/name' elektraGetOptsHelpMessage docs/examples use 'opt/arg/name' instead of 'opt/arg/help' Aug 10, 2022
@kodebach
Copy link
Member

I'll update the rm example in the tutorial

Please also check other docs, like examples/opts.c and examples/gopts.c

should I change the Issue title and description, or leave it?

I updated it.

hannes99 added a commit to hannes99/libelektra that referenced this issue Aug 10, 2022
markus2330 added a commit that referenced this issue Aug 17, 2022
fix #4432: opts docs: use arg/help instead of arg/name
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants