Additional interface for automation, based on JSON#14
Open
vanrein wants to merge 9 commits intoCartroo:masterfrom
Open
Additional interface for automation, based on JSON#14vanrein wants to merge 9 commits intoCartroo:masterfrom
vanrein wants to merge 9 commits intoCartroo:masterfrom
Conversation
Describes the general idea under ParseItem, implements it under Token. The other subclasses of ParseItem will follow the same idea. Still missing is the actual method to use as the extra input channel.
Functions implemented: match_json(), check_match_json(), onecmd_json(). In addition, added json=True flag to the wrapper of the method decorator and inserted the onecmd_json method into every decorated class. As for stdio, we'd like to provide stdin and capture stdout/stderr and possibly even interpret "FieldName: Value" lines in stdout.
Split a single "do_" string into simple words, without shell escaping. There is a variation based on JSON escaping that is better standardised, more portable and better tested. Using shlex is better avoided for reasons of boring consistency and reliable automation.
Author
|
Andrew, I made this donation because of your invitation "feel free to send me pull requests if you make an improvement you feel others would find useful" but can you please decide on accept-or-reject? I would like to flatten the temporary patches in our builds, preferably to your "pip install" package. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on the syntax and variable names contained in it, this patch adds a JSON interface using those names as dictionary lookup keys.
The interface is an added
onecmd_json()that expects JSON input, either in string from or as parsed by thejson.loads()function, but other than the command format and its better suitability for automation, it works exactly likeonecmd()for manually entered strings.The key
do_holds the token words to use, including the command to run; the keystdin_may be added with the value to feed into standard input; upon return,stdout_is set to what is printed on standard output and, if anything is printed on standard error, it can be found instderr_.This work was done for the InternetWide project where it allows the same shell to be used by operators and remote services.