Skip to content
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

Make it possible to pipe utilities #59

Open
fhunleth opened this issue Mar 1, 2021 · 5 comments
Open

Make it possible to pipe utilities #59

fhunleth opened this issue Mar 1, 2021 · 5 comments

Comments

@fhunleth
Copy link
Collaborator

fhunleth commented Mar 1, 2021

At a shell prompt, it's really convenient to be able to pipe the output from one command into another. The current toolshed commands don't let you do this. Here's an example that would be nice to support:

iex> cat("/etc/services") |> grep(~r/ntp/)
... all lines with `ntp` in them...

The refactor branch has a start at implementing this.

@mnishiguchi
Copy link
Contributor

Does this boil down to letting functions return an Elixir representation instead of printing the result and returning :"do not show this result in output"?

  • cat/1 can return a string
  • Some functions like dmesg/0 might be OK as is...

Maybe we want to think of specific scenarios where pipe-ability is handy like cat + grep. Is there anything else?

@fhunleth
Copy link
Collaborator Author

I suppose that I regularly pipe output when using bash, so this comes up all the time for me. I want to grep pretty much everything that returns a string in Elixir. This includes non-Toolshed things like inspect and traces too. Piping is also useful for redirecting text output to files or transfer over the network so that the text can be looked using an editor.

Fwiw, I prototyped this feature a couple years ago in the refactor branch. That branch needs some work to bring it up to date, but I'd be willing to put that in if there's interest.

@mnishiguchi
Copy link
Contributor

mnishiguchi commented Jun 14, 2022

Ah wrapping the result in a standardized struct, nice!
It works like a charm.

I think pipe-ability will be a huge appeal to Elixir programmers. Also if you yourself want to do the piping all the time, that is a good reason to implement the feature since you are one of the Nerves heavy users.

@mnishiguchi
Copy link
Contributor

I could inherit your work if you rebase it on the latest main. There seem to be some major merge conflicts.

@fhunleth
Copy link
Collaborator Author

I rebased the refactor branch into the pipes branch. It's definitely part complete. This looks like a decent amount of work since there are a lot of commands and some of them look like they need some thought to pipe nicely. I'm wondering if it might be easier to tackle a couple easier issues before this one. Perhaps we should strategize on this after you get a chance to look over the branch more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants