psyinfra / onyo

text-based inventory system on top of git
ISC License
3 stars 5 forks source link

`onyo get --match` siliently discards multiple invocations #649

Open aqw opened 2 months ago

aqw commented 2 months ago

I ran an onyo get command similar to the following:

onyo get --match type=laptop --match type=desktop

The result was that --match type=laptop was silently ignored and only --match type=desktop was used.

I expected that onyo get would error, and tell me that --match can only be used once.

This may affect other option flags as well.

bpoldrack commented 1 month ago

Hm. It's not that the flag can't be used multiple times. It can. You can have multiple match criteria and specify them by either multiple expressions after --match or distribute them across multiple --match options and I think that's fine. They should normally be treated as ANDed. The bug appears to be that multiple match criteria for the same key overwrite eachother instead of being combined by AND. IOW: In my view the result of your query should not necessarily be an error but no result instead, as there is no asset that matches both criteria. And in the general case (regex) we can't easily tell that the given criteria are contradictory, which is why I'm not sold on the error. When exactly would we raise it?

So, agree it's a bug, but not so much on the solution.

aqw commented 1 month ago

Now that I've used --match more, the behavior you described is definitely the right behavior.

+1