mirror of
https://github.com/beetbox/beets.git
synced 2025-12-31 13:02:47 +01:00
implemented set_field cli parsing
This commit is contained in:
parent
0148070445
commit
1da972f4bb
3 changed files with 26 additions and 1 deletions
|
|
@ -25,7 +25,8 @@ import:
|
|||
pretend: false
|
||||
search_ids: []
|
||||
duplicate_action: ask
|
||||
bell: no
|
||||
bell: no
|
||||
set_fields: {}
|
||||
|
||||
clutter: ["Thumbs.DB", ".DS_Store"]
|
||||
ignore: [".*", "*~", "System Volume Information", "lost+found"]
|
||||
|
|
|
|||
|
|
@ -1060,6 +1060,24 @@ class SubcommandsOptionParser(CommonOptionsParser):
|
|||
suboptions, subargs = subcommand.parse_args(args)
|
||||
return subcommand, suboptions, subargs
|
||||
|
||||
@staticmethod
|
||||
def _store_dict(option, opt_str, value, parser):
|
||||
"""Custom action callback to parse options which have ``key=value``
|
||||
pairs as values. All such pairs passed for this option are
|
||||
aggregated into a dictionary.
|
||||
"""
|
||||
dest = option.dest
|
||||
option_values = getattr(parser.values, dest, None)
|
||||
|
||||
if option_values is None:
|
||||
# This is the first supplied ``key=value`` pair of option.
|
||||
# Initialize empty dictionary and get a reference to it.
|
||||
setattr(parser.values, dest, dict())
|
||||
option_values = getattr(parser.values, dest)
|
||||
|
||||
key, value = value.split('=')
|
||||
option_values[key] = value
|
||||
|
||||
|
||||
optparse.Option.ALWAYS_TYPED_ACTIONS += ('callback',)
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ from beets import config
|
|||
from beets import logging
|
||||
from beets.util.confit import _package_path
|
||||
import six
|
||||
from . import SubcommandsOptionParser
|
||||
|
||||
VARIOUS_ARTISTS = u'Various Artists'
|
||||
PromptChoice = namedtuple('PromptChoice', ['short', 'long', 'callback'])
|
||||
|
|
@ -1017,6 +1018,11 @@ import_cmd.parser.add_option(
|
|||
metavar='ID',
|
||||
help=u'restrict matching to a specific metadata backend ID'
|
||||
)
|
||||
import_cmd.parser.add_option(
|
||||
u'--set-field', dest='set_fields', action='callback', callback=SubcommandsOptionParser._store_dict,
|
||||
metavar='FIELD=VALUE',
|
||||
help=u'set the given fields to the supplied values after importing'
|
||||
)
|
||||
import_cmd.func = import_func
|
||||
default_commands.append(import_cmd)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue