'Add -f/--format option to print some LibModel instances with a
custom format.
`target` is optional and can be one of ``library.Item``, \'item\',
``library.Album`` and \'album\'.
Several behaviors are available:
- if `target` is given then the format is only applied to that
LibModel
- if the album option is used then the target will be autodetected
- otherwise the format is applied to both items and albums.
Sets the format property on the options extracted from the CLI.'

def add_format_option(self, flags=('-f', '--format'), target=None):

    kwargs = {}
    if target:
        if isinstance(target, six.string_types):
            target = {'item': library.Item, 'album': library.Album}[target]
        kwargs['target'] = target
    opt = optparse.Option(action='callback', callback=self._set_format, callback_kwargs=kwargs, help=u'print    with    custom    format', *flags)
    self.add_option(opt)
