Skip to content

Additional interface for automation, based on JSON#14

Open
vanrein wants to merge 9 commits intoCartroo:masterfrom
arpa2:json
Open

Additional interface for automation, based on JSON#14
vanrein wants to merge 9 commits intoCartroo:masterfrom
arpa2:json

Conversation

@vanrein
Copy link
Copy Markdown

@vanrein vanrein commented Nov 22, 2018

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 the json.loads() function, but other than the command format and its better suitability for automation, it works exactly like onecmd() for manually entered strings.

The key do_ holds the token words to use, including the command to run; the key stdin_ 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 in stderr_.

This work was done for the InternetWide project where it allows the same shell to be used by operators and remote services.

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.
@vanrein
Copy link
Copy Markdown
Author

vanrein commented Feb 22, 2019

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!
-Rick

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

Successfully merging this pull request may close these issues.

1 participant