shaarli / python-shaarli-client

Python3 CLI to interact with a Shaarli instance
https://python-shaarli-client.readthedocs.io/
MIT License
44 stars 10 forks source link

get-links: excluding tags from results (using `-` operator) does not work #55

Closed nodiscc closed 2 years ago

nodiscc commented 3 years ago

https://shaarli.example.org/?searchterm=&searchtags=video+-idontwantthistag will return all links tagged video but NOT tagged idontwantthistag. Excluding tags in this way using the python client does not appear to work.

(.venv) $ shaarli get-links --searchtags video -idontwantthistag
shaarli: error: unrecognized arguments: -idontwantthistag

(.venv) $ shaarli get-links --searchtags video '-idontwantthistag'
shaarli: error: unrecognized arguments: -idontwantthistag

(.venv) $ shaarli get-links --searchtags video '\-idontwantthistag'
[]

This might be a limitation of the API (?), I have not checked using curl since I don't know exactly how to generate a JWT token to use with curl --header 'Autorization: Bearer ...

virtualtam commented 3 years ago

Hi!

It is required to pass all values to --searchtags as a quoted string:

shaarli get-links --searchtags "video -idontwantthistag"

The value passed to --searchtags must not start with a dash though, a workaround is to start the string with a space:

shaarli get-links --searchtags " -idontwantthistag -northisone"

This feels clumsy though, a solution could be to introduce an excludetags parameter to the API so we can do:

shaarli get-links --searchtags video --excludetags idontwantthistag

For clarity and consistency we could have:

@ArthurHoaro what do you think of it?

nodiscc commented 3 years ago

shaarli get-links --searchtags "video -idontwantthistag" shaarli get-links --searchtags " -idontwantthistag -northisone"

Thanks!

It is required to pass all values to --searchtags as a quoted string:

It does work without quotes (except this edge case with the minus sign), it's what confused me initially:

(.venv) $ shaarli get-links --limit 2 --searchtags video technology
# returns correct results

The value passed to --searchtags must not start with a dash though, a workaround is to start the string with a space: This feels clumsy though, a solution could be to introduce an excludetags parameter to the API

Actually your workaround looks fine to me, if we document it.

I'd rather have a consistency between API parameters, python client command line, and Shaarli URL parameters (what you suggest would mean supporting the excludetags URL parameter in Shaarli, hence an extra search field, am I right?) I think the - operator make more sense.

The fact that it does not work in first position with the python client is an unfortunate limitation of the ArgumentParser implementation. Really, I can live with it.