Skip to content
Myr

default.yml

This file

Path

docs/content/tutorial/default.yml

337 lines · 14.1 KiB · YAML

Last changed by

Fix typos (#3173)Nathan Baulchbefore adoption860af44

History of this file

Take it

The walk stopped after 200 commits: lines older than c3b1496 point at it.

Update NEWS.md with changes since 1.7 (#2948)Mattias Wadmanbefore adoptionc3b1496

lines 1–209why, one step back
1headline: Tutorial
2body:3 - text: |45 GitHub has a JSON API, so let's play with that. This URL gets us the last6 5 commits from the jq repo.78 - command: "curl 'https://api.github.com/repos/jqlang/jq/commits?per_page=5'"9 result: |10 [11 {12 "sha": "cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",13 "node_id": "C_kwDOAE3WVdoAKGNmZjUzMzZlYzcxYjZmZWUzOTZhOTViYjBlNGJlYTM2NWUwY2QxZTg",14 "commit": {15 "author": {16 "name": "Mattias Wadman",17 "email": "mattias.wadman@gmail.com",18 "date": "2021-06-09T14:02:22Z"19 },20 "committer": {21 "name": "Nico Williams",22 "email": "nico@cryptonector.com",23 "date": "2022-05-26T21:04:32Z"24 },25 "message": "docs: Document repeat(exp)",26 "tree": {27 "sha": "d67d5542df1f16d1a48e1fb75749f60482cd874b",28 "url": "https://api.github.com/repos/jqlang/jq/git/trees/d67d5542df1f16d1a48e1fb75749f60482cd874b"29 },30 "url": "https://api.github.com/repos/jqlang/jq/git/commits/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",31 "comment_count": 0,32 "verification": {33 "verified": false,34 "reason": "unsigned",35 "signature": null,36 "payload": null37 }38 },39 "url": "https://api.github.com/repos/jqlang/jq/commits/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",40 "html_url": "https://github.com/jqlang/jq/commit/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",41 "comments_url": "https://api.github.com/repos/jqlang/jq/commits/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8/comments",42 "author": {43 ...4445 - text: |4647 GitHub returns nicely formatted JSON. For servers that don't, it can be48 helpful to pipe the response through jq to pretty-print it. The simplest49 jq program is the expression `.`, which takes the input and produces it50 unchanged as output.5152 - command: "curl 'https://api.github.com/repos/jqlang/jq/commits?per_page=5' | jq '.'"53 result: |54 [55 {56 "sha": "cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",57 "node_id": "C_kwDOAE3WVdoAKGNmZjUzMzZlYzcxYjZmZWUzOTZhOTViYjBlNGJlYTM2NWUwY2QxZTg",58 "commit": {59 "author": {60 "name": "Mattias Wadman",61 "email": "mattias.wadman@gmail.com",62 "date": "2021-06-09T14:02:22Z"63 },64 "committer": {65 "name": "Nico Williams",66 "email": "nico@cryptonector.com",67 "date": "2022-05-26T21:04:32Z"68 },69 "message": "docs: Document repeat(exp)",70 "tree": {71 "sha": "d67d5542df1f16d1a48e1fb75749f60482cd874b",72 "url": "https://api.github.com/repos/jqlang/jq/git/trees/d67d5542df1f16d1a48e1fb75749f60482cd874b"73 },74 "url": "https://api.github.com/repos/jqlang/jq/git/commits/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",75 "comment_count": 0,76 "verification": {77 "verified": false,78 "reason": "unsigned",79 "signature": null,80 "payload": null81 }82 },83 "url": "https://api.github.com/repos/jqlang/jq/commits/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",84 "html_url": "https://github.com/jqlang/jq/commit/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",85 "comments_url": "https://api.github.com/repos/jqlang/jq/commits/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8/comments",86 "author": {87 ...8889 - text: |9091 We can use jq to extract just the first commit.9293 - command: "curl 'https://api.github.com/repos/jqlang/jq/commits?per_page=5' | jq '.[0]'"94 result: |95 {96 "sha": "cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",97 "node_id": "C_kwDOAE3WVdoAKGNmZjUzMzZlYzcxYjZmZWUzOTZhOTViYjBlNGJlYTM2NWUwY2QxZTg",98 "commit": {99 "author": {100 "name": "Mattias Wadman",101 "email": "mattias.wadman@gmail.com",102 "date": "2021-06-09T14:02:22Z"103 },104 "committer": {105 "name": "Nico Williams",106 "email": "nico@cryptonector.com",107 "date": "2022-05-26T21:04:32Z"108 },109 "message": "docs: Document repeat(exp)",110 "tree": {111 "sha": "d67d5542df1f16d1a48e1fb75749f60482cd874b",112 "url": "https://api.github.com/repos/jqlang/jq/git/trees/d67d5542df1f16d1a48e1fb75749f60482cd874b"113 },114 "url": "https://api.github.com/repos/jqlang/jq/git/commits/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",115 "comment_count": 0,116 "verification": {117 "verified": false,118 "reason": "unsigned",119 "signature": null,120 "payload": null121 }122 },123 "url": "https://api.github.com/repos/jqlang/jq/commits/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",124 "html_url": "https://github.com/jqlang/jq/commit/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8",125 "comments_url": "https://api.github.com/repos/jqlang/jq/commits/cff5336ec71b6fee396a95bb0e4bea365e0cd1e8/comments",126 "author": {127 "login": "wader",128 "id": 185566,129 "node_id": "MDQ6VXNlcjE4NTU2Ng==",130 "avatar_url": "https://avatars.githubusercontent.com/u/185566?v=4",131 "gravatar_id": "",132 "url": "https://api.github.com/users/wader",133 "html_url": "https://github.com/wader",134 "followers_url": "https://api.github.com/users/wader/followers",135 "following_url": "https://api.github.com/users/wader/following{/other_user}",136 "gists_url": "https://api.github.com/users/wader/gists{/gist_id}",137 "starred_url": "https://api.github.com/users/wader/starred{/owner}{/repo}",138 "subscriptions_url": "https://api.github.com/users/wader/subscriptions",139 "organizations_url": "https://api.github.com/users/wader/orgs",140 "repos_url": "https://api.github.com/users/wader/repos",141 "events_url": "https://api.github.com/users/wader/events{/privacy}",142 "received_events_url": "https://api.github.com/users/wader/received_events",143 "type": "User",144 "site_admin": false145 },146 "committer": {147 "login": "nicowilliams",148 "id": 604851,149 "node_id": "MDQ6VXNlcjYwNDg1MQ==",150 "avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",151 "gravatar_id": "",152 "url": "https://api.github.com/users/nicowilliams",153 "html_url": "https://github.com/nicowilliams",154 "followers_url": "https://api.github.com/users/nicowilliams/followers",155 "following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",156 "gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",157 "starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",158 "subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",159 "organizations_url": "https://api.github.com/users/nicowilliams/orgs",160 "repos_url": "https://api.github.com/users/nicowilliams/repos",161 "events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",162 "received_events_url": "https://api.github.com/users/nicowilliams/received_events",163 "type": "User",164 "site_admin": false165 },166 "parents": [167 {168 "sha": "f2ad9517c72f6267ae317639ab56bbfd4a8653d4",169 "url": "https://api.github.com/repos/jqlang/jq/commits/f2ad9517c72f6267ae317639ab56bbfd4a8653d4",170 "html_url": "https://github.com/jqlang/jq/commit/f2ad9517c72f6267ae317639ab56bbfd4a8653d4"171 }172 ]173 }174175 - text: |176177 For the rest of the examples, I'll leave out the `curl` command - it's not178 going to change.179180 There's a lot of info we don't care about there, so we'll restrict it down181 to the most interesting fields.182183 - command: "jq '.[0] | {message: .commit.message, name: .commit.committer.name}'"184 result: |185 {186 "message": "docs: Document repeat(exp)",187 "name": "Nico Williams"188 }189190 - text: |191192 The `|` operator in jq feeds the output of one filter (`.[0]` which gets193 the first element of the array in the response) into the input of another194 (`{...}` which builds an object out of those fields). You can access195 nested attributes, such as `.commit.message`.196197 Now let's get the rest of the commits.198199 - command: "jq '.[] | {message: .commit.message, name: .commit.committer.name}'"200 result: |201 {202 "message": "docs: Document repeat(exp)",203 "name": "Nico Williams"204 }205 {206 "message": "Mention -n in IO-section and for input/inputs",207 "name": "Nico Williams"208 }209 {

Fix typos (#3173)Nathan Baulchbefore adoption860af44

line 210why, one step back
210 "message": "Fix iteration problem for non decimal string\n\nWhen the string transformation to number failed, all following\ntransformation failed too.\n\nThis happend because status in decNumberFromString function is\nupdated just in error case. Reusing the DEC_CONTEXT that failed\nbefore results into error even if the string is valid number.",

Update NEWS.md with changes since 1.7 (#2948)Mattias Wadmanbefore adoptionc3b1496

lines 211–251why, one step back
211 "name": "Nico Williams"
212 }213 {214 "message": "docs: point to Libera.Chat instead of Freenode",215 "name": "Nico Williams"216 }217 {218 "message": "Missing \"va_end\" call. This was found by running the cppcheck static analysis where it shows as error.",219 "name": "Nico Williams"220 }221222 - text: |223224 `.[]` returns each element of the array returned in the response, one at a225 time, which are all fed into226 `{message: .commit.message, name: .commit.committer.name}`.227228 Data in jq is represented as streams of JSON values - every jq229 expression runs for each value in its input stream, and can230 produce any number of values to its output stream.231232 Streams are serialised by just separating JSON values with233 whitespace. This is a `cat`-friendly format - you can just join234 two JSON streams together and get a valid JSON stream.235236 If you want to get the output as a single array, you can tell jq to237 "collect" all of the answers by wrapping the filter in square238 brackets:239240 - command: "jq '[.[] | {message: .commit.message, name: .commit.committer.name}]'"241 result: |242 [243 {244 "message": "docs: Document repeat(exp)",245 "name": "Nico Williams"246 },247 {248 "message": "Mention -n in IO-section and for input/inputs",249 "name": "Nico Williams"250 },251 {

Fix typos (#3173)Nathan Baulchbefore adoption860af44

line 252why, one step back
252 "message": "Fix iteration problem for non decimal string\n\nWhen the string transformation to number failed, all following\ntransformation failed too.\n\nThis happend because status in decNumberFromString function is\nupdated just in error case. Reusing the DEC_CONTEXT that failed\nbefore results into error even if the string is valid number.",

Update NEWS.md with changes since 1.7 (#2948)Mattias Wadmanbefore adoptionc3b1496

lines 253–302why, one step back
253 "name": "Nico Williams"
254 },255 {256 "message": "docs: point to Libera.Chat instead of Freenode",257 "name": "Nico Williams"258 },259 {260 "message": "Missing \"va_end\" call. This was found by running the cppcheck static analysis where it shows as error.",261 "name": "Nico Williams"262 }263 ]264265 - text: |266267 - - -268269 Next, let's try getting the URLs of the parent commits out of the270 API results as well. In each commit, the GitHub API includes information271 about "parent" commits. There can be one or many.272273 "parents": [274 {275 "sha": "f2ad9517c72f6267ae317639ab56bbfd4a8653d4",276 "url": "https://api.github.com/repos/jqlang/jq/commits/f2ad9517c72f6267ae317639ab56bbfd4a8653d4",277 "html_url": "https://github.com/jqlang/jq/commit/f2ad9517c72f6267ae317639ab56bbfd4a8653d4"278 }279 ]280281 We want to pull out all of the "html_url" fields inside that array of parent282 commits and make a simple list of strings to go along with the283 "message" and "author" fields we already have.284285 - command: "jq '[.[] | {message: .commit.message, name: .commit.committer.name, parents: [.parents[].html_url]}]'"286 result: |287 [288 {289 "message": "docs: Document repeat(exp)",290 "name": "Nico Williams",291 "parents": [292 "https://github.com/jqlang/jq/commit/f2ad9517c72f6267ae317639ab56bbfd4a8653d4"293 ]294 },295 {296 "message": "Mention -n in IO-section and for input/inputs",297 "name": "Nico Williams",298 "parents": [299 "https://github.com/jqlang/jq/commit/c4d39c4d22f2b12225ca1b311708f7e084ad9ff8"300 ]301 },302 {

Fix typos (#3173)Nathan Baulchbefore adoption860af44

line 303why, one step back
303 "message": "Fix iteration problem for non decimal string\n\nWhen the string transformation to number failed, all following\ntransformation failed too.\n\nThis happend because status in decNumberFromString function is\nupdated just in error case. Reusing the DEC_CONTEXT that failed\nbefore results into error even if the string is valid number.",

Update NEWS.md with changes since 1.7 (#2948)Mattias Wadmanbefore adoptionc3b1496

lines 304–337why, one step back
304 "name": "Nico Williams",
305 "parents": [306 "https://github.com/jqlang/jq/commit/174db0f93552bdb551ae1f3c5c64744df0ad8e2f"307 ]308 },309 {310 "message": "docs: point to Libera.Chat instead of Freenode",311 "name": "Nico Williams",312 "parents": [313 "https://github.com/jqlang/jq/commit/29cf77977ef52eec708982b19bf9d2ec17443337"314 ]315 },316 {317 "message": "Missing \"va_end\" call. This was found by running the cppcheck static analysis where it shows as error.",318 "name": "Nico Williams",319 "parents": [320 "https://github.com/jqlang/jq/commit/55e6e2c21829bd866bd4b18ee254b05c9020320a"321 ]322 }323 ]324325 - text: |326327 Here we're making an object as before, but this time the `parents`328 field is being set to `[.parents[].html_url]`, which collects329 all of the parent commit URLs defined in the parents object.330331 - text: |332333 - - -334335 Here endeth the tutorial! There's lots more to play with. Go336 read [the manual](../manual/) if you're interested, and [download337 jq](../download/) if you haven't already.