Revision bd40efdf

b/kamaki/cli/commands/cyclades_cli.py
37 37
from kamaki.cli.errors import raiseCLIError, CLISyntaxError
38 38
from kamaki.clients.cyclades import CycladesClient, ClientError
39 39
from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument
40
from kamaki.cli.argument import ProgressBarArgument, DateArgument
40
from kamaki.cli.argument import ProgressBarArgument, DateArgument, IntArgument
41 41
from kamaki.cli.commands import _command_init
42 42

  
43 43
from base64 import b64encode
......
609 609

  
610 610
@command(flavor_cmds)
611 611
class flavor_list(_init_cyclades):
612
    """List flavors"""
612
    """List available hardware flavors"""
613 613

  
614 614
    arguments = dict(
615
        detail=FlagArgument('show detailed output', '-l')
615
        detail=FlagArgument('show detailed output', '-l'),
616
        limit=IntArgument('limit the number of flavors to list', '-n'),
617
        more=FlagArgument(
618
            'output results in pages (-n to set items per page, defaul is 10)',
619
            '--more')
616 620
    )
617 621

  
618 622
    def main(self):
......
621 625
            flavors = self.client.list_flavors(self['detail'])
622 626
        except Exception as err:
623 627
            raiseCLIError(err)
624
        print_items(flavors, with_redundancy=self['detail'])
628
        if self['more']:
629
            print_items(
630
                flavors,
631
                with_redundancy=self['detail'],
632
                page_size=self['limit'] if self['limit'] else 10)
633
        else:
634
            print_items(
635
                flavors,
636
                with_redundancy=self['detail'],
637
                page_size=self['limit'])
625 638

  
626 639

  
627 640
@command(flavor_cmds)
b/kamaki/cli/utils.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.
33 33

  
34
from sys import stdout
34
from sys import stdout, stdin
35 35
from re import compile as regex_compile
36 36
from kamaki.cli.errors import raiseCLIError
37 37

  
......
194 194
def print_items(items,
195 195
    title=('id', 'name'),
196 196
    with_enumeration=False,
197
    with_redundancy=False):
197
    with_redundancy=False,
198
    page_size=0):
198 199
    """print dict or list items in a list, using some values as title
199 200
    Objects of next level don't inherit enumeration (default: off) or titles
200 201

  
......
202 203
    :param title: (tuple) keys to use their values as title
203 204
    :param with_enumeration: (boolean) enumerate items (order id on title)
204 205
    :param with_redundancy: (boolean) values in title also appear on body
206
    :param page_size: (int) show results in pages of page_size items, enter to
207
        continue
205 208
    """
209
    try:
210
        page_size = int(page_size) if int(page_size) > 0 else len(items)
211
    except:
212
        page_size = len(items)
213
    num_of_pages = len(items) // page_size
214
    num_of_pages += 1 if len(items) % page_size else 0
206 215
    for i, item in enumerate(items):
207 216
        if with_enumeration:
208 217
            stdout.write('%s. ' % (i + 1))
......
221 230
            print_list(item, ident=1)
222 231
        else:
223 232
            print(' %s' % item)
233
        if num_of_pages and len(items) > (i + 1) and 0 == (i + 1) % page_size:
234
            num_of_pages -= 1
235
            print('(%s listed - %s more - "enter" to continue)' % (
236
                i + 1,
237
                len(items) - (i + 1)))
238
            stdin.read(1)
224 239

  
225 240

  
226 241
def format_size(size):

Also available in: Unified diff