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

put-link should update only specified fields instead of overwriting all fields #34

Open mfioretti opened 6 years ago

mfioretti commented 6 years ago

The Usage section of the documentation says that "put-link" "Updates an existing link or note". This is not true. What it does is to transform a link into a private note with a different title. Even the example ("shaarli put-link --private 3252") in the documentation itself shows this.

Also, the inline help says:

(shaarli) [root@fima-01-hetzner ~]# shaarli -c /root/scripts/shaarli.conf   put-link --help
usage: shaarli put-link [-h] [--description DESCRIPTION [DESCRIPTION ...]]
                        [--private] [--tags TAGS [TAGS ...]]
                        [--title TITLE [TITLE ...]] [--url URL]
                        resource

positional arguments:
  resource              Link ID

optional arguments:
  -h, --help            show this help message and exit
  --description DESCRIPTION [DESCRIPTION ...]
                        Link description
  --private             Link visibility
  --tags TAGS [TAGS ...]
                        List of tags associated with the link
  --title TITLE [TITLE ...]
                        Link title
  --url URL             Link URL

but if add and then I try to update a link, it gets changed title, and URL, just like in the docs. But why should they change, if one only sets status to private?:

(shaarli) [marco ~]# shaarli -c shaarli.conf  post-link --url https://www.linux.com --tags "freeSoftware testing" --description "go penguins" --title 'A nice operating system'
{
    "created": "2018-09-04T18:54:08+02:00",
    "description": "go penguins",
    "id": 4,
    "private": false,
    "shorturl": "Gxqflg",
    "tags": [
        "freeSoftware",
        "testing"
    ],
    "title": "A nice operating system",
    "updated": "",
    "url": "https://www.linux.com"
}
(shaarli) [marco ~]# shaarli -c shaarli.conf  put-link --private 4
{
    "created": "2018-09-04T18:54:08+02:00",
    "description": "",
    "id": 4,
    "private": true,
    "shorturl": "Gxqflg",
    "tags": [],
    "title": "?Gxqflg",
    "updated": "2018-09-04T18:54:36+02:00",
    "url": "https://localhost/?Gxqflg"

Besides: "put-link --private true 2" , or e.g "put-link --title 'new title' does not work at all:

(shaarli) [marco ~]# shaarli -c shaarli.conf  put-link --private true 4
usage: shaarli put-link [-h] [--description DESCRIPTION [DESCRIPTION ...]]
                        [--private] [--tags TAGS [TAGS ...]]
                        [--title TITLE [TITLE ...]] [--url URL]
                        resource
shaarli put-link: error: argument resource: true is not a positive integer
(shaarli) [marco ~]# shaarli -c shaarli.conf  put-link --title 'A new title' 4
usage: shaarli put-link [-h] [--description DESCRIPTION [DESCRIPTION ...]]
                        [--private] [--tags TAGS [TAGS ...]]
                        [--title TITLE [TITLE ...]] [--url URL]
                        resource
shaarli put-link: error: argument resource: A new title is not a positive integer
virtualtam commented 6 years ago

Hi @mfioretti,

As we've haven't had much feedback on the REST API, there are some rough edges remaining on both the API itself, as well as the provided Python client.

From the API documentation for the PUT link endpoint:

Update an existing link with provided request data. Keep in mind that all link’s fields will be updated.

Which is indeed not ideal as it does not allow for atomic operations on relevant fields.

Besides: "put-link --private true 2" , or e.g "put-link --title 'new title' does not work at all:

--private sets the link visibility flag, and does not expect a boolean argument, e.g.:

mfioretti commented 6 years ago

Hello @virtualtam .

I had NOT understood how the --private switch needs to be used, my bad!

As for the other issues... if every time I have to update a bookmark I have to pass to shaarli-client ALL its fields, even if only one changed, that is not ideal, but no big deal either, really. In my tests here, however, I noticed that sometimes shaarli-client did not return anything at all on STDOUT, even when it had succceeded. It should return the full json record of the updated bookmark, right? And when it returns nothing, can it be the memory issues of the php application mentioned at https://github.com/shaarli/Shaarli/issues/1223, or should be worry about something else?

Thanks

ArthurHoaro commented 6 years ago

Which is indeed not ideal as it does not allow for atomic operations on relevant fields.

I think that would be a PATCH request. It can be added if it's needed.

@mfioretti I'm not really familiar with this client, but if the PHP API exhausts its memory, you will find an error in the PHP/webserver logs.