jaraco / keyring

MIT License
1.24k stars 152 forks source link

Add argument to not output newline with "get" #657

Closed wcooley closed 2 months ago

wcooley commented 10 months ago

This PR addresses #656 which I opened earlier today. It doesn't do anything with completion support; I have to confess that I do not know how that works.

While this could be more sophisticated (such as supporting a --newline for symmetry, to undo the effect of a prior --no-newline), this is enough to get started and for my own personal needs.

jaraco commented 9 months ago

Thanks for the contrib. I have some reservations, but nothing that can't be overcome.

My reservations stem from, "why hasn't this issue been solved elsewhere?" In other words, it seems to me that keyring isn't the first application to output text in a CLI for use in a pipe. Is there an established convention for handling these sorts of situations? Is there an existing library that implements these conventions (such that they don't have to be implemented inline with keyring's unique logic)? I suspect the answer is "no, every application just does its own thing and it's the responsibility of each application to adapt to its users' needs as the arise," but I'd be delighted if there were some guidance out there.

My other reservation is with the use of a boolean parameter. I try to avoid the use of those. I'd prefer something like "--format" or "--template", which specifies the format of the output, and maybe default to "{password}\n" but allow it to be overridden by "--format {password}". I'm less sure about this concern, and it depends a lot on what background we might discover in the first concern.

Let me know what you find / think.

jaraco commented 6 months ago

Another consideration - maybe keyring should detect if the output is being piped, and in that case, default to a format without the newline.

jaraco commented 5 months ago

What do you think about re-using the is tty logic to infer whether the caller would prefer a newline?

jaraco commented 2 months ago

Since this issue is languishing, I'm going to close it for now. Feel free to revive the conversation and we can re-open it.