-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
impl Display for Expression #89
Comments
What do you think the display implementation should be? I've hesitated about doing this in the past, because I don't think there's one obvious way to do it. |
Another practical issue is that internal |
The main question is how to escape spaces, quotes etc, right? My main use case for wanting this feature is for logging the commands that my tool is executing in a human-readable manner. I don't "need" perfect copy-pastability of printed commands, but it would be nice to have. |
I agree. Being able to log the command before it's executed would be very useful. |
Could you tell me a little more about your use cases? Another thought that I've had here is that the majority of callers construct an |
It's mainly just a convenience thing. I'm writing a xtask, and would like to log the commands that run. Now, there are a few ways I could go about this. I could probably create my own macro, and have that log and then create an |
Maybe it would make sense to have a method like I think my litmus test for "not worth getting right" here is quoting/escaping whitespace. If we can offer a function that's doesn't even try to quote whitespace for you (and makes lots of other compromises like that one), it'll be dead simple to implement, and hopefully useful most of the time. How does that sound? |
What you might want to do is create an iterator over some sort of "component" enum instead. |
Also, if wanted, I can probably drum up a PR. |
Or, better yet; |
@oconnor663 would you want a PR for this? I could look into it if wanted - but I don't want to start working on this if you think it's not something you want in the project. |
The way I'm standing at the moment, I'd love to see a PR on a simpler "to_string_lossy" or something like that, but I'm skeptical about exposing a more complex, structured API for inspection. I start thinking about cases like this: (cat xyz | sed s/a/b/) 2> stderr.txt | sed s/b/c/ As in "you've got three programs in a pipeline, and the stderrs of the first two have been jointly redirected to a file". Duct can execute that. But can an iterator of components faithfully describe it? It seems like you'd need a tree, which is of course what Duct uses internally. The prospect of exposing the entire internal tree (or some parallel structure) through the public API seems like much too much added complexity, for what would really be a niche debugging feature. On the other hand, maybe I'm blowing it out of proportion, and you've thought of some sweet spot in between. What do you think? |
I'm not thinking of structure, just display tokens. But tokens, so they can be formatted as you please, with a built in simple default. So parts should probably be named DisplayPart or somesuch. No intent to make it parseable (after all, you already lose env vars and similar by stringifying). |
Please impl Display for Expression so that commands can be printed without the awkward debug formatting :)
The text was updated successfully, but these errors were encountered: