Skip to content

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

Merged

Conversation

peterschrammel
Copy link
Member

Allows reading the commandline in JSON format from stdin

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.


#include "json_interface.h"

#include <iostream>
Copy link
Collaborator

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))
Copy link
Collaborator

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.

{
if(argument.is_string())
cmdline.args.push_back(argument.value);
else
Copy link
Collaborator

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.

}
}

/// Parse JSON-formatted commandline options from stdin
Copy link
Collaborator

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
Copy link
Collaborator

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"
Copy link
Collaborator

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.)

Copy link
Member Author

@peterschrammel peterschrammel Apr 28, 2019

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',

Copy link
Collaborator

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.

Copy link
Member Author

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...

Copy link
Collaborator

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:

  1. A "bi"-directional interface is about input and output.
  2. --{json,xml}-ui set up the output side of an interface.
  3. The comment claims that --{json,xml}-interface configure a bi-directional interface.
  4. The actual implementation, however, only reads input when using --{json,xml}-interface.
  5. One possible fix would be that upon seeing --{json,xml}-interface we also set the option for --{json,xml}-ui.
  6. 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. yes
  2. yes
  3. yes
  4. yes
  5. is being fixed here (was broken)
  6. not required because 5 works.

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.
@peterschrammel peterschrammel force-pushed the json-cmdline-interface branch from cf56b53 to 651c6aa Compare April 29, 2019 11:05
@peterschrammel peterschrammel merged commit 9e045dd into diffblue:develop Apr 29, 2019
@peterschrammel peterschrammel deleted the json-cmdline-interface branch April 29, 2019 12:16
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.

2 participants