Revision faeccbf9 kamaki/cli/commands/image.py

b/kamaki/cli/commands/image.py
83 83
            '--container-format'),
84 84
        disk_format=ValueArgument('filter by disk format', '--disk-format'),
85 85
        name=ValueArgument('filter by name', '--name'),
86
        name_pref=ValueArgument(
87
            'filter by name prefix (case insensitive)',
88
            '--name-prefix'),
89
        name_suff=ValueArgument(
90
            'filter by name suffix (case insensitive)',
91
            '--name-suffix'),
92
        name_like=ValueArgument(
93
            'print only if name contains this (case insensitive)',
94
            '--name-like'),
86 95
        size_min=IntArgument('filter by minimum size', '--size-min'),
87 96
        size_max=IntArgument('filter by maximum size', '--size-max'),
88 97
        status=ValueArgument('filter by status', '--status'),
......
109 118
                images.append(img)
110 119
        return images
111 120

  
121
    def _filtered_by_name(self, images):
122
        np, ns, nl = self['name_pref'], self['name_suff'], self['name_like']
123
        return [img for img in images if (
124
            (not np) or img['name'].lower().startswith(np.lower())) and (
125
            (not ns) or img['name'].lower().endswith(ns.lower())) and (
126
            (not nl) or nl.lower() in img['name'].lower())]
127

  
112 128
    @errors.generic.all
113 129
    @errors.cyclades.connection
114 130
    def _run(self):
......
129 145
            images = self._filtered_by_owner(detail, filters, order)
130 146
        else:
131 147
            images = self.client.list_public(detail, filters, order)
148
        images = self._filtered_by_name(images)
132 149

  
133 150
        if self['more']:
134 151
            print_items(

Also available in: Unified diff