when many products are found, ask user to select one

This commit is contained in:
Romain Bignon 2012-05-04 20:48:33 +02:00
commit b37c2160b5

View file

@ -94,14 +94,22 @@ class Comparoob(ReplApplication):
for backend, product in self.do('search_products', pattern):
products.append(product)
product = None
if len(products) == 0:
print >>sys.stderr, 'Error: no product found with this pattern'
return 1
elif len(products) == 1:
product = products[0]
else:
print >>sys.stderr, 'Error: too many results, TODO'
return 1
print 'What product do you want to compare?'
for i, product in enumerate(products):
print ' %s%2d)%s %s' % (self.BOLD, i+1, self.NC, product.name)
r = int(self.ask(' Select a product', regexp='\d+'))
while product is None:
if r <= 0 or r > len(products):
print 'Error: Please enter a valid ID'
continue
product = products[r-1]
self.change_path([u'prices'])
self.start_format()