-
Notifications
You must be signed in to change notification settings - Fork 402
fix(available_interfaces): fix regression of unwanted trailing colons #1131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import pytest | ||
|
|
||
| from conftest import assert_bash_exec | ||
|
|
||
|
|
||
| @pytest.mark.bashcomp(cmd=None) | ||
| class TestUtilCompgenAvailableInterfaces: | ||
| @pytest.fixture | ||
| def functions(self, bash): | ||
| assert_bash_exec( | ||
| bash, | ||
| "_comp__test_dump() { ((${#arr[@]})) && printf '<%s>' \"${arr[@]}\"; echo; }", | ||
| ) | ||
| assert_bash_exec( | ||
| bash, | ||
| '_comp__test_compgen() { local -a arr=(00); _comp_compgen -v arr "$@"; _comp__test_dump; }', | ||
| ) | ||
|
|
||
| def test_1_trailing_colons(self, bash, functions): | ||
| output = assert_bash_exec( | ||
| bash, | ||
| "_comp__test_compgen available_interfaces", | ||
| want_output=True, | ||
| ) | ||
| assert ":" not in output.strip() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second thought, this is not correct, it will break display of things like br-something and lo:0 (aliases only come out from ifconfig that way it seems).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, thank you for pointing this out. @yedayak I think you can make a proper fix for that. Could you take a look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked some stuff, and it seems you can create interfaces with most punctuation in them, for example
a_b-cand an interface namedveth2@veth3. I didn't manage to create interfaces with:in them, but as @scop mentioned ifconfig can output them like that. I think the best solution will be to remove the last colon always, and maybe to useip -jsonwhen available?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although maybe interfaces with
@in them are a edge case we shouldn't care about, in which case we should strip everything from there until the endThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that mean you suggest something like
"${generated[@]%:}"?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re how to create interfaces with colons in them, e.g.
These show up in ifconfig output like
They do not show up in
ip linkoutput for me. They would show up inip addroutput, but not in a way we'd currently parse anyway.There's also
...but that does not show up in
ifconfigoutput. It does inip linkoutput, but again not in a way we'd currently parse.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest just stripping the trailing colon as well (did also in #1133).
JSON output is nice in theory, but opens the can of worms that with what would we parse the JSON with?
jq,yq, ...? Probably quite a bit of code and even more fallbacks involved, not sure if it's worth it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much, although I'm not sure I understand how it works. only thing is it still completes with
@if ifconfig isn't available. I think@and following characters should be stripped, at least whenipis being used. Maybe making a case for that is worth it?Agreed about that.