-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23b1435
commit 137ed2c
Showing
63 changed files
with
36,084 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
gron | ||
*.tgz | ||
*.zip | ||
*.swp | ||
*.exe | ||
cpu.out | ||
gron.test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: go | ||
|
||
go: | ||
- 1.7 | ||
- 1.8 | ||
- 1.9 | ||
- tip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# Advanced Usage | ||
|
||
Although gron's primary purpose is API discovery, when combined with other tools like `grep` it can do some interesting things. | ||
|
||
As an exercise, let's try to mimick some of the examples from the [jq tutorial](https://stedolan.github.io/jq/tutorial/). | ||
|
||
> Disclaimer: munging data on the command line with gron can be useful, but using tools like `grep` and `sed` to manipulate the | ||
> data is error-prone and shouldn't be relied on in scripts. | ||
Get the last 5 commits from the gron repo: | ||
``` | ||
▶ gron "https://api.github.com/repos/tomnomnom/gron/commits?per_page=5" | ||
json = []; | ||
json[0] = {}; | ||
json[0].author = {}; | ||
json[0].author.avatar_url = "https://avatars.githubusercontent.com/u/58276?v=3"; | ||
json[0].author.events_url = "https://api.github.com/users/tomnomnom/events{/privacy}"; | ||
... | ||
json[4].parents[0].html_url = "https://github.com/tomnomnom/gron/commit/cbcad2299e55c28a9922776e58b2a0b5a0f05016"; | ||
json[4].parents[0].sha = "cbcad2299e55c28a9922776e58b2a0b5a0f05016"; | ||
json[4].parents[0].url = "https://api.github.com/repos/tomnomnom/gron/commits/cbcad2299e55c28a9922776e58b2a0b5a0f05016"; | ||
json[4].sha = "91b204972e63a1166c9d148fbbfd839f8697f91b"; | ||
json[4].url = "https://api.github.com/repos/tomnomnom/gron/commits/91b204972e63a1166c9d148fbbfd839f8697f91b"; | ||
``` | ||
|
||
To make the rest of this a little more readable, let's add an alias for that: | ||
|
||
``` | ||
▶ alias ggh='gron "https://api.github.com/repos/tomnomnom/gron/commits?per_page=5"' | ||
``` | ||
|
||
Extract just the first commit using `fgrep "json[0]"`: | ||
``` | ||
▶ ggh | fgrep "json[0]" | ||
json[0] = {}; | ||
json[0].author = {}; | ||
json[0].author.avatar_url = "https://avatars.githubusercontent.com/u/58276?v=3"; | ||
json[0].author.events_url = "https://api.github.com/users/tomnomnom/events{/privacy}"; | ||
json[0].author.followers_url = "https://api.github.com/users/tomnomnom/followers"; | ||
... | ||
json[0].parents[0].html_url = "https://github.com/tomnomnom/gron/commit/48aba5325ece087ae24ab72684851cbe77ce8311"; | ||
json[0].parents[0].sha = "48aba5325ece087ae24ab72684851cbe77ce8311"; | ||
json[0].parents[0].url = "https://api.github.com/repos/tomnomnom/gron/commits/48aba5325ece087ae24ab72684851cbe77ce8311"; | ||
json[0].sha = "7da81e29c27241c0a5c2e5d083ddebcfcc525908"; | ||
json[0].url = "https://api.github.com/repos/tomnomnom/gron/commits/7da81e29c27241c0a5c2e5d083ddebcfcc525908"; | ||
``` | ||
|
||
Get just the committer's name and the commit message using `egrep "(committer.name|commit.message)"`: | ||
``` | ||
▶ ggh | fgrep "json[0]" | egrep "(committer.name|commit.message)" | ||
json[0].commit.committer.name = "Tom Hudson"; | ||
json[0].commit.message = "Adds 0.1.7 to changelog"; | ||
``` | ||
|
||
Turn the result back into JSON using `gron --ungron`: | ||
``` | ||
▶ ggh | fgrep "json[0]" | egrep "(committer.name|commit.message)" | gron --ungron | ||
[ | ||
{ | ||
"commit": { | ||
"committer": { | ||
"name": "Tom Hudson" | ||
}, | ||
"message": "Adds 0.1.7 to changelog" | ||
} | ||
} | ||
] | ||
``` | ||
|
||
gron preserves the location of values in the JSON, but you can use `sed` to remove keys from the path: | ||
``` | ||
▶ ggh | fgrep "json[0]" | egrep "(committer.name|commit.message)" | sed -r "s/(commit|committer)\.//g" | ||
json[0].name = "Tom Hudson"; | ||
json[0].message = "Adds 0.1.7 to changelog" | ||
``` | ||
|
||
With those keys removed, the result is a 'flattened' object, which looks much cleaner when turned | ||
back into JSON with `gron --ungron`: | ||
|
||
``` | ||
▶ ggh | fgrep "json[0]" | egrep "(committer.name|commit.message)" | sed -r "s/(commit|committer)\.//g" | gron --ungron | ||
[ | ||
{ | ||
"message": "Adds 0.1.7 to changelog", | ||
"name": "Tom Hudson" | ||
} | ||
] | ||
``` | ||
|
||
Removing the `fgrep "json[0]"` from the pipeline means we do the same for all commits: | ||
``` | ||
▶ ggh | egrep "(committer.name|commit.message)" | sed -r "s/(commit|committer)\.//g" | gron --ungron | ||
[ | ||
{ | ||
"message": "Adds 0.1.7 to changelog", | ||
"name": "Tom Hudson" | ||
}, | ||
{ | ||
"message": "Refactors natural sort to actualy work + be more readable", | ||
"name": "Tom Hudson" | ||
}, | ||
... | ||
``` | ||
|
||
To include the `html_url` key for each commit's parents, all we need to do is add `parents.*html_url` into our call to `egrep`: | ||
``` | ||
▶ ggh | egrep "(committer.name|commit.message|parents.*html_url)" | sed -r "s/(commit|committer)\.//g" | ||
json[0].name = "Tom Hudson"; | ||
json[0].message = "Adds 0.1.7 to changelog"; | ||
json[0].parents[0].html_url = "https://github.com/tomnomnom/gron/commit/48aba5325ece087ae24ab72684851cbe77ce8311"; | ||
json[1].name = "Tom Hudson"; | ||
json[1].message = "Refactors natural sort to actualy work + be more readable"; | ||
json[1].parents[0].html_url = "https://github.com/tomnomnom/gron/commit/3eca8bf5e07151f077cebf0d942c1fa8bc51e8f2"; | ||
... | ||
``` | ||
|
||
To make the structure more like that in the final example in the `jq` tutorial, we can use `sed -r "s/\.html_url//"` to remove the `.html_url` part of the path: | ||
``` | ||
▶ ggh | egrep "(committer.name|commit.message|parents.*html_url)" | sed -r "s/(commit|committer)\.//g" | sed -r "s/\.html_url//" | ||
json[0].name = "Tom Hudson"; | ||
json[0].message = "Adds 0.1.7 to changelog"; | ||
json[0].parents[0] = "https://github.com/tomnomnom/gron/commit/48aba5325ece087ae24ab72684851cbe77ce8311"; | ||
json[1].name = "Tom Hudson"; | ||
json[1].message = "Refactors natural sort to actualy work + be more readable"; | ||
json[1].parents[0] = "https://github.com/tomnomnom/gron/commit/3eca8bf5e07151f077cebf0d942c1fa8bc51e8f2"; | ||
... | ||
``` | ||
|
||
And, of course, the statements can be turned back into JSON with `gron --ungron`: | ||
``` | ||
▶ ggh | egrep "(committer.name|commit.message|parents.*html_url)" | sed -r "s/(commit|committer)\.//g" | sed -r "s/\.html_url//" | gron --ungron | ||
[ | ||
{ | ||
"message": "Adds 0.1.7 to changelog", | ||
"name": "Tom Hudson", | ||
"parents": [ | ||
"https://github.com/tomnomnom/gron/commit/48aba5325ece087ae24ab72684851cbe77ce8311" | ||
] | ||
}, | ||
{ | ||
"message": "Refactors natural sort to actualy work + be more readable", | ||
"name": "Tom Hudson", | ||
"parents": [ | ||
"https://github.com/tomnomnom/gron/commit/3eca8bf5e07151f077cebf0d942c1fa8bc51e8f2" | ||
] | ||
}, | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Changelog | ||
|
||
## 0.6.0 | ||
- Adds `--json`/JSON stream output support (thanks @csabahenk!) | ||
- Removes trailing newline character for monochrome output (issue #43) | ||
|
||
## 0.5.2 | ||
- Built with Go 1.10 to fix issue #32 - Thanks @VladimirAlexiev and @joekyo! | ||
|
||
## 0.5.1 | ||
- Fixes bug where empty identifiers would be treated as bare words (thanks for the report, @waltertross!) | ||
|
||
## 0.5.0 | ||
- Adds `-k`/`--insecure` to disable validation of certificates when fetching URLs (thanks @jagsta!) | ||
|
||
## 0.4.0 | ||
- Adds `-c`/`--colorize` to force colorization of output (thanks @orivej!) | ||
- Adds `-s`/`--stream` option to read one JSON object per line | ||
- Native string quoting (performance improvement) | ||
- Fixes bug with strings ending in a double-slash (issue #25) | ||
|
||
## 0.3.7 | ||
- HTML characters (`<`, `>` etc) are no-longer escaped in gron output (issue #22) | ||
|
||
## 0.3.6 | ||
- Fixes bug where invalid statements were outputted | ||
|
||
## 0.3.5 | ||
- General performance improvements; 5 to 17 times faster (see issue #21 for details) | ||
|
||
## 0.3.4 | ||
- Speed improvements when using `--monochrome` | ||
- Adds `--no-sort` option | ||
|
||
## 0.3.3 | ||
- Slightly improved error reporting when ungronning | ||
- 20 second timeout on HTTP(s) requests (thanks @gummiboll!) | ||
- Version information added at build time + `--version` option (issue #19) | ||
|
||
## 0.3.2 | ||
- Adds handling of `--` lines produced by grep -A etc (issue #15) | ||
|
||
## 0.3.1 | ||
- Built with Go 1.7! | ||
- Up to 25% faster | ||
- 40% smaller binaries | ||
|
||
## 0.3.0 | ||
- Adds colorized gron output | ||
- Fixes formatting of large ints in ungron output (issue #12) | ||
|
||
## 0.2.9 | ||
- Adds colorized ungron output (thanks @nwidger!) | ||
- Adds 32 bit binaries to releases | ||
|
||
## 0.2.8 | ||
- Adds freebsd release binaries | ||
|
||
## 0.2.7 | ||
- Fixes bad handling of escape sequences when ungronning - but properly this time (issue #7) | ||
|
||
## 0.2.5 | ||
- Fixes bad handling of escape sequences when ungronning (issue #7) | ||
|
||
## 0.2.4 | ||
- Fixes handling of large integers (issue #6) | ||
|
||
## 0.2.3 | ||
- Switches Windows binary packaging to zip instead of tgz | ||
|
||
## 0.2.2 | ||
- Tweaks release automation, no user-facing changes | ||
|
||
## 0.2.1 | ||
- Adds windows binary | ||
|
||
## 0.2.0 | ||
- Adds [ungronning](README.mkd#ungronning)! | ||
|
||
## 0.1.7 | ||
- Fixes sorting of array keys; now uses natural sort | ||
|
||
## 0.1.6 | ||
- Adds proper handling of key quoting using Unicode ranges | ||
- Adds basic benchmarks | ||
- Adds profiling script | ||
|
||
## 0.1.5 | ||
- Adds scripted builds for darwin on amd64 | ||
|
||
## 0.1.4 | ||
- Minor changes to release script | ||
|
||
## 0.1.3 | ||
- Releases are now tarballs | ||
|
||
## 0.1.2 | ||
- Underscores no-longer cause keys to be quoted | ||
- HTTP requests are now done with `Accept: application/json` | ||
- HTTP requests are now done with `User-Agent: gron/0.1` | ||
|
||
## 0.1.1 | ||
- Adds support for fetching URLs directly | ||
|
||
## 0.1.0 | ||
- Support for files | ||
- Support for `stdin` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Contributing | ||
|
||
* Raise an issue if appropriate | ||
* Fork the repo | ||
* Make your changes | ||
* Use [gofmt](https://golang.org/cmd/gofmt/) | ||
* Make sure the tests pass (run `./script/test`) | ||
* Make sure the linters pass (run `./script/lint`) | ||
* Issue a pull request | ||
|
||
## Commit Messages | ||
I'd prefer it if commit messages describe what the *commit does*, not what *you did*. | ||
|
||
For example, I'd prefer: | ||
|
||
``` | ||
Adds lint; removes fluff | ||
``` | ||
|
||
Over: | ||
|
||
``` | ||
Added lint; removed fluff | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 Tom Hudson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.