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

Added a -q option to suppress output if no errors, and show filename on error #17

Merged
merged 5 commits into from
Jun 14, 2014
Merged

Conversation

martinlindhe
Copy link
Contributor

I intend to use jsonlint as part of build process and would like to supress unnessecary output, so I added a -q option to make it quiet on successful validation.

Also added name of the file when error was found

@martinlindhe martinlindhe reopened this Jun 11, 2014
@martinlindhe martinlindhe changed the title Added a -q option to suppress output if no errors was found Added a -q option to suppress output if no errors, and show filename on error Jun 11, 2014
before:
  $ bin/jsonlint bad.json
  bad.json: Parse error on line 2:
  ...th trailing comma",}
  ----------------------^
  Expected: 'STRING' - It appears you have an extra trailing comma

after:
  $ bin/jsonlint bad.json
  bad.json: Parse error on line 2:
  ...th trailing comma",}
  ---------------------^
if ($contents = file_get_contents('php://stdin')) {
lint($contents);
}

echo 'Usage: jsonlint file'.PHP_EOL;
echo 'Usage: jsonlint file [options]'.PHP_EOL;
Copy link
Contributor

Choose a reason for hiding this comment

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

the usage should display the available options too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for feedback. While looking at how to fix this, i realized the code path would only output usage info after stdin have been read. (this is the same in the original code).

So instead i added other options (-h, --help) to show the usage information in commit
https://github.com/martinlindhe/jsonlint/commit/b46b0a1d41c03603e3c66e53cf03b3a96a791d5c

fixing broken code path where usage info was displayed
only if file_get_contents('php://stdin') failed, which is
not possible
@Seldaek Seldaek merged commit b46b0a1 into Seldaek:master Jun 14, 2014
@Seldaek
Copy link
Owner

Seldaek commented Jun 14, 2014

Thanks!

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.

3 participants