orhun / rustypaste-cli

A CLI tool for rustypaste
https://github.com/orhun/rustypaste
MIT License
56 stars 8 forks source link

feat(cli): add `-l` flag for retrieving file list from server #45

Closed tessus closed 1 year ago

tessus commented 1 year ago

rpaste -l

[{"file_name":".foo.BjOZ.txt","file_size":5,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":".foo.pJXC.bar","file_size":9,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":".foo.tFAL.bar.txt","file_size":13,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":"foo.rZZE.txt","file_size":4,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":"foo.78ZI.bar","file_size":8,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":"foo.J8VG.bar.txt","file_size":12,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":".foo.WOWM.txt","file_size":5,"expires_at_utc":"2023-08-07 21:58:18"},{"file_name":".foo.0pgN.bar","file_size":9,"expires_at_utc":"2023-08-07 21:58:18"},{"file_name":".foo.gQLo.bar.txt","file_size":13,"expires_at_utc":"2023-08-07 21:58:18"},{"file_name":"foo.Gl8n.txt","file_size":4,"expires_at_utc":"2023-08-07 21:58:19"},{"file_name":"foo.F2cf.bar","file_size":8,"expires_at_utc":"2023-08-07 21:58:19"},{"file_name":"foo.LCQZ.bar.txt","file_size":12,"expires_at_utc":"2023-08-07 21:58:20"}]

rpaste -lp

      Name        | Size |    Expiry (UTC)
------------------|------|--------------------
.foo.BjOZ.txt     |    5 | 2023-08-07 21:58:17
.foo.pJXC.bar     |    9 | 2023-08-07 21:58:17
.foo.tFAL.bar.txt |   13 | 2023-08-07 21:58:17
foo.rZZE.txt      |    4 | 2023-08-07 21:58:17
foo.78ZI.bar      |    8 | 2023-08-07 21:58:17
foo.J8VG.bar.txt  |   12 | 2023-08-07 21:58:17
.foo.WOWM.txt     |    5 | 2023-08-07 21:58:18
.foo.0pgN.bar     |    9 | 2023-08-07 21:58:18
.foo.gQLo.bar.txt |   13 | 2023-08-07 21:58:18
foo.Gl8n.txt      |    4 | 2023-08-07 21:58:19
foo.F2cf.bar      |    8 | 2023-08-07 21:58:19
foo.LCQZ.bar.txt  |   12 | 2023-08-07 21:58:20
tessus commented 1 year ago

-l or --list will return the JSON as-is now.

The table is shown with -p or --pretty.

tessus commented 1 year ago

rpaste -l

[{"file_name":".foo.BjOZ.txt","file_size":5,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":".foo.pJXC.bar","file_size":9,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":".foo.tFAL.bar.txt","file_size":13,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":"foo.rZZE.txt","file_size":4,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":"foo.78ZI.bar","file_size":8,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":"foo.J8VG.bar.txt","file_size":12,"expires_at_utc":"2023-08-07 21:58:17"},{"file_name":".foo.WOWM.txt","file_size":5,"expires_at_utc":"2023-08-07 21:58:18"},{"file_name":".foo.0pgN.bar","file_size":9,"expires_at_utc":"2023-08-07 21:58:18"},{"file_name":".foo.gQLo.bar.txt","file_size":13,"expires_at_utc":"2023-08-07 21:58:18"},{"file_name":"foo.Gl8n.txt","file_size":4,"expires_at_utc":"2023-08-07 21:58:19"},{"file_name":"foo.F2cf.bar","file_size":8,"expires_at_utc":"2023-08-07 21:58:19"},{"file_name":"foo.LCQZ.bar.txt","file_size":12,"expires_at_utc":"2023-08-07 21:58:20"}]

rpaste -lp

      Name        | Size |    Expiry (UTC)
------------------|------|--------------------
.foo.BjOZ.txt     |    5 | 2023-08-07 21:58:17
.foo.pJXC.bar     |    9 | 2023-08-07 21:58:17
.foo.tFAL.bar.txt |   13 | 2023-08-07 21:58:17
foo.rZZE.txt      |    4 | 2023-08-07 21:58:17
foo.78ZI.bar      |    8 | 2023-08-07 21:58:17
foo.J8VG.bar.txt  |   12 | 2023-08-07 21:58:17
.foo.WOWM.txt     |    5 | 2023-08-07 21:58:18
.foo.0pgN.bar     |    9 | 2023-08-07 21:58:18
.foo.gQLo.bar.txt |   13 | 2023-08-07 21:58:18
foo.Gl8n.txt      |    4 | 2023-08-07 21:58:19
foo.F2cf.bar      |    8 | 2023-08-07 21:58:19
foo.LCQZ.bar.txt  |   12 | 2023-08-07 21:58:20
orhun commented 1 year ago

I refactored the implementation in 6d9398fff330d4af93c9d5b0c54b5095b90f7aeb, can you verify the behavior is the same?

tessus commented 1 year ago

Nope, but that was to be expected. You removed 2 critical parts in the code.

if result set empty (no files on server)

$ rpaste -lp
Name | Size |    Expiry (UTC)
-|---|--------------------

biggest file smaller than 1000 bytes

$ rpaste -lp
      Name        | Size |    Expiry (UTC)
------------------|----|--------------------
.foo.yZgw.txt     |  5 | 2023-08-11 16:01:57
.foo.oyQ9.bar     |  9 | 2023-08-11 16:01:57
.foo.n9UH.bar.txt | 13 | 2023-08-11 16:01:57
foo.zBnH.txt      |  4 | 2023-08-11 16:01:57
foo.ZgDY.bar      |  8 | 2023-08-11 16:01:57
foo.DJ7n.bar.txt  | 12 | 2023-08-11 16:01:57
.foo.Alac.txt     |  5 | 2023-08-11 16:01:58
.foo.LCm7.bar     |  9 | 2023-08-11 16:01:59
.foo.lWKi.bar.txt | 13 | 2023-08-11 16:01:59
foo.fQc6.txt      |  4 | 2023-08-11 16:01:59
foo.qqEA.bar      |  8 | 2023-08-11 16:02:00
foo.zCPn.bar.txt  | 12 | 2023-08-11 16:02:00

Give me a few minutes to fix this.

orhun commented 1 year ago

if result set empty (no files on server)

I think that's fine, I would rather return something rather than nothing.

biggest file smaller than 1000 bytes

What's the issue in this output? edit: ah, the header...

tessus commented 1 year ago

I think that's fine, I would rather return something rather than nothing.

In that case, wouldn't a message be nicer?

What's the issue in this output? edit: ah, the header...

It's rather the rest of the table. This is why I set the initial value to 1000 for testing the max.

tessus commented 1 year ago

Or maybe a :( at the end?

No files on server :(

similar to what the server returns: file is not found or expired :(

tessus commented 1 year ago

It's of course up to you, but I think a message looks more professional. A table header looks to me as if an edge case was forgotten.