Query command with head/tail.
(lib, opts, args)
| 29 | |
| 30 | |
| 31 | def lslimit(lib, opts, args): |
| 32 | """Query command with head/tail.""" |
| 33 | |
| 34 | if (opts.head is not None) and (opts.tail is not None): |
| 35 | raise ValueError("Only use one of --head and --tail") |
| 36 | if (opts.head or opts.tail or 0) < 0: |
| 37 | raise ValueError("Limit value must be non-negative") |
| 38 | |
| 39 | if opts.album: |
| 40 | objs = lib.albums(args) |
| 41 | else: |
| 42 | objs = lib.items(args) |
| 43 | |
| 44 | if opts.head is not None: |
| 45 | objs = islice(objs, opts.head) |
| 46 | elif opts.tail is not None: |
| 47 | objs = deque(objs, opts.tail) |
| 48 | |
| 49 | for obj in objs: |
| 50 | print_(format(obj)) |
| 51 | |
| 52 | |
| 53 | lslimit_cmd = Subcommand("lslimit", help="query with optional head or tail") |