-
Notifications
You must be signed in to change notification settings - Fork 7
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
add ability to check exit status of command that was run #19
base: master
Are you sure you want to change the base?
add ability to check exit status of command that was run #19
Conversation
0d108ad
to
6f61a39
Compare
@FauconFan I have rebased onto the updated
|
Hi! I think you are in the right direction! A few comments and things that comes out of my head:
That would be really great overall I just approved CI in this PR, so you can run your tests within Windows and Linux. |
Alright, I got The mdbook-cmdrun/tests/command.rs Lines 47 to 57 in b3f4248
and probably the following on Windoze mdbook-cmdrun/tests/command.rs Line 61 in b3f4248
After some googling, I think there are two options forward:
@FauconFan any opinions on these two paths forward? Edit: The shell word splitting is not without its pitfalls unfortunately. It (I tested with |
I guess I was also excited about using
Maybe after this experimentation we should conclude that using a full CLI parser like clap is not the way forward for this parsing? There is so much parsing "outside" of the parsing done by clap that I don't think using clap is worth it... What do you think @FauconFan ? It could also certainly be the case that my infamiliarity with clap and Rust is hiding an obvious solution that avoids these issues. |
Hello @tomeichlersmith, Sorry for the delay for getting back to you. I'm not opposed to either shlex or shellwords. I never used them, but they look very stable. For maintainability, I'm more concerned about bug fixing and readability than a few tricks to parse the input in the way we have stated, and if you don't want to use clap, i'm okay with that. I'm not a huge fan of handcrafting solutions (in this case manual parsing) where it can be done with very established solutions (or if you have a really reason to do it manually!). Another solution would be to not have -N argument and just use clap which is very common in the Rust cli space. As said, a quick win would be to "drop" the shorthand -N and use clap, and hop it's working I'm more interested in the tests that comes with the implementation than the implementation itself (except maintainability). The rest is up to you. Me advising for clap was because I thought that was easy, and apparently it isn't. That's fine I let you the judge of how you want to proceed. |
That makes sense, I will focus on tests and getting a longer-term maintainable solution. No worries on the delay :) I am just using this to help learn some Rust so I am not in a huge rush. |
This is a really good way to learn indeed :) |
c9ce4b8
to
ad94dce
Compare
Alright, I dropped back to manual parsing because of the mentioned reasons above. I stored my work on a branch on my fork in case you want to double check that I'm not missing anything obvious. The main issue is that shellwords (and the like) interpret words when splitting causing us to lose some of the escape characters. Using To Do List
|
I am making a draft PR because I would want to add some documentation to the README and associated tools, but it appears to be working as intended and so I'd like feedback.
The basic idea is to allow for users to optionally specify an exit code the command should return. This is done by inspecting the command and if the first word starts with
-
, then the exit code that should be returned comes after.Examples
Leaving with a non-zero code will do nothing (current behavior).
Specifying an exit code that the command returns successfully builds.
Mis-matching exit codes will propagate an error message into the markdown to be rendered.