Skip to content

add quiet option #382

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 6 commits into from
Mar 17, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/validate-json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function __autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
Expand Down Expand Up @@ -112,6 +111,7 @@ Usage: validate-json data.json
Options:
--dump-schema Output full schema and exit
--dump-schema-url Output URL of schema
--verbose Show additional output
-h --help Show this help

HLP;
Expand Down Expand Up @@ -221,7 +221,9 @@ try {
$validator->check($data, $schema);

if ($validator->isValid()) {
echo "OK. The supplied JSON validates against the schema.\n";
if(isset($arOptions['--verbose'])) {
echo "OK. The supplied JSON validates against the schema.\n";
}
} else {
echo "JSON does not validate. Violations:\n";
foreach ($validator->getErrors() as $error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking great :-).

While you're at it, can we also have a --quiet option that suppresses the error output?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, but what would be the use case?

Copy link
Contributor

@erayd erayd Mar 11, 2017

Choose a reason for hiding this comment

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

Use case is scripts or pipelines where you don't care about the error output (and don't want the clutter); you just want to validate. Lots of linux / unix scripts only care about the exit status being zero (OK) or nonzero (not OK), which this script complies with.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, okay. Sounds good. Comin' up.

Expand Down