-
Notifications
You must be signed in to change notification settings - Fork 3
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
cli: add -c
/ -i
for non-interactive use
#4
Conversation
Hi @pillo79 , thanks for your kind words and for contributing, yes PR are welcome.
Non-interactive sessions is indeed something I would like DTSh to support, although my initial though was batch scripts, not command line arguments. That being said, I've tried your PR, and I'm more than fine with these
It was the best approach you could think off without introducing other API changes. But the design I had in mind was rather to rely on implementations of the
I've pushed the required refactoring and API changes in
Then implemented the batch scripts use case:
I tested the above new API with a simple ad-hoc Python script, and it seems to work fine. To handle the command line arguments (the
Would you mind also adding the scripts use case to
Note: unlike Do not hesitate to ask for help if this is not clear.
May be adding a "Batch Support" sub-section to "Usage" in the Getting started Guide (see Thanks. |
2985d78
to
914d28d
Compare
Rebased and reimplemented on the most recent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, thank for the nice work.
The requested changes are really minor, and I hope you won't find them too far fetched.
They mainly come from my preference to keep DTSh strictly typed: I'm not a pythonista and would quickly get lost otherwise. It's my fault, mypy is not configured strict
in setup.cfg
, only pylsp-mypy is: I'll fix that.
BTW, you may have noticed that my use of type hinting is not always consistent: this is because I'm not always sure what's the best practice. I feel Python type hinting, like everything Python, is moving really fast, and what was new in 3.8 may as well be promoted to the best practice in 3.9, then deprecated in 3.11, and so on.
Maybe you'll help me RFC all of this for DTSh once Zephyr's requirements are upgraded to Python 3.9.
I'm really glad we'll merge this batch support. Thanks.
src/dtsh/io.py
Outdated
|
||
|
||
class DTShInputCmds(DTShInput): | ||
"""Command-line input processor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you reword the doctring: DTShInputCmds
does not process command lines, it's rather some pseudo input stream.
@pillo79 , please, don't apply suggestions using the GitHub interface:
Please, rebase instead and re-apply your changes from there, like you've previously done. It's my fault, I should have used the "Comments" not "Request changes" feedbak. Sorry. Thanks. |
I think suggestions are a great tool! I used it temporarily just to get the diffs so I could fixup them individually 👍 |
Rebased on latest |
It's fine, just rebase once you're done: then we'll merge the PR and I'll rebase my own work onto that. Thanks. |
@pillo79 , oops, it seems you squashed the dtsh.rich.session commit into the dtsh.io commit ? Could you please submit 4 commits as before: io, rich.session, cli, getting-started. Thanks. |
This class is used to execute a list of shell commands in batch mode (no user interaction is supported).
Use DTShInputCmds class in DTShRichSession constructor to accept batch commands from cli arguments.
Add support for batch commands to the CLI. This allows the user to execute a series of commands from a file or from the command line at startup, and optionally enter an interactive loop after the batch commands have been executed.
Nope, I always modified both files in the same commit; these changes looked very related to me... 🤷♂️ |
Maybe I hadn't noticed. The rationale for this far fetched splitting, even for changes which may look closely related, is to keep things a bit easier to backport to the RFC/PR (which shall show as this 30 separate commits series for the sake of reviewers' health). This batch/non-interactive support is really something that I had in mind, but was not my priority when working on DTSh. Thanks to your PR, this happened faster than I thought, and I'm really happy about it. A bit out of topic: I'm going to push the initial implementation of the Thanks. |
Sure will! |
Hello, thanks for the super nice tool and hope you accept PRs!
I have added
-c
and-i
(as in the customsh
usage) to allow calling it non-interactively from scripts or command line.As the tool is very nicely structured, I'm not sure I've done it TheRightWay ™️ 🙂 so let me know any issues.
Also, not sure where to look to add docs! 😇