iio_info.py example: pick uri automatically when there's only one #1159
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.
PR Description
I was testing v0.25's iio_info.py and saw it didn't do anything when no command-line arguments were given. If there are more than one available uri a message is shown before exiting the program (with
sys.exit(0)
). However, this line is also executed when there's only one or zero of them, and without printing any message previously. This causes confusion, at least in my opinion. I've seen that v1 didn't had any changes in that file, meaning that this issue still persists.For reference, the "oficial" C-programmed iio_info (the one that comes built in the releases) selects the first uri if only one exists by default.
What I've done in this PR is to mimic what it's being done in the iio_info executable. I'm not sure if the examples should change in v1, but at least it should be useful for v0.25 (this PR is on the main branch, but I can move it to the v0.25 branch if you prefer). I've also fixed a typo some lines below.
It's my first PR ever to an open-source project, so don't hesitate on giving me constructive feedback, it's all a little new to me!
Tested on v0.25, with Python3.6 and Python2.7 on a Ubuntu 18.04.
PR Type
PR Checklist
(due to the simplicity of the fix, and given the fact that it is one of the example codes I consider that some of the checks don't apply, I left them unchecked)