Skip to content

Provide example how to extend script with own package #13

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

Closed
breml opened this issue Jul 4, 2019 · 2 comments
Closed

Provide example how to extend script with own package #13

breml opened this issue Jul 4, 2019 · 2 comments

Comments

@breml
Copy link

breml commented Jul 4, 2019

In #12 I suggested to add a separate sub package called unix with an API similar to the unix coreutils commands. This issue was closed with the suggestion to implement this in it's own package/library, separated from this package.

So I tried to figure out, what would be the best way to do this and therefore I wanted to reach out to you (@bitfield and all other followers of this package) to discuss, how this could be done.

My goal is to leverage this package, especially the Pipe and be able to combine (in an as nice as possible way) functions from this package (e.g. script.Freq()) with functions from an other package (e.g. unix.Head()).

I looked at the example in the README but this does not work in a seperate package, because you can not add new methods to an type defined in an other package.

So the question is, what is the best way to approach this?

@bitfield
Copy link
Owner

bitfield commented Jul 5, 2019

I've spotted this problem as well, and it's a shame, because I would have liked people to be able to implement their own Pipe methods in their own programs and libraries. I did consider making Pipe an interface, but of course it would be a gigantic and ever-growing interface, and you'd have to implement all of it just to add one method.

I think the only thing you can really do is build a unix.Pipe type which wraps the methods of script.Pipe—that gives you the opportunity to add new semantics. For example, unix.Pipe.Head() can work like Unix head, but perhaps call script.First() internally to implement it.

If you prefer to fork script entirely and give it a new API, I'm fine with that too, although that would obviously involve a lot of duplication, which isn't ideal.

@bitfield
Copy link
Owner

Closing this, as I hope you'll make your own package which provides a Unix-like interface to these operations, as discussed!

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