Skip to content

Commit

Permalink
Merge pull request #46 from python-cmd2/select_index
Browse files Browse the repository at this point in the history
Deal with select index out of range.
  • Loading branch information
tleonhardt committed Feb 16, 2017
2 parents 49059cb + 1f539c5 commit fa4120d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,8 +1195,9 @@ def select(self, options, prompt='Your choice? '):
response = int(response)
result = fulloptions[response - 1][0]
break
except ValueError:
pass # loop and ask again
except (ValueError, IndexError):
self.stdout.write("{!r} isn't a valid choice. Pick a number between 1 and {}:\n".format(response,
len(fulloptions)))
return result

@options([make_option('-l', '--long', action="store_true", help="describe function of parameter")])
Expand Down

0 comments on commit fa4120d

Please sign in to comment.