Skip to content
Myr

Document module system

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

Fix #511.

authored by Nicolas Williams · committed by Nicolas Williams · parent 1ba8c2c · Browse files · 1 file+85 added−0 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+85 added−0 removed

  • other:+85 added−0 removed

1 file+85 added−0 removed

modified:docs/content/3.manual/manual.yml+85 added
159 unmodified lines
160161 Read filter from the file rather than from a command line, like162 awk's -f option. You can also use '#' to make comments.163164 * `-Ldirectory` / `-L directory`:165166 Add `directory` to the search list for modules. See the section167 on modules below.168169 * `-e` / `--exit-status`:170171 Sets the exit status of jq to 0 if the last output values was172 neither `false` nor `null`, 1 if the last output value was
2070 unmodified lines
2243 that we did before:22442245 (.posts[] | select(.author == "stedolan") | .comments) |=2246 . + ["terrible."]22472248 - title: Modules2249 body: |22502251 jq has a library/module system. Modules are files whose names end2252 in `.jq`. Modules should start with a `module` directive.2253 Programs and modules must `import` their dependencies, if any.22542255 A search path is used to search for modules. Each directory in2256 the search path is tested twice: once with a directory named "any"2257 added on the end, and once with the jq version number as a2258 directory added on the end.22592260 For paths starting with "~/", the user's home directory is2261 substituted for "~".22622263 For paths starting with "$ORIGIN/", the path of the directory of2264 the dependent is used. For main programs that's the path of the2265 jq executable's containing directory.22662267 Modules may be organized into a hierarchy, with name components2268 separated by double-colons ("::"). For example: "foo::bar". Each2269 component in the name corresponds to a directory on the2270 filesystem. Consecutive components with the same name are not2271 allowed to avoid ambiguities (e.g., "foo::foo").22722273 For example, a module named "foo::bar" would be searched for in2274 "foo/bar.jq" and "foo/bar/bar.jq" in the given search path. This2275 is intended to allow modules to be placed in a directory along2276 with, for example, version control files, README files, and so on,2277 but also to allow for single-file modules.22782279 The search path used is as follows:22802281 - the directory indicated in the search key of the `import`2282 directive metadata (see below)2283 - otherwise any directory(ies) listed in the `-L` command-line2284 argument2285 - otherwise any directory(ies) listed in the `$JQ_LIBRARY_PATH`2286 environment variable22872288 For example, with `-L$HOME/.jq` A module `foo` can be found in2289 `$HOME/.jq/any/foo.jq`, `$HOME/.jq/1.4/foo.jq`,2290 `$HOME/.jq/any/foo/foo.jq`, and in `$HOME/.jq/foo/foo.jq`.22912292 entries:2293 - title: "`module NAME {<metadata>};`"2294 body: |22952296 Defines a module named `NAME` with the given metadata. If2297 given it must be the first thing in the module. Programs also2298 may use this directive.22992300 The metadata must be a constant jq expression. It should be2301 an object with keys like "version", "repo", "URI", and so on.2302 At this time jq doesn't use this metadata, but it is made2303 available to users via the `modulemeta` builtin.23042305 - title: "`import NAME {<metadata>};` `import NAME {<metadata>} as NAME;`"2306 body: |23072308 Imports a module named `NAME`. If the second form is used2309 then the module's symbols are prefixed with "NAME::".23102311 The metadata must be a constant jq expression. It should be2312 an object with keys like "version", "repo", "URI", and so on.2313 2314 The "search" key in the metadata, if present, should have a2315 string value consisting of a single directory path to search.23162317 - title: "`modulemeta`"2318 body: |23192320 Takes a module name as input and outputs the module's2321 metadata, with the module's imports (including metadata) as2322 the "deps" key.23232324 Programs can use this to query a module's metadata, which they2325 could then use to, for example, search for, download, and2326 install missing dependencies.