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

(Feature) Provide a way to read from a file a series of instructions #39

Open
TFCx opened this issue Jan 14, 2020 · 3 comments
Open

(Feature) Provide a way to read from a file a series of instructions #39

TFCx opened this issue Jan 14, 2020 · 3 comments

Comments

@TFCx
Copy link

TFCx commented Jan 14, 2020

It would be very useful to be able to read a series of instructions from a file. That would allow scripting as well as easy testing.
Should there be a way to configure to either 1) do all the instructions even if some returns errors 2) exit at the first instruction returning an error?
Also I'm not familiar with rust yet but there might be some additional design/testing involved in an async environment?

@mendelt
Copy link
Owner

mendelt commented Jan 14, 2020

Thank you for the great idea. This should be reasonably easy to implement.
I'm not sure about error handling yet. I think we'll crash out of the application when a panic occurs, this is similar to how cmdr works for manual input, and we'll probably go for option 1 in the first version for normal error results.
Cmdr itself works completely synchronously at the moment and I'm not sure if it makes sense to change this. I think it makes sense to keep cmdr synchronous but I don't think there are any issues using it to kick of async stuff running in the background. But I havent played with this yet and I'm open to suggestions on how to do this better.

@mendelt
Copy link
Owner

mendelt commented Jan 19, 2020

I have this working right now but I'm not completely happy with the interface yet. So I'll play with this a bit more before I create a release.
If you're interested in trying out the new feature I have everything working in the master branch. There is an example in cmdr/examples/09-file-input.rs that shows how to run commands from a file.
Basically there already was a LineReader trait that abstracted away input but this was not accessible and only had a RustyLineReader implementation that uses the RustyLine library for user input. I created a FileLineReader and an alternative entry-point to change what LineReader implementation you use.

@TFCx
Copy link
Author

TFCx commented Jan 19, 2020

I'll test it tomorrow with my small use case. I have been using a locally modified version of cmdr but your code seems better. I have another small request, but i'll open another issue for it.

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