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
Provenance
- Commit
f8d9478- Tree
590c31b- Author
Nicolas Williams <nico@cryptonector.com>- Committer
Nicolas Williams <nico@cryptonector.com>- Parent
1ba8c2c
1 file changed+85 added−0 removed
modified:docs/content/3.manual/manual.yml+85 added
159 unmodified lines160 161 Read filter from the file rather than from a command line, like162 awk's -f option. You can also use '#' to make comments.163 164+ * `-Ldirectory` / `-L directory`:165+166+ Add `directory` to the search list for modules. See the section167+ on modules below.168+169 * `-e` / `--exit-status`:170 171 Sets the exit status of jq to 0 if the last output values was172 neither `false` nor `null`, 1 if the last output value was2070 unmodified lines2243 that we did before:2244 2245 (.posts[] | select(.author == "stedolan") | .comments) |=2246 . + ["terrible."]2247+2248+ - title: Modules2249+ body: |2250+2251+ 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.2254+2255+ 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.2259+2260+ For paths starting with "~/", the user's home directory is2261+ substituted for "~".2262+2263+ 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.2266+2267+ 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").2272+2273+ 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.2278+2279+ The search path used is as follows:2280+2281+ - 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 variable2287+2288+ 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`.2291+2292+ entries:2293+ - title: "`module NAME {<metadata>};`"2294+ body: |2295+2296+ 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.2299+2300+ 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.2304+2305+ - title: "`import NAME {<metadata>};` `import NAME {<metadata>} as NAME;`"2306+ body: |2307+2308+ Imports a module named `NAME`. If the second form is used2309+ then the module's symbols are prefixed with "NAME::".2310+2311+ 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.2316+2317+ - title: "`modulemeta`"2318+ body: |2319+2320+ Takes a module name as input and outputs the module's2321+ metadata, with the module's imports (including metadata) as2322+ the "deps" key.2323+2324+ 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.