~callum/barszcz

ba0f2277329e07d4c84157e14b85c498a9ca1357 — Callum Brown 1 year, 9 months ago cb06c5a
Fix value not associated with key in more command

When using 'more' on an attribute the query would be like:
```
artist:John Rock
```
Which would list items which match `artist:John` and `Rock`.
Using quote marks to encapsulate the value also causes problems:
```
title:'Don't Mess With Mister "T"'
```
is invalid because of the unmatched quotation marks, and beets doesn't
deal with escaping (leaving that to the shell).

But what the shell does is pass a list of arguments, so beets supports taking
the query as a list like `['key:value', 'key2:value2']`. Problem solved.

Apart from now displaying the query in the summary takes a little more work.

Fixes: https://todo.sr.ht/~callum/barszcz/35
1 files changed, 11 insertions(+), 2 deletions(-)

M beetsplug/barszcz.py
M beetsplug/barszcz.py => beetsplug/barszcz.py +11 -2
@@ 445,7 445,13 @@ class Barszcz:
        if query:
            # Query could be blank/empty
            summary_lines[0] += " matched by query:"
            summary_lines.append(query)
            if isinstance(query, str):
                summary_lines.append(query)
            elif isinstance(query, list):
                # A query list of length one is used by the `more` command for
                # `AttributeThings`. In this case, print the list minus the
                # square brackets.
                summary_lines.append(str(query)[1:-1])
        summary = HeadingThing(summary_lines)

        things = [summary] + album_things + item_things


@@ 481,7 487,10 @@ class Barszcz:
                *self.group_dimensions,
            )
        elif isinstance(thing, AttributeThing):
            return self.ls(f"{thing.key}:{thing.value}")
            # Use a list query to ensure the value is associated with the key
            # (not any other fields), and to avoid problems with escaping of
            # quote marks.
            return self.ls([f"{thing.key}:{thing.value}"])

    def do_command(self, command):
        """"Attempts to parse a command string and execute it.