@ai-ecoverse/slicc-man 0.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +179 -5
- package/host/cache.mjs +43 -0
- package/host/io.mjs +15 -0
- package/host/main.mjs +54 -0
- package/host/pager.mjs +38 -0
- package/host/path.mjs +33 -0
- package/host/scman.mjs +14 -0
- package/host/upgrade.mjs +93 -0
- package/lib/man.mjs +215 -0
- package/lib/markdown.mjs +456 -0
- package/lib/options.mjs +192 -0
- package/lib/render.mjs +214 -0
- package/lib/search.mjs +83 -0
- package/lib/site.mjs +205 -0
- package/package.json +47 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,9 +1,183 @@
|
|
|
1
|
-
#
|
|
1
|
+
# slicc-man
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`man`, `apropos` and `whatis` for SLICC, and `scman` for SLICC, macOS, Linux and Windows. They show the pages www.sliccy.com already serves: a page is the Markdown at `https://www.sliccy.com/man/<topic>.md`, the topics are the `/man/*` entries of [`sitemap.xml`](https://www.sliccy.com/sitemap.xml), and a page's one-line description is its first paragraph. The package renders the Markdown itself, so it needs no `man`, groff or mandoc on the host, and keeps what it fetched in an [offline cache](#offline-cache).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
In SLICC, the commands are `man`, `apropos`, `whatis` and `scman`, which is `man` under another name. On a host only `scman` is installed, so the host's own `man` is never shadowed.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
In SLICC, the package declares its commands in `slicc.commands`, so installing it puts them in `/usr/bin`:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pnpm add -g @ai-ecoverse/slicc-man
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
On macOS and Linux (get.sliccy.ai, once live):
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
curl -fsSL https://get.sliccy.ai/man | sh
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
On Windows, in PowerShell (get.sliccy.ai, once live):
|
|
22
|
+
|
|
23
|
+
```powershell
|
|
24
|
+
irm https://get.sliccy.ai/man.ps1 | iex
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The same installers are attached to every GitHub release, as `install.sh` and `install.ps1`:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
curl -fsSL https://github.com/ai-ecoverse/slicc-man/releases/latest/download/install.sh | sh
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
They install the release's `scman` with a launcher in `~/.local/bin` (on Windows `%LOCALAPPDATA%\slicc-man\bin`, added to the user's `PATH`), and download Node 24 into the install when no Node 24 or later is on `PATH` (the `.tar.gz`, or the `.zip` on Windows), checked against nodejs.org's `SHASUMS256.txt`. Each release also carries the package tarball, `slicc-man-<version>.tgz`, and `SHA256SUMS`, which covers the tarball, `install.sh` and `install.ps1`: the installers check the tarball against it, unpack it into `${XDG_DATA_HOME:-~/.local/share}/slicc-man/<version>` (on Windows `%LOCALAPPDATA%\slicc-man\<version>`), write the launcher (`scman`, or `scman.ps1` and `scman.cmd` on Windows, which only start `node.exe` with the entry script and the arguments, the node call and its `exit` on one line of the `.cmd`), run it with `--version` (the version alone, or `scman <version>` from older releases), and print `scman <version> installed to <launcher>`. Options pass through (`curl -fsSL https://get.sliccy.ai/man | sh -s -- --help`): `--version <version>` installs that release instead of the latest, `--dir <dir>` puts the launcher in `<dir>`, and `--help` prints the usage; `install.sh` exits 2 for an unknown option or one without its value. `install.ps1` takes the same options, spelled `-Version`, `-Dir` and `-Help`. `SLICC_INSTALL_BASE_URL` replaces the directory the assets are downloaded from (by default `https://github.com/ai-ecoverse/slicc-man/releases/latest/download`, or `…/releases/download/v<version>` with `--version`), and `SLICC_NODE_DIST_BASE` nodejs.org, for mirrors and tests.
|
|
34
|
+
|
|
35
|
+
On a machine with Node 24 or later, npm works too:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm install -g @ai-ecoverse/slicc-man
|
|
39
|
+
scman tree
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
or without installing, `npx -p @ai-ecoverse/slicc-man scman tree`. The package's `bin` has only `scman`.
|
|
43
|
+
|
|
44
|
+
## man
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
man [options] [section] topic...
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`man tree` shows the tree page. With several topics, `man` shows each in turn. A topic is looked up in lower case; `topic(1)` is the same as `1 topic`. When the first of two or more operands is a section name (a digit, or a digit and letters, as `3p`), it is the section. Every page is in section 1: a page asked for in any other section prints `No manual entry for <topic> in section <n>` to stderr, and with `-s`, the list as given. A topic that isn't a page name (empty, starting with `.`, or with anything but letters, digits, `.`, `_`, `+` and `-`) has no page, and nothing is fetched for it.
|
|
51
|
+
|
|
52
|
+
| option | does |
|
|
53
|
+
| --- | --- |
|
|
54
|
+
| `-s <list>`, `--sections=<list>` | the sections to look in, separated by `:` or `,` |
|
|
55
|
+
| `-k`, `--apropos` | `apropos` with the operands as keywords |
|
|
56
|
+
| `-f`, `--whatis` | `whatis` with the operands as topics |
|
|
57
|
+
| `-a`, `--all` | show every matching page; there is only ever one, so it changes nothing |
|
|
58
|
+
| `-w`, `--where`, `--path`, `--location` | print the page's URL, `https://www.sliccy.com/man/<topic>.md`, instead of showing it |
|
|
59
|
+
| `-P <pager>`, `--pager=<pager>` | the pager (see [Rendering](#rendering)) |
|
|
60
|
+
| `-l`, `--local-file` | render the operands, local Markdown files (`-` for stdin), as pages; the page's name is the file's, without `.md`, and `stdin` for `-` |
|
|
61
|
+
| `-i`, `--ignore-case` | the default |
|
|
62
|
+
| `-I`, `--match-case` | look the topic up as typed, not in lower case |
|
|
63
|
+
| `--nh`, `--no-hyphenation`, `--nj`, `--no-justification` | accepted; the renderer neither hyphenates nor justifies |
|
|
64
|
+
| `-h`, `--help` | the usage to stdout, exit 0 |
|
|
65
|
+
| `-V`, `--version` | the version alone (`1.2.0`) to stdout, exit 0; every host command takes it, and the installer runs the launcher with it |
|
|
66
|
+
| `--upgrade` | see [`--upgrade`](#--upgrade) |
|
|
67
|
+
|
|
68
|
+
Short options may be grouped (`-aw`). An option's value may be attached (`-s1`, `-Pcat`, `--pager=cat`) or the next argument; options may come after the operands, and `--` ends the options. Of `-k` and `-f`, the last one given counts, and so for `-i` and `-I`. With `-k` or `-f`, the operands are matched with `apropos`'s and `whatis`'s defaults, and only `-s` of the other options counts. `man` with no topic prints `What manual page do you want?` and `For example, try 'man man'.` to stderr and exits 2.
|
|
69
|
+
|
|
70
|
+
## apropos and whatis
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
apropos [options] keyword...
|
|
74
|
+
whatis [options] topic...
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`apropos` searches the topics and descriptions, `whatis` the topics only. Each match is a line like man-db's: the topic and ` (1)` padded to 20 columns, ` - `, and the description, as in `tree (1) - List contents of directories in a tree-like format.` Matches come in the sitemap's order, each once, and are case-insensitive.
|
|
78
|
+
|
|
79
|
+
| option | `apropos` | `whatis` |
|
|
80
|
+
| --- | --- | --- |
|
|
81
|
+
| none | each keyword is a regular expression (JavaScript syntax) matched anywhere in a topic or description | each topic must be a page name exactly |
|
|
82
|
+
| `-r`, `--regex` | the default | the topic is a regular expression matched anywhere in a page name |
|
|
83
|
+
| `-w`, `--wildcard` | each keyword is a shell wildcard (`*`, `?`, `[…]`) matched against a whole topic or a whole word of a description | the topic is a wildcard matched against a whole page name |
|
|
84
|
+
| `-e`, `--exact` | each keyword must be a whole topic or a whole word of a description | the default |
|
|
85
|
+
| `-a`, `--and` | a page must match every keyword, not any one | not taken |
|
|
86
|
+
| `-l`, `--long` | don't cut lines to the terminal width | the same |
|
|
87
|
+
| `-s <list>`, `--sections=<list>` | only those sections; without 1, nothing matches | the same |
|
|
88
|
+
| `-h`, `-V`, `--upgrade` | as for `man` | the same |
|
|
89
|
+
|
|
90
|
+
On a terminal, a line wider than the width (see [Rendering](#rendering)) is cut and ends in `...`; through a pipe it is whole. A keyword with no match prints `<keyword>: nothing appropriate.` to stderr. With `-a`, that is printed for the keywords together, when no page matches them all. A regular expression that doesn't parse is a usage error, `<cmd>: <keyword>: invalid regular expression`. With no keyword, `apropos` prints `apropos what?` (`whatis`: `whatis what?`) to stderr and exits 2; `man -k` and `man -f` do the same.
|
|
91
|
+
|
|
92
|
+
## Not supported
|
|
93
|
+
|
|
94
|
+
These man-db options can't work here. They print `<cmd>: <option>: not supported` to stderr and exit 2, before anything is fetched:
|
|
95
|
+
|
|
96
|
+
- **man:** `-t`/`--troff`, `-T`/`--troff-device`, `-H`/`--html`, `-X`/`--gxditview`, `-Z`/`--ditroff`, `-M`/`--manpath`, `-m`/`--systems`, `-L`/`--locale`, `-C`/`--config-file`, `-d`/`--debug`, `-D`/`--default`, `-W`/`--where-cat`, `-c`/`--catman`, `-u`/`--update`, `-e`/`--extension`, `-p`/`--preprocessor`, `-R`/`--recode`, `-E`/`--encoding`, `-K`/`--global-apropos`, `-r`/`--prompt`, `--regex`, `--wildcard`, `--names-only`, `--no-subpages`.
|
|
97
|
+
- **apropos, whatis:** `-M`/`--manpath`, `-m`/`--systems`, `-L`/`--locale`, `-C`/`--config-file`, `-d`/`--debug`, `-v`/`--verbose`.
|
|
98
|
+
|
|
99
|
+
Any other option, or an option without its value, prints `<cmd>: unknown option: <option>` (or `<cmd>: <option>: needs a value`) and the usage to stderr, and exits 2. So does `--upgrade` with anything else, as `<cmd>: --upgrade takes no other arguments`.
|
|
100
|
+
|
|
101
|
+
## Exit codes
|
|
102
|
+
|
|
103
|
+
| code | means |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| 0 | done |
|
|
106
|
+
| 1 | `--upgrade` on a host, when the installer fails |
|
|
107
|
+
| 2 | a usage error (`man` with no topic included), an option that isn't supported, or an operational error: the site unreachable with nothing cached, a pager that can't be run, a file `-l` can't read |
|
|
108
|
+
| 16 | at least one topic has no page, or one keyword matched nothing |
|
|
109
|
+
|
|
110
|
+
`man nope` prints `No manual entry for nope` to stderr and exits 16. With several topics, the others are still shown. `-w` exits 16 for a topic with no page too, printing the URLs of the others.
|
|
111
|
+
|
|
112
|
+
## Rendering
|
|
113
|
+
|
|
114
|
+
A page is turned from Markdown into a man page:
|
|
115
|
+
|
|
116
|
+
- **Header:** `TOPIC(1)`, `SLICC Manual` centred, `TOPIC(1)`, then a blank line.
|
|
117
|
+
- **NAME:** the first paragraph becomes `topic - description`, under `NAME`.
|
|
118
|
+
- **Sections:** each `##` heading is a section heading in capitals at the left margin (`## See Also` becomes `SEE ALSO`), and `###` a subheading indented 3 columns. The body is indented 7 columns and wrapped at the width.
|
|
119
|
+
- **Text:** `**strong**` and `` `code` `` are bold, `*emphasis*` and `_emphasis_` underlined. A link shows its text only, an image its alt text. Lists keep their marker with the item's lines hanging after it. Code blocks and tables are kept line for line, indented and never wrapped.
|
|
120
|
+
- **Escapes:** a backslash before ASCII punctuation is dropped, as Markdown does, which undoes the site's `\[`, `\<` and `\--`; inside code it stays.
|
|
121
|
+
- **Metadata:** the trailing table whose first row is `Metadata` is dropped.
|
|
122
|
+
- **Control characters:** none from a page reaches the terminal; they are dropped, except tabs, which become spaces.
|
|
123
|
+
|
|
124
|
+
The width is `MANWIDTH` when it is a positive number, else the terminal's width when stdout is a terminal, else 80.
|
|
125
|
+
|
|
126
|
+
When stdout is a terminal, bold and underline are ANSI escapes (`ESC[1m`, `ESC[4m`), unless `NO_COLOR` is set and not empty, and the page goes through a pager: `-P`, else `MANPAGER`, else `PAGER`, else `less -R` when `less` is on `PATH`, else straight to stdout. The pager is a command line run by the shell (`sh -c`, `cmd /c` on Windows), with the page on its stdin; an empty one means straight to stdout. A pager that exits non-zero doesn't change the exit code; one that can't be run is exit 2. When stdout isn't a terminal, the page is plain text, with no escapes and no pager. `apropos` and `whatis` never use a pager.
|
|
127
|
+
|
|
128
|
+
## Offline cache
|
|
129
|
+
|
|
130
|
+
Pages, the sitemap and the topic index are cached:
|
|
131
|
+
|
|
132
|
+
- on a host in `$XDG_CACHE_HOME/slicc-man`, by default `~/.cache/slicc-man`, and on Windows in `%LOCALAPPDATA%\slicc-man\cache`;
|
|
133
|
+
- in SLICC in `~/.cache/slicc-man`, which lives in OPFS, so it survives reloads.
|
|
134
|
+
|
|
135
|
+
Each site has its own directory in the cache, named by the base URL's host and port (`www.sliccy.com`, `127.0.0.1-8080`), with one JSON file per page, `sitemap.json` and `index.json`. A cached copy is fresh for the response's `Cache-Control` `max-age` (the site sends 4 hours), and 4 hours without one. A stale copy is revalidated with `If-Modified-Since` (the response's `Last-Modified`): `304` keeps it and makes it fresh again, `200` replaces it, and `404` drops it, so the topic has no page. When the site can't be reached, or answers 5xx, a cached copy is shown however old, after one line on stderr, `<cmd>: <url>: <reason>; showing the copy cached <date>`. With nothing cached, the command prints `<cmd>: <url>: <reason>` and exits 2. The cache is written atomically (a temporary file renamed into place), so two commands at once never see half a page; a cache that can't be written is skipped without a word.
|
|
136
|
+
|
|
137
|
+
`apropos` and `whatis` read the index: every `/man/<topic>` entry of the sitemap, with its description, the first paragraph of its page, rendered as plain text on one line. The index is built from the cached sitemap and pages, fetching what is missing or stale (pages through the same cache, several at a time), and cached itself under the same rules. A page that fails to load is listed without a description.
|
|
138
|
+
|
|
139
|
+
`SLICC_MAN_URL` overrides the base URL `https://www.sliccy.com`: pages are `$SLICC_MAN_URL/man/<topic>.md` and the sitemap `$SLICC_MAN_URL/sitemap.xml`, whose entries count by their path, whatever their host. The tests point it at a local server.
|
|
140
|
+
|
|
141
|
+
## Fallback
|
|
142
|
+
|
|
143
|
+
In SLICC only: when a topic has no page and is a command on `PATH`, `man` prints `No manual entry for <topic>; showing <topic> --help` to stderr, then the output of `<topic> --help` (stdout and stderr together, as plain text, through the pager when stdout is a terminal), and that topic counts as found, so `man` can exit 0. seven's own commands often have no page yet. The fallback doesn't apply to a section other than 1, `-w`, `-k`, `-f` or `-l`. On a host there is no fallback; the host has its own `man`.
|
|
144
|
+
|
|
145
|
+
## `--upgrade`
|
|
146
|
+
|
|
147
|
+
Every host command takes `--upgrade`. It runs the latest release's installer (`install.sh`, or `install.ps1` on Windows) with `--dir` set to the directory the command is installed in, so the new version replaces the old one in place, then prints `<cmd>: <old> → <new>` (for example `scman: 1.2.0 → 1.3.0`), or `<cmd>: already up to date (<version>)`, to stdout and exits 0. If the installer fails, its stderr is passed through and the command exits 1. A command installed with npm prints `npm install -g @ai-ecoverse/slicc-man@latest` to run instead, and exits 0. In SLICC, `--upgrade` prints `pnpm add -g @ai-ecoverse/slicc-man@latest` to run, and exits 0; it installs nothing itself. `--upgrade` takes no other arguments.
|
|
148
|
+
|
|
149
|
+
The commands are `scman` on a host and `man`, `apropos`, `whatis` and `scman` in SLICC.
|
|
150
|
+
|
|
151
|
+
The launcher the installer writes sets `SCMAN_INSTALL_DIR` to its own directory; that is how `scman` knows the installer put it there (it removes the variable before it starts a pager or the installer), and without it `scman` counts as installed with npm. The installer is downloaded from `https://github.com/ai-ecoverse/slicc-man/releases/latest/download/` and run as `sh install.sh --dir DIR`, or `powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File install.ps1 -Dir DIR` (else `pwsh.exe`); the line it prints, `scman <version> installed to <launcher>`, names the new version. A download that fails is the installer failing: `<cmd>: could not download <url>: <reason>`, exit 1. The download has 60 seconds; after that `--upgrade` prints `<cmd>: download timed out` to stderr and exits 1. `SLICC_INSTALL_BASE_URL`, when set, replaces that release URL for `--upgrade` and for the installers' own downloads.
|
|
152
|
+
|
|
153
|
+
## Platforms
|
|
154
|
+
|
|
155
|
+
| platform | commands | cache | pager | network |
|
|
156
|
+
| --- | --- | --- | --- | --- |
|
|
157
|
+
| SLICC | `man`, `apropos`, `whatis`, `scman` | `~/.cache/slicc-man`, in OPFS | `less -R` (seven's `less`) | the kernel's network transport |
|
|
158
|
+
| macOS | `scman` | `$XDG_CACHE_HOME/slicc-man`, else `~/.cache/slicc-man` | `less -R` | direct HTTPS |
|
|
159
|
+
| Linux | `scman` | `$XDG_CACHE_HOME/slicc-man`, else `~/.cache/slicc-man` | `less -R` when installed, else stdout | direct HTTPS |
|
|
160
|
+
| Windows | `scman` | `%LOCALAPPDATA%\slicc-man\cache` | `less -R` when on `PATH` (Git for Windows has one), else stdout | direct HTTPS |
|
|
161
|
+
|
|
162
|
+
`scman -k` and `scman -f` are its `apropos` and `whatis`. Other Unix systems are treated as Linux.
|
|
163
|
+
|
|
164
|
+
## Development
|
|
165
|
+
|
|
166
|
+
```sh
|
|
167
|
+
npm install
|
|
168
|
+
npm run lint
|
|
169
|
+
npm test
|
|
170
|
+
npm run test:unit
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
- `npm run lint`: Biome, the no-comment check and the other [slicc-shared-web](https://github.com/ai-ecoverse/slicc-shared-web) checks, then `shellcheck -s sh` and `dash -n` on `install.sh`.
|
|
174
|
+
- `npm test`: the integration tests in `test/integration/`. `host.test.mjs` runs `scman` (in-process, so a terminal can be faked, and as `host/scman.mjs`) against a local HTTP server on an ephemeral port standing in for www.sliccy.com (`SLICC_MAN_URL`), serving copies of the site's `tree.md` and `man.md` (`pages.json`, with their expected renderings), with a temporary cache and fake tools, `less` among them, on a temporary `PATH`; only CI touches the real site. `install.test.mjs` runs `install.sh` on a tarball packed from the tree, with the Node on `PATH` and with a Node download from a fake nodejs.org, and `--upgrade` against a release served from a local server; `install.ps1` is checked statically, and run when `pwsh` is on `PATH`. `repo.test.mjs` checks the workflow, the release config, the package's shape, what `npm pack` ships and the repo rules.
|
|
175
|
+
- `npm run test:unit`: the unit tests in the gitignored `test/unit/`, with Node's coverage in `coverage/unit/lcov.info`. The pre-commit hook wants 100% coverage of the changed lines.
|
|
176
|
+
|
|
177
|
+
CI is `.github/workflows/ci.yml`, the only workflow, which runs [slicc-shared-web's pipeline](https://github.com/ai-ecoverse/slicc-shared-web#pipeline) at the devDependency's version, on Linux only: `npm run lint`, then `npm test`, then on a pull request the Claude and Codex reviews. The merge queue requires `ci / integration` and `ci / review`. On a push to `main`, semantic-release releases and publishes to npm through trusted publishing, with provenance from `ci.yml`, and attaches `slicc-man-<version>.tgz`, `SHA256SUMS`, `install.sh` and `install.ps1` to the GitHub release (`scripts/assets.mjs` renames the tarball and writes `SHA256SUMS`).
|
|
178
|
+
|
|
179
|
+
The code is in `lib/` (options, the Markdown renderer, the cache and index, apropos and whatis, shared with SLICC) and `host/` (`scman.mjs`, the cache directory, the pager, `--upgrade`).
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
Apache-2.0
|
package/host/cache.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { isAbsolute, join } from 'node:path';
|
|
4
|
+
import { variable } from './path.mjs';
|
|
5
|
+
|
|
6
|
+
export function cacheRoot(platform, env) {
|
|
7
|
+
if (platform === 'win32') {
|
|
8
|
+
const local = variable(env, 'LOCALAPPDATA') || join(homedir(), 'AppData', 'Local');
|
|
9
|
+
return join(local, 'slicc-man', 'cache');
|
|
10
|
+
}
|
|
11
|
+
const xdg = env.XDG_CACHE_HOME;
|
|
12
|
+
if (xdg && isAbsolute(xdg)) return join(xdg, 'slicc-man');
|
|
13
|
+
return join(env.HOME || homedir(), '.cache', 'slicc-man');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let counter = 0;
|
|
17
|
+
|
|
18
|
+
export function store(dir) {
|
|
19
|
+
const file = (id) => join(dir, `${id}.json`);
|
|
20
|
+
return {
|
|
21
|
+
async read(id) {
|
|
22
|
+
try {
|
|
23
|
+
return await readFile(file(id), 'utf8');
|
|
24
|
+
} catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
async write(id, text) {
|
|
29
|
+
await mkdir(dir, { recursive: true });
|
|
30
|
+
const temp = join(dir, `.${id}.${process.pid}.${Date.now()}.${counter++}.tmp`);
|
|
31
|
+
try {
|
|
32
|
+
await writeFile(temp, text);
|
|
33
|
+
await rename(temp, file(id));
|
|
34
|
+
} catch (error) {
|
|
35
|
+
await rm(temp, { force: true });
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
async remove(id) {
|
|
40
|
+
await rm(file(id), { force: true });
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
package/host/io.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { writeSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
export function say(fd, text) {
|
|
4
|
+
const data = Buffer.from(text);
|
|
5
|
+
let at = 0;
|
|
6
|
+
while (at < data.length) {
|
|
7
|
+
try {
|
|
8
|
+
at += writeSync(fd, data, at, data.length - at);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (error.code === 'EAGAIN') continue;
|
|
11
|
+
if (error.code === 'EPIPE') return;
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
package/host/main.mjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { run } from '../lib/man.mjs';
|
|
4
|
+
import { cacheRoot, store } from './cache.mjs';
|
|
5
|
+
import { say } from './io.mjs';
|
|
6
|
+
import { page } from './pager.mjs';
|
|
7
|
+
import { lookup } from './path.mjs';
|
|
8
|
+
import { upgrade, version } from './upgrade.mjs';
|
|
9
|
+
|
|
10
|
+
const reasons = {
|
|
11
|
+
ENOENT: 'No such file or directory',
|
|
12
|
+
EACCES: 'Permission denied',
|
|
13
|
+
EISDIR: 'Is a directory',
|
|
14
|
+
ENOTDIR: 'Not a directory',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function read(file, fds) {
|
|
18
|
+
try {
|
|
19
|
+
return readFileSync(file === '-' ? fds[0] : file, 'utf8');
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw new Error(reasons[error.code] ?? error.message);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function main({
|
|
26
|
+
name,
|
|
27
|
+
argv,
|
|
28
|
+
env,
|
|
29
|
+
platform,
|
|
30
|
+
fds,
|
|
31
|
+
tty,
|
|
32
|
+
columns,
|
|
33
|
+
fetch = globalThis.fetch,
|
|
34
|
+
now,
|
|
35
|
+
}) {
|
|
36
|
+
const child = { ...env };
|
|
37
|
+
delete child.SCMAN_INSTALL_DIR;
|
|
38
|
+
const root = cacheRoot(platform, env);
|
|
39
|
+
const io = {
|
|
40
|
+
tty,
|
|
41
|
+
columns,
|
|
42
|
+
fetch,
|
|
43
|
+
now,
|
|
44
|
+
version: version(),
|
|
45
|
+
out: (text) => say(fds[1], text),
|
|
46
|
+
err: (text) => say(fds[2], text),
|
|
47
|
+
store: (dir) => store(join(root, dir)),
|
|
48
|
+
which: (file) => lookup(file, platform, env) !== undefined,
|
|
49
|
+
page: (command, text) => page(command, text, { name, platform, env: child, fds }),
|
|
50
|
+
read: (file) => read(file, fds),
|
|
51
|
+
upgrade: () => upgrade({ name, env, platform, fds, fetch }),
|
|
52
|
+
};
|
|
53
|
+
return run({ kind: 'man', name, argv, env, io });
|
|
54
|
+
}
|
package/host/pager.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { say } from './io.mjs';
|
|
3
|
+
import { variable } from './path.mjs';
|
|
4
|
+
|
|
5
|
+
export function shell(command, platform, env) {
|
|
6
|
+
if (platform === 'win32') {
|
|
7
|
+
return {
|
|
8
|
+
file: variable(env, 'COMSPEC') || 'cmd.exe',
|
|
9
|
+
args: ['/d', '/s', '/c', `"${command}"`],
|
|
10
|
+
options: { windowsVerbatimArguments: true },
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return { file: '/bin/sh', args: ['-c', command], options: {} };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function page(command, text, { name, platform, env, fds }) {
|
|
17
|
+
const run = shell(command, platform, env);
|
|
18
|
+
const ignore = () => {};
|
|
19
|
+
process.on('SIGINT', ignore);
|
|
20
|
+
return new Promise((done) => {
|
|
21
|
+
let failed = false;
|
|
22
|
+
const child = spawn(run.file, run.args, {
|
|
23
|
+
...run.options,
|
|
24
|
+
env,
|
|
25
|
+
stdio: ['pipe', fds[1], fds[2]],
|
|
26
|
+
});
|
|
27
|
+
child.on('error', (error) => {
|
|
28
|
+
failed = true;
|
|
29
|
+
say(fds[2], `${name}: ${command}: ${error.message}\n`);
|
|
30
|
+
});
|
|
31
|
+
child.stdin.on('error', ignore);
|
|
32
|
+
child.stdin.end(text);
|
|
33
|
+
child.on('close', (code) => {
|
|
34
|
+
process.off('SIGINT', ignore);
|
|
35
|
+
done(failed || code === 126 || code === 127 ? 2 : 0);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
package/host/path.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { accessSync, constants, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export function variable(env, name) {
|
|
5
|
+
const found = Object.keys(env).find((key) => key.toUpperCase() === name);
|
|
6
|
+
return found === undefined ? undefined : env[found];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function lookup(file, platform, env) {
|
|
10
|
+
const windows = platform === 'win32';
|
|
11
|
+
const dirs = String((windows ? variable(env, 'PATH') : env.PATH) ?? '')
|
|
12
|
+
.split(windows ? ';' : ':')
|
|
13
|
+
.filter(Boolean);
|
|
14
|
+
const exts = windows
|
|
15
|
+
? [
|
|
16
|
+
'',
|
|
17
|
+
...String(variable(env, 'PATHEXT') || '.COM;.EXE;.BAT;.CMD')
|
|
18
|
+
.split(';')
|
|
19
|
+
.filter(Boolean),
|
|
20
|
+
]
|
|
21
|
+
: [''];
|
|
22
|
+
for (const dir of dirs) {
|
|
23
|
+
for (const ext of exts) {
|
|
24
|
+
const path = join(dir, file + ext);
|
|
25
|
+
try {
|
|
26
|
+
if (!statSync(path).isFile()) continue;
|
|
27
|
+
if (!windows) accessSync(path, constants.X_OK);
|
|
28
|
+
return path;
|
|
29
|
+
} catch {}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
package/host/scman.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { isatty } from 'node:tty';
|
|
3
|
+
import { main } from './main.mjs';
|
|
4
|
+
|
|
5
|
+
const tty = isatty(1);
|
|
6
|
+
process.exitCode = await main({
|
|
7
|
+
name: 'scman',
|
|
8
|
+
argv: process.argv.slice(2),
|
|
9
|
+
env: process.env,
|
|
10
|
+
platform: process.platform,
|
|
11
|
+
fds: [0, 1, 2],
|
|
12
|
+
tty,
|
|
13
|
+
columns: tty ? process.stdout.columns : undefined,
|
|
14
|
+
});
|