Mydayyy / pbcli

pbcli is a command line client which allows to upload and download pastes from privatebin directly from the command line.
MIT License
11 stars 4 forks source link

add useful utility functions for `PostPasteResponse` #6

Closed nain-F49FF806 closed 6 months ago

nain-F49FF806 commented 6 months ago

Advantages:

I haven't changed the CLI output in order to keep compatibility.

But as an idea, something like the following could be used for output when TTY detected.

        let paste_url_str = format!("Paste url: {}", res.to_url(api.base()).as_str());
        std::io::stdout().write_all(paste_url_str.as_bytes())?;
        writeln!(std::io::stdout())?;
        let delete_url_str = format!("Delete url: {}", res.to_delete_url(api.base()).as_str());
        std::io::stdout().write_all(delete_url_str.as_bytes())?;
        writeln!(std::io::stdout())?;

Output:

Paste url: https://privatebin.net/?0a37477133f68c6c#48k1bFdRRfkMGxaKVdPEvRryABJ6cSdFk1c6RoPEbjq7
Delete url: https://privatebin.net/?pasteid=0a37477133f68c6c&deletetoken=7325797b0957881829d9f052d0c3d4281e4c6cb8bc50f1509c573669c7eff066
Mydayyy commented 6 months ago

Greetings,

I apologize for the late reply.

I like the idea of extracting that kind of functionality into the struct.

I haven't changed the CLI output in order to keep compatibility. But as an idea, something like the following could be used for output when TTY detected.

This idea is great as well. As you already mentioned currently this would break backward functionality, but in general I like the idea of adapting the output based on whether it is an interactive session or not.

What would be possible is to extend the output for the --json switch, for example add deleteurl and pasteurl as keys there. Makes it easier to access it via scripting without having to assemble it yourself from the other pieces.

I will test and merge it later once I am at my computer. Thank you for the contribution!

Best Regards Mydayyy

nain-F49FF806 commented 5 months ago

Greeting,

Just wanted to let you know that Share Paste app, which uses uniffi bindings to expose this library in Android, is now live! You can see how we're using this functionality over here: readme-screenshots.

I also maintain a branch of pbcli with the uniffi bindings here. Feel free to have a look and add to upstream if it makes sense at some point.

Best regards. :)

Mydayyy commented 5 months ago

wow, thats great :open_mouth: I'm honored that you chose PBCLI as your library of choice for the PrivateBin communication, thank you!

If you want you can create a PR to merge the UniFFI branch into here. It will just take me a few days to go over that since I also plan to read some basics about UniFFI

Best Regards Mydayyy