Skip to content

Commit

Permalink
Use proper token in command completion (fixes #31)
Browse files Browse the repository at this point in the history
  • Loading branch information
vhotspur committed Jan 13, 2024
1 parent 7840faa commit bd344d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* setup C style (via `.clang-format`) (see #51, @vhotspur)
* CI checks C style as well as file encoding and line-endings (see #51, @vhotspur)
* completion for `add` prints available devices (see #31, @vhotspur)

### Changed

Expand Down
18 changes: 14 additions & 4 deletions src/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,20 @@ static gen_t system_add_find_generator(token_t **parm, const cmd_t *cmd,
ASSERT(data != NULL);
ASSERT(*data == NULL);

uint32_t first_device_order = 0;
if ((parm_type(*parm) == tt_str)
&& (dev_type_by_partial_name(parm_str(*parm), &first_device_order))
&& (parm_last(*parm))) {
/*
* If this does not look like an add command, we bail out.
*/
if (!((parm_type(*parm) == tt_str) && (strcmp(parm_str(*parm), "add") == 0))) {
return NULL;
}

/*
* We skip the first token - "add" command name - and check that user
* supplied only one more parameter (we do not auto-complete for device
* properties).
*/
token_t *next = parm_next(parm);
if (parm_last(next)) {
return generator_devtype;
}

Expand Down

0 comments on commit bd344d6

Please # to comment.