Output option
Thanks for your quick response to #9. This PR implements the kind of thing I had in mind.
It makes this possible:
$ slack-cli -s au-phiware -l 1 -o >(gpg -d)
[@au-phiware 2018-12-10 15:13:06] au-phiware:
stdin: https://files.slack.com/files-pri/T40QQHKDE-FEPB666BM/stdin
gpg: encrypted with 4096-bit RSA key, ID DEADBEEF0D19D828, created 2018-04-15
"au-phiware"
This is secret...
Please note, this is my first time write any python and I am unaware of its idiosyncrasies, please feel free to make edits. Also, I wasn't sure if that was the best way to get hold of the token.
Thanks for the PR @au-phiware! This is an interesting proposition, but I see a few cases where the change is going to be inconvenient:
- When there is a binary file upload, dumping to stdout is unreadable.
- When the file is very large (> 1 Mb) the console becomes unreadable, too.
- When reading a long history (
-l 1000) this makes the user download many (potentially large) files.
Can you please tell me what is your use case, so that we can improve on your solution? Maybe you just want to view the last uploaded file? In such case, would you be ok with saving to disk, with something like:
slack-cli -s au-phiware -l 1 -o /tmp/mybackup/ && cat /tmp/mybackup/stdin | gpg -d
?
Those are valid points, I guess in those situations the user would just not use the --output option.
Another feature might be an --output-dir option that operates more like a download manager.
Regarding specific use cases, I've only just starting using this and the 'pipe into gpg' was certainly the first use case that I came across.
@au-phiware Note that the --output-dir solution you are suggesting corresponds to what I suggested, too :)
slack-cli -s au-phiware -l 1 -o /tmp/mybackup/ && cat /tmp/mybackup/stdin | gpg -d
In this example the -o option corresponds to your --output-dir.
I like the idea of having a download manager. We could save files automatically to <output-dir>/<channel name>/<datetime><file name>. Your PR does almost that -- would you have the time (and interest) to modify it to match these requirements<
Regarding output to stdout, there are some cases where it might be useful. However, the gpg example is hard to achieve: for this to work, the command would need to output only the file content, and no extra indication, such as the file url, the content of other conversations, etc. AFAIK if we pipe anything else to gpg, then decryption will fail with gpg: [don't know]: invalid packet errors. So I'm not sure it's a practical scenario. What do you think?
@regisb, yes, I thought your -o and my --output-dir were the same thing (but you can never be sure :wink:).
I don't have a lot of time to spare, but I think a "download to directory" would be a fairly simple change, so I'll try and give it a shot.
Also, that gpg example in my OP is the real output when building slack-cli from this PR, so it is working and practical. But it relies on the user to get the option right... Here's a more fuller example:
$ gpg -e --armor <<<'This is secret...' | slack-cli -d au-phiware --file /dev/stdin
...gpg promts...
slack-cli -s au-phiware -l 1 -o "stdin:">(gpg -d)
[@au-phiware 2018-12-17 16:32:29] au-phiware:
stdin: https://files.slack.com/files-pri/T04QQHKDE-FEWDYAQF9/stdin
gpg: encrypted with 4096-bit RSA key, ID DEADBEEF0D19D828, created 2018-04-15
"au-phiware"
This is secret...
Looks good! The important thing is that we agree on the right CLI options. I'll implement this feature, using your PR as a starting point.