-
Notifications
You must be signed in to change notification settings - Fork 277
JSON cmdline interface #4585
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
JSON cmdline interface #4585
Conversation
ebc6165
to
9a6f74a
Compare
src/json/json_interface.cpp
Outdated
|
||
#include "json_interface.h" | ||
|
||
#include <iostream> |
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.
Nit pick: I'd prefer for standard-library includes to come last, see also some recent exchange that @kroening and I had; the idea is that any included header file should parse even without additional includes being present. So do the most minimal ones (the ones from util
) first, and then by increasing complexity.
throw invalid_command_line_argument_exceptiont( | ||
"array expected", "'options'"); | ||
} | ||
for(const auto &option_pair : to_json_object(options)) |
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.
Nit pick: add a blank line before this one to be consistent with the code a few lines above.
src/json/json_interface.cpp
Outdated
{ | ||
if(argument.is_string()) | ||
cmdline.args.push_back(argument.value); | ||
else |
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.
I believe you could increase readability by doing
if(!argument.is_string())
{
throw ...
}
cmdline.args.push_back(argument.value);
because it reduces the number of closing braces that immediately follow each other. This applies even more so down below, where you currently have three closing braces.
src/json/json_interface.cpp
Outdated
} | ||
} | ||
|
||
/// Parse JSON-formatted commandline options from stdin |
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.
I think this should just be removed - or at least I have no idea what Doxygen makes of documentation at both declaration and definition when they aren't the same.
|
||
class cmdlinet; | ||
|
||
/// Parses the JSON-formatted command line from stdin |
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.
I think it would be rather important to document the expected JSON syntax! Otherwise you're bound to trial and error...
@@ -1030,6 +1033,7 @@ void cbmc_parse_optionst::help() | |||
" --xml-ui use XML-formatted output\n" | |||
" --xml-interface bi-directional XML interface\n" | |||
" --json-ui use JSON-formatted output\n" | |||
" --json-interface bi-directional JSON interface\n" |
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.
Is this actually bi-directional?! Doesn't it only become "bi"directional when using both --json-interface
and --json-ui
? (The same is of course true for XML.)
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.
I was wondering about that and have now more investigated in the XML case (see comments there). The original intention was that --xml-interface subsumes --xml-ui.
Actually, the current behaviour was broken because the UI was set before the option could have been parsed from stdin, which seems difficult to fix without splitting the parse_optionst
constructor into two phases and adding a set_ui
to ui_message_handlert
(rather no).
Also, the question is what happens with errors during parsing the options - they should already be output in a proper format. Thus, I'd rather stick with the original intention of 'bi-directional',
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.
I'm not sure I fully understand - I agree that --{json,xml}-interface
should subsume --{json,xml}-ui
- but I don't think that was actually work as such? If things can be made to work as such then we'd have the desired bi-directional interface.
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.
--json-interface
now implies --json-ui
, and --xml-interface
now implies --xml-ui
.
but I don't think that was actually work as such?
Not sure, I understand...
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.
Let me retry, my apologies for completely broken English:
- A "bi"-directional interface is about input and output.
--{json,xml}-ui
set up the output side of an interface.- The comment claims that
--{json,xml}-interface
configure a bi-directional interface. - The actual implementation, however, only reads input when using
--{json,xml}-interface
. - One possible fix would be that upon seeing
--{json,xml}-interface
we also set the option for--{json,xml}-ui
. - This might not actually work as it could be too late, in which case a more extensive change would be required. If this is the case, a simple fix would be to change the comment such as not to promise a bi-directional interface. Users wanting to use a bi-directional interface would then need to provide both
--{json,xml}-interface
and--{json,xml}-ui
.
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.
- yes
- yes
- yes
- yes
- is being fixed here (was broken)
- not required because 5 works.
9a6f74a
to
8d7230b
Compare
f4fa2e6
to
cf56b53
Compare
return true if a property is either true or false.
json-interface subsumes json-ui. When json-interface is enabled then other commandline options haven't been parsed yet when the UI is set.
allows reading the command line in JSON format from stdin.
Allows reading the commandline in JSON format from stdin.
cf56b53
to
651c6aa
Compare
Allows reading the commandline in JSON format from stdin