Skip to content

Commit aeb68ca

Browse files
committed
Moved _store_dict.
1 parent bdb250a commit aeb68ca

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

beets/ui/__init__.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,32 +1114,6 @@ def show_model_changes(
11141114
# Helper functions for option parsing.
11151115

11161116

1117-
def _store_dict(option, opt_str, value, parser):
1118-
"""Custom action callback to parse options which have ``key=value``
1119-
pairs as values. All such pairs passed for this option are
1120-
aggregated into a dictionary.
1121-
"""
1122-
dest = option.dest
1123-
option_values = getattr(parser.values, dest, None)
1124-
1125-
if option_values is None:
1126-
# This is the first supplied ``key=value`` pair of option.
1127-
# Initialize empty dictionary and get a reference to it.
1128-
setattr(parser.values, dest, {})
1129-
option_values = getattr(parser.values, dest)
1130-
1131-
try:
1132-
key, value = value.split("=", 1)
1133-
if not (key and value):
1134-
raise ValueError
1135-
except ValueError:
1136-
raise UserError(
1137-
f"supplied argument `{value}' is not of the form `key=value'"
1138-
)
1139-
1140-
option_values[key] = value
1141-
1142-
11431117
class CommonOptionsParser(optparse.OptionParser):
11441118
"""Offers a simple way to add common formatting options.
11451119

beets/ui/commands/import_/__init__.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,32 @@ def import_func(lib, opts, args: list[str]):
131131
import_files(lib, byte_paths, query)
132132

133133

134+
def _store_dict(option, opt_str, value, parser):
135+
"""Custom action callback to parse options which have ``key=value``
136+
pairs as values. All such pairs passed for this option are
137+
aggregated into a dictionary.
138+
"""
139+
dest = option.dest
140+
option_values = getattr(parser.values, dest, None)
141+
142+
if option_values is None:
143+
# This is the first supplied ``key=value`` pair of option.
144+
# Initialize empty dictionary and get a reference to it.
145+
setattr(parser.values, dest, {})
146+
option_values = getattr(parser.values, dest)
147+
148+
try:
149+
key, value = value.split("=", 1)
150+
if not (key and value):
151+
raise ValueError
152+
except ValueError:
153+
raise ui.UserError(
154+
f"supplied argument `{value}' is not of the form `key=value'"
155+
)
156+
157+
option_values[key] = value
158+
159+
134160
import_cmd = ui.Subcommand(
135161
"import", help="import new music", aliases=("imp", "im")
136162
)
@@ -308,7 +334,7 @@ def import_func(lib, opts, args: list[str]):
308334
"--set",
309335
dest="set_fields",
310336
action="callback",
311-
callback=ui._store_dict,
337+
callback=_store_dict,
312338
metavar="FIELD=VALUE",
313339
help="set the given fields to the supplied values",
314340
)

0 commit comments

Comments
 (0)