Skip to content
Myr

Add fixes for manual (#2391)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Benjamin Wuethrich · committed by GitHub · parent a87dca3 · Browse files · 1 file+57 added−46 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+57 added−46 removed

  • other:+57 added−46 removed

1 file+57 added−46 removed

modified:docs/content/manual/manual.yml+57 added-46 removed
3112 unmodified lines
31133114 entries:3115 - title: "Update-assignment: `|=`"3116 body: |3117 This is the "update" operator '|='. It takes a filter on the3117 This is the "update" operator `|=`. It takes a filter on the3118 right-hand side and works out the new value for the property3119 of `.` being assigned to by running the old value through this3120 expression. For instance, (.foo, .bar) |= .+1 will build an3121 object with the "foo" field set to the input's "foo" plus 1,3122 and the "bar" field set to the input's "bar" plus 1.3120 expression. For instance, `(.foo, .bar) |= .+1` will build an3121 object with the `foo` field set to the input's `foo` plus 1,3122 and the `bar` field set to the input's `bar` plus 1.31233124 The left-hand side can be any general path expression; see `path()`.31253126 Note that the left-hand side of '|=' refers to a value in `.`.3126 Note that the left-hand side of `|=` refers to a value in `.`.3127 Thus `$var.foo |= . + 1` won't work as expected (`$var.foo` is3128 not a valid or useful path expression in `.`); use `$var |3129 .foo |= . + 1` instead.3130
24 unmodified lines
3155 - title: "Plain assignment: `=`"3156 body: |31573158 This is the plain assignment operator. Unlike the others, the3159 input to the right-hand-side (RHS) is the same as the input to3160 the left-hand-side (LHS) rather than the value at the LHS3159 input to the right-hand side (RHS) is the same as the input to3160 the left-hand side (LHS) rather than the value at the LHS3161 path, and all values output by the RHS will be used (as shown3162 below).31633164 If the RHS of '=' produces multiple values, then for each such3164 If the RHS of `=` produces multiple values, then for each such3165 value jq will set the paths on the left-hand side to the value3166 and then it will output the modified `.`. For example,3167 `(.a,.b)=range(2)` outputs `{"a":0,"b":0}`, then3167 `(.a,.b) = range(2)` outputs `{"a":0,"b":0}`, then3168 `{"a":1,"b":1}`. The "update" assignment forms (see above) do3169 not do this.31703171 This example should show the difference between '=' and '|=':3171 This example should show the difference between `=` and `|=`:31723173 Provide input '{"a": {"b": 10}, "b": 20}' to the programs:3173 Provide input `{"a": {"b": 10}, "b": 20}` to the programs31743175 .a = .b31763177 and31783179 .a |= .b31803179 The former will set the "a" field of the input to the "b"3180 field of the input, and produce the output {"a": 20, "b": 20}.3181 The latter will set the "a" field of the input to the "a"3182 field's "b" field, producing {"a": 10, "b": 20}.3181 The former will set the `a` field of the input to the `b`3182 field of the input, and produce the output `{"a": 20, "b": 20}`.3183 The latter will set the `a` field of the input to the `a`3184 field's `b` field, producing `{"a": 10, "b": 20}`.31853184 Another example of the difference between '=' and '|=':3186 examples:3187 - program: .a = .b3188 input: '{"a": {"b": 10}, "b": 20}'3189 output: '{"a":20,"b":20}'31903186 null|(.a,.b)=range(3)3191 - program: .a |= .b3192 input: '{"a": {"b": 10}, "b": 20}'3193 output: '{"a":10,"b":20}'31943188 outputs '{"a":0,"b":0}', '{"a":1,"b":1}', and '{"a":2,"b":2}',3189 while3195 - program: (.a, .b) = range(3)3196 input: 'null'3197 output:3198 - '{"a":0,"b":0}'3199 - '{"a":1,"b":1}'3200 - '{"a":2,"b":2}'32013191 null|(.a,.b)|=range(3)3202 - program: (.a, .b) |= range(3)3203 input: 'null'3204 output: '{"a":0,"b":0}'32053193 outputs just '{"a":0,"b":0}'.31943206 - title: Complex assignments3207 body: |3208 Lots more things are allowed on the left-hand side of a jq assignment3209 than in most languages. We've already seen simple field accesses on
44 unmodified lines
3254 importer to alter this path.32553256 Paths in the a search path are subject to various substitutions.32573247 For paths starting with "~/", the user's home directory is3248 substituted for "~".3258 For paths starting with `~/`, the user's home directory is3259 substituted for `~`.32603250 For paths starting with "$ORIGIN/", the path of the jq executable3251 is substituted for "$ORIGIN".3261 For paths starting with `$ORIGIN/`, the path of the jq executable3262 is substituted for `$ORIGIN`.32633253 For paths starting with "./" or paths that are ".", the path of3254 the including file is substituted for ".". For top-level programs3264 For paths starting with `./` or paths that are `.`, the path of3265 the including file is substituted for `.`. For top-level programs3266 given on the command-line, the current directory is used.32673268 Import directives can optionally specify a search path to which3269 the default is appended.
4 unmodified lines
32743275 Null and empty string path elements terminate search path3276 processing.32773267 A dependency with relative path "foo/bar" would be searched for in3268 "foo/bar.jq" and "foo/bar/bar.jq" in the given search path. This3278 A dependency with relative path `foo/bar` would be searched for in3279 `foo/bar.jq` and `foo/bar/bar.jq` in the given search path. This3280 is intended to allow modules to be placed in a directory along3281 with, for example, version control files, README files, and so on,3282 but also to allow for single-file modules.32833284 Consecutive components with the same name are not allowed to avoid3274 ambiguities (e.g., "foo/foo").3285 ambiguities (e.g., `foo/foo`).32863287 For example, with `-L$HOME/.jq` a module `foo` can be found in3288 `$HOME/.jq/foo.jq` and `$HOME/.jq/foo/foo.jq`.32893279 If "$HOME/.jq" is a file, it is sourced into the main program.3290 If `$HOME/.jq` is a file, it is sourced into the main program.32913292 entries:3293 - title: "`import RelativePathString as NAME [<metadata>];`"3294 body: |32953296 Imports a module found at the given path relative to a3286 directory in a search path. A ".jq" suffix will be added to3297 directory in a search path. A `.jq` suffix will be added to3298 the relative path string. The module's symbols are prefixed3288 with "NAME::".3299 with `NAME::`.33003301 The optional metadata must be a constant jq expression. It3291 should be an object with keys like "homepage" and so on. At3292 this time jq only uses the "search" key/value of the metadata.3302 should be an object with keys like `homepage` and so on. At3303 this time jq only uses the `search` key/value of the metadata.3304 The metadata is also made available to users via the3305 `modulemeta` builtin.33063296 The "search" key in the metadata, if present, should have a3307 The `search` key in the metadata, if present, should have a3308 string or array value (array of strings); this is the search3309 path to be prefixed to the top-level search path.33103311 - title: "`include RelativePathString [<metadata>];`"3312 body: |33133314 Imports a module found at the given path relative to a3315 directory in a search path as if it were included in place. A3305 ".jq" suffix will be added to the relative path string. The3316 `.jq` suffix will be added to the relative path string. The3317 module's symbols are imported into the caller's namespace as3318 if the module's content had been included directly.33193320 The optional metadata must be a constant jq expression. It3310 should be an object with keys like "homepage" and so on. At3311 this time jq only uses the "search" key/value of the metadata.3321 should be an object with keys like `homepage` and so on. At3322 this time jq only uses the `search` key/value of the metadata.3323 The metadata is also made available to users via the3324 `modulemeta` builtin.33253326 - title: "`import RelativePathString as $NAME [<metadata>];`"3327 body: |33283329 Imports a JSON file found at the given path relative to a3319 directory in a search path. A ".json" suffix will be added to3330 directory in a search path. A `.json` suffix will be added to3331 the relative path string. The file's data will be available3332 as `$NAME::NAME`.33333334 The optional metadata must be a constant jq expression. It3324 should be an object with keys like "homepage" and so on. At3325 this time jq only uses the "search" key/value of the metadata.3335 should be an object with keys like `homepage` and so on. At3336 this time jq only uses the `search` key/value of the metadata.3337 The metadata is also made available to users via the3338 `modulemeta` builtin.33393329 The "search" key in the metadata, if present, should have a3340 The `search` key in the metadata, if present, should have a3341 string or array value (array of strings); this is the search3342 path to be prefixed to the top-level search path.33433344 - title: "`module <metadata>;`"
3 unmodified lines
3348 proper operation. It serves only the purpose of providing3349 metadata that can be read with the `modulemeta` builtin.33503351 The metadata must be a constant jq expression. It should be3341 an object with keys like "homepage". At this time jq doesn't3352 an object with keys like `homepage`. At this time jq doesn't3353 use this metadata, but it is made available to users via the3354 `modulemeta` builtin.33553356 - title: "`modulemeta`"3357 body: |33583359 Takes a module name as input and outputs the module's metadata3360 as an object, with the module's imports (including metadata)3350 as an array value for the "deps" key.3361 as an array value for the `deps` key.33623363 Programs can use this to query a module's metadata, which they3364 could then use to, for example, search for, download, and3365 install missing dependencies.
40 unmodified lines