Skip to content
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

add quiet option #382

Merged
merged 6 commits into from
Mar 17, 2017
Merged

add quiet option #382

merged 6 commits into from
Mar 17, 2017

Conversation

shmax
Copy link
Collaborator

@shmax shmax commented Mar 11, 2017

Fix for #380

Only emit output from CLI when there are errors or when --quiet is not specified.

Actually, I'm wondering if maybe we should just skip the --quiet option and simply not produce any output at all when validation passes. That's generally how other linux programs work from the command line.

@erayd @bighappyface @evilebottnawi

@alexander-akait
Copy link

and simply not produce any output at all when validation passes. That's generally how other linux programs work from the command line.

It's a great idea

@erayd
Copy link
Contributor

erayd commented Mar 11, 2017

Actually, I'm wondering if maybe we should just skip the --quiet option and simply not produce any output at all when validation passes. That's generally how other linux programs work from the command line.

I like this a lot, although if we go down this road, having a --verbose option probably makes sense.

@shmax
Copy link
Collaborator Author

shmax commented Mar 11, 2017

I like this a lot, although if we go down this road, having a --verbose option probably makes sense.

Yeah, that's better. Let me flip it around...

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.

@shmax
Copy link
Collaborator Author

shmax commented Mar 11, 2017

Added 'quiet' option, and moved all of the option parsing stuff to the top of the file.

echo $e->getMessage() . "\n";
output("Error loading JSON schema file\n");
output($urlSchema . "\n");
output($e->getMessage() . "\n");
exit(2);
}
$refResolver = new JsonSchema\SchemaStorage($retriever, $resolver);
$schema = $refResolver->resolveRef($urlSchema);

if (isset($arOptions['--dump-schema'])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicit requests for output like this should override --quiet.

Copy link
Contributor

Choose a reason for hiding this comment

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

GitHub highlighted the wrong line - I'm referring to if (isset($arOptions['--dump-schema']))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sgtm

@@ -198,21 +210,21 @@ try {
$urlSchema = $resolver->resolve($pathSchema, $urlData);

if (isset($arOptions['--dump-schema-url'])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicit requests for output like this should override --quiet

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.

Not sure whether you're intending this one in a different commit to the --dump-schema one, or if you missed it - but in the past you've combined this kind of thing in a single commit, so adding a comment just in case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Never mind, I see you just posted a commit for that at about the same time as my last comment!

Copy link
Contributor

@erayd erayd left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for doing this :-).

@shmax
Copy link
Collaborator Author

shmax commented Mar 11, 2017

My pleasure. Only 28 issues to go!

@alexander-akait
Copy link

/cc @erayd can merge?

@erayd
Copy link
Contributor

erayd commented Mar 15, 2017

@shmax Any chance you could change the base branch to 6.0.0? Or would you prefer to forward-port this one, rather than backporting to 5.2.0?

@shmax
Copy link
Collaborator Author

shmax commented Mar 15, 2017

Any chance you could change the base branch to 6.0.0?

SGTM

@shmax shmax changed the base branch from master to 6.0.0-dev March 15, 2017 19:19
@erayd
Copy link
Contributor

erayd commented Mar 15, 2017

Awesome - thanks :-)

@bighappyface bighappyface merged commit d3f7740 into jsonrainbow:6.0.0-dev Mar 17, 2017
erayd pushed a commit to erayd/json-schema that referenced this pull request Mar 17, 2017
* add quiet option

* use verbose instead of quiet

* add quiet option

* always output dump-schema

* always output dump-schema-url

* fix typo and ws
@erayd erayd mentioned this pull request Mar 17, 2017
erayd pushed a commit to erayd/json-schema that referenced this pull request Mar 17, 2017
* add quiet option

* use verbose instead of quiet

* add quiet option

* always output dump-schema

* always output dump-schema-url

* fix typo and ws
bighappyface pushed a commit that referenced this pull request Mar 22, 2017
* Add URI translation for retrieval & add local copies of spec schema

* Add use line for InvalidArgumentException & adjust scope (#372)

Fixes issue #371

* add quiet option (#382)

* add quiet option

* use verbose instead of quiet

* add quiet option

* always output dump-schema

* always output dump-schema-url

* fix typo and ws

* [BUGFIX] Add provided schema under a dummy / internal URI (fixes #376) (#378)

* Add provided schema under a dummy / internal URI (fixes #376)

In order to resolve internal $ref references within a user-provided
schema, SchemaStorage needs to know about the schema. As user-supplied
schemas do not have an associated URI, use a dummy / internal one instead.

* Remove dangling use

* Change URI to class constant on SchemaStorage

* Add option to disable validation of "format" constraint (#383)

* Add more unit tests (#366)

* Add test coverage for coercion API

* Complete test coverage for SchemaStorage

* Add test coverage for ObjectIterator

* Add exception test for JsonPointer

* MabeEnum\Enum appears to use singletons - add testing const

* Don't check this line for coverage

mbstring is on all test platforms, so this line will never be reached.

* Add test for TypeConstraint::validateTypeNameWording()

* Add test for exception on TypeConstraint::validateType()

* PHPunit doesn't like an explanation with its @codeCoverageIgnore...

* Add various tests for UriRetriever

* Add tests for FileGetContents

* Add tests for JsonSchema\Uri\Retrievers\Curl

* Add missing bad-syntax test file

* Restrict ignore to the exception line only

* Fix exception scope

* Allow the schema to be an associative array (#389)

* Allow the schema to be an associative array

Implements #388.

* Use json_decode(json_encode()) for array -> object cast

* Skip exception check on PHP versions < 5.5.0

* Skip test on HHVM, as it's happy to encode resources

* Enable FILTER_FLAG_EMAIL_UNICODE for email format if present (#398)

* Don't throw exceptions until after checking anyOf / oneOf (#394)

Fixes #393

* Fix infinite recursion on some schemas when setting defaults (#359) (#365)

* Don't try to fetch files that don't exist

Throws an exception when the ref can't be resolved to a useful file URI,
rather than waiting for something further down the line to fail after
the fact.

* Refactor defaults code to use LooseTypeCheck where appropriate

* Test for not treating non-containers like arrays

* Update comments

* Rename variable for clarity

* Add CHECK_MODE_ONLY_REQUIRED_DEFAULTS

If CHECK_MODE_ONLY_REQUIRED_DEFAULTS is set, then only apply defaults
if they are marked as required.

* Workaround for $this scope issue on PHP-5.3

* Fix infinite recursion via $ref when applying defaults

* Add missing second test for array case

* Add test for setting a default value for null

* Also fix infinite recursion via $ref for array defaults

* Move nested closure into separate method

* $parentSchema will always be set when $name is, so don't check it

* Handle nulls properly - fixes issue #377

* Add option to also validate the schema (#357)

* Remove stale files from #357 (obviated by #362) (#400)

* Stop #386 sneaking in alongside another PR backport
erayd pushed a commit to erayd/json-schema that referenced this pull request Mar 22, 2017
* add quiet option

* use verbose instead of quiet

* add quiet option

* always output dump-schema

* always output dump-schema-url

* fix typo and ws
@shmax shmax deleted the add-quiet-option branch March 2, 2019 01:51
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.

4 participants