Skip to content

Don't tab complete to parameters on other nodes#26

Open
kivkiv12345 wants to merge 3 commits intomasterfrom
prevent_misleading_param_completion
Open

Don't tab complete to parameters on other nodes#26
kivkiv12345 wants to merge 3 commits intomasterfrom
prevent_misleading_param_completion

Conversation

@kivkiv12345
Copy link
Contributor

Also inform the user when they haven't downloaded any parameters from the specified node

Also inform the user when they haven't downloaded any parameters from the specified node
Copy link
Contributor

@fadeto404 fadeto404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I like all improvements to auto completion! :D
A nice addition would be to print all parameters on the node if auto completing without a token (e.g. "get "/"get -n 130 ").
A passing thought is that you might have been able to save yourself some trouble by scanning the token for " -n %d" instead of rebuilding the arguments, but maybe this is more robust.


if (skip_prefix == NULL) {
fprintf(stderr, "%s() does not support the line/command: '%s'", __func__, slash->buffer);
assert(false); // Assert because this should be a compile-time error on part of the programmer, not the user.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert is a run-time thing ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't deny that. To clarify, I meant that this check should only ever fail if a compile-time change is made elsewhere in the program. So that's why this asserts, rather than returning an error.
I don't think this interpretation of asserts is exclusive to Python.

}

/* Build args */
int slash_build_args(char *args, char **argv, int *argc);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this way of declaring a function, this is not really friendly to future changes.
It would be best to add this function to a header so that we know this function is used in several places...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's a bit nasty. It seems I've misplaced my TODO on line 110-112 (inclusive).
I did consider properly exposing slash_build_args() in a header, but I would rather keep it as internal functionality for now.
The reason we use it anyway is because slash->argc and slash->argv aren't properly initialized, before the tab-completer is called. So we would ideally fix those instead. I had some trouble though, as hinted by my TODO.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, add it to a "private" header (usually, one in the "src" folder as the ones in the "include" folder are definitely public).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that slash_build_args() comes from lib/slash/, and this commit is for lib/param/, so I don't think a "private" header would be visible to us.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know what to do then... Promote "slash_build_args" to a public API in a libslash Pull Request...

#define SLASH_ARG_MAX 16 /* Maximum number of arguments */
char *argv[SLASH_ARG_MAX];
int argc = 0;
char *args = strdup(slash->buffer + strlen(skip_prefix));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a corresponding call to "free", am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. It was I, who was missing something :)
I must've simply gotten too used to attribute((cleanup())) for my own good.
I've added a corresponding free() in the newest commit (8962b67)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants