prolog-notebook 0.6.3 → 0.6.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.4] — 2026-08-31
4
+
5
+ ### Changed
6
+
7
+ - **`prolog-notebook <command> --help` answers about that command only.** It printed the whole
8
+ card — all five commands — which makes the reader find their command again in a page they did
9
+ not ask for. What works anywhere is still listed, because it is as true of the command they
10
+ asked about as of any other, and the note about a stopped search now travels with `--limit`
11
+ rather than sitting under everything.
12
+
13
+ It works wherever the command is named: `view --help`, `--help view`, and
14
+ `view chapter.prolog.md -h` all ask the same question, as do the `run` and `exec` aliases.
15
+ Name no command, or one that does not exist, and the whole card comes back as before.
16
+
17
+ - **The help, the per-command help and the misplaced-option message are derived from one
18
+ table.** They were three lists kept by hand, which is how the help came to advertise
19
+ `--check-update` under no command while three of the four commands refused it.
20
+
3
21
  ## [0.6.3] — 2026-08-30
4
22
 
5
23
  `prolog-notebook build lists.prolog.md --check-update` answered *unknown option* — on a flag the
package/README.md CHANGED
@@ -149,7 +149,7 @@ Three work anywhere, because they are about the tool rather than about a noteboo
149
149
  |---|---|
150
150
  | `--version` | the tool's version, **the SWI-Prolog version it will run your chapters with**, and the copyright |
151
151
  | `--check-update` | ask npm whether a newer one exists, and say so either way — forced, whatever the daily check thinks, and answered even down a pipe |
152
- | `-h`, `--help` | the same list, from the command itself |
152
+ | `-h`, `--help` | help for the command you named, or all of them if you named none |
153
153
 
154
154
  ```sh
155
155
  prolog-notebook upgrade # fetch the latest
@@ -38,57 +38,112 @@ for (const stream of [process.stdout, process.stderr]) {
38
38
  const require = createRequire(import.meta.url);
39
39
 
40
40
  /**
41
- * EACH OPTION UNDER THE COMMAND THAT TAKES IT (869erqra0).
41
+ * THE COMMANDS, AND WHAT EACH ONE TAKES one table, three readers (869erqra0).
42
42
  *
43
- * They were listed in one flat `Options` block with no owner, which reads as a
44
- * promise that every one of them works everywhere so `build --check-update`
45
- * was a reasonable thing to type and `unknown option` was a strange thing to be
46
- * told. Only three of them are actually the tool's rather than a command's, and
47
- * now only those three are listed as such.
43
+ * The whole help, a single command's help, and the message a misplaced option
44
+ * gets are all derived from here. They were three lists kept by hand, which is
45
+ * how the help came to advertise flags that no command accepted.
46
+ *
47
+ * Options belong to COMMANDS, not to the tool. Listing them in one flat block
48
+ * reads as a promise that every one works everywhere, and only three of them do.
48
49
  */
49
- const USAGE = `prolog-notebook — Jupyter-style notebooks for Prolog
50
-
51
- prolog-notebook view <file.prolog.md> read it in a browser, cells and all
52
- --port <n> what it listens on (default 8777)
53
- --no-open print the URL instead of opening a browser
54
-
55
- prolog-notebook build <file.prolog.md> write a page you can host or send
56
- --out <dir> where it writes (default: <file>-site)
57
-
58
- prolog-notebook execute <file.prolog.md>... run every query, write the answers in
59
- --limit <n> solutions to take from one query before stopping (default ${DEFAULT_LIMIT})
60
- --stdout print the result instead of writing the file
61
- --quiet report only failures
50
+ const COMMANDS = {
51
+ view: {
52
+ usage: 'prolog-notebook view <file.prolog.md>',
53
+ blurb: 'read it in a browser, cells and all',
54
+ options: [
55
+ ['--port <n>', 'what it listens on (default 8777)'],
56
+ ['--no-open', 'print the URL instead of opening a browser'],
57
+ ],
58
+ },
59
+ build: {
60
+ usage: 'prolog-notebook build <file.prolog.md>',
61
+ blurb: 'write a page you can host or send',
62
+ options: [['--out <dir>', 'where it writes (default: <file>-site)']],
63
+ },
64
+ execute: {
65
+ usage: 'prolog-notebook execute <file.prolog.md>...',
66
+ blurb: 'run every query, write the answers in',
67
+ options: [
68
+ ['--limit <n>', `solutions to take from one query before stopping (default ${DEFAULT_LIMIT})`],
69
+ ['--stdout', 'print the result instead of writing the file'],
70
+ ['--quiet', 'report only failures'],
71
+ ],
72
+ // Belongs to --limit, so it goes wherever --limit goes and nowhere else.
73
+ note: 'A query that stops at the limit is written without a terminator, which is the\n'
74
+ + "format's way of saying the search was never exhausted. Nothing is invented.\n",
75
+ },
76
+ clear: {
77
+ usage: 'prolog-notebook clear <file.prolog.md>...',
78
+ blurb: 'take the answers back out',
79
+ options: [
80
+ ['--stdout', 'print the result instead of writing the file'],
81
+ ['--quiet', 'report only failures'],
82
+ ],
83
+ },
84
+ upgrade: {
85
+ usage: 'prolog-notebook upgrade',
86
+ blurb: 'fetch the latest version',
87
+ options: [],
88
+ },
89
+ };
62
90
 
63
- prolog-notebook clear <file.prolog.md>... take the answers back out
64
- --stdout print the result instead of writing the file
65
- --quiet report only failures
91
+ /** `exec` and `run` reach `execute` and are deliberately undocumented (869erp0jd). */
92
+ const ALIASES = { exec: 'execute', run: 'execute' };
66
93
 
67
- prolog-notebook upgrade fetch the latest version
94
+ /** The command this argument names, aliases resolved, or null. */
95
+ const commandNamed = (arg) => (COMMANDS[arg] ? arg : ALIASES[arg] ?? null);
68
96
 
69
- Anywhere
97
+ const ANYWHERE = `Anywhere
70
98
  --check-update ask npm whether a newer one exists, and say so either way
71
99
  --version version, engine and copyright
72
100
  -h, --help this
73
-
74
- A query that stops at the limit is written without a terminator, which is the
75
- format's way of saying the search was never exhausted. Nothing is invented.
76
101
  `;
77
102
 
103
+ /** One command, laid out exactly as it is laid out in the full help. */
104
+ function commandHelp(name) {
105
+ const { usage, blurb, options } = COMMANDS[name];
106
+ return [` ${usage.padEnd(44)}${blurb}`]
107
+ .concat(options.map(([flag, what]) => ` ${flag.padEnd(16)}${what}`))
108
+ .join('\n');
109
+ }
110
+
111
+ const USAGE = `prolog-notebook — Jupyter-style notebooks for Prolog
112
+
113
+ ${Object.keys(COMMANDS).map(commandHelp).join('\n\n')}
114
+
115
+ ${ANYWHERE}
116
+ ${COMMANDS.execute.note}`;
117
+
118
+ /**
119
+ * JUST THE COMMAND ASKED ABOUT (869erqra0).
120
+ *
121
+ * The Captain, on being shown all five for `build --help`: "not really. If I run
122
+ * prolog-notebook cmd --help I want only help on that cmd." Printing everything
123
+ * makes the reader find their command again in a page they did not ask for.
124
+ *
125
+ * What works anywhere stays, because it is true of the command they asked about
126
+ * as much as of any other.
127
+ */
128
+ function helpFor(name) {
129
+ const { note } = COMMANDS[name];
130
+ return `${commandHelp(name)}\n\n${ANYWHERE}${note ? `\n${note}` : ''}`;
131
+ }
132
+
78
133
  /**
79
134
  * Which command each option belongs to, so a misplaced one can say where it lives.
80
135
  *
136
+ * Derived, so a flag added to a command above cannot be forgotten here.
81
137
  * `unknown option "--limit"` is true and unhelpful when the flag is real and two
82
- * lines further up the same help. This costs a lookup table and saves a re-read.
138
+ * lines further up the same help.
83
139
  */
84
- const BELONGS_TO = {
85
- '--limit': 'execute',
86
- '--stdout': 'execute and clear',
87
- '--quiet': 'execute and clear',
88
- '--out': 'build',
89
- '--port': 'view',
90
- '--no-open': 'view',
91
- };
140
+ const BELONGS_TO = {};
141
+ for (const [name, { options }] of Object.entries(COMMANDS)) {
142
+ for (const [flag] of options) {
143
+ const bare = flag.split(' ')[0];
144
+ BELONGS_TO[bare] = BELONGS_TO[bare] ? `${BELONGS_TO[bare]} and ${name}` : name;
145
+ }
146
+ }
92
147
 
93
148
  function unknownOption(arg, command) {
94
149
  const home = BELONGS_TO[arg];
@@ -237,7 +292,11 @@ const NPM_LINE = process.platform === 'win32' ? 'npm.cmd' : 'npm';
237
292
  async function main(argv) {
238
293
  const args = argv.slice(2);
239
294
  if (!args.length || args.includes('-h') || args.includes('--help')) {
240
- process.stdout.write(USAGE);
295
+ // Whichever command they named, wherever they named it: `view --help`,
296
+ // `--help view` and `view chapter.prolog.md -h` all ask the same question.
297
+ // A help flag that is positional is its own small annoyance.
298
+ const named = args.map((arg) => commandNamed(arg)).find(Boolean);
299
+ process.stdout.write(named ? helpFor(named) : USAGE);
241
300
  return 0;
242
301
  }
243
302
  if (args.includes('--version') || args.includes('-V')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prolog-notebook",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Jupyter-style notebooks for Prolog. Runs in the browser, installs nothing.",
5
5
  "type": "module",
6
6
  "main": "./src/node.js",
@@ -1,4 +1,4 @@
1
1
  {
2
- "commit": "2d089b9",
3
- "built": "2026-08-30 22:55:39 UTC"
2
+ "commit": "9973408",
3
+ "built": "2026-08-30 23:05:20 UTC"
4
4
  }
package/src/version.js CHANGED
@@ -10,7 +10,7 @@
10
10
  export const NAME = 'Prolog Notebook';
11
11
 
12
12
  /** Must equal package.json's `version` — test/run.test.mjs enforces it. */
13
- export const VERSION = '0.6.3';
13
+ export const VERSION = '0.6.4';
14
14
 
15
15
  /** The two facts a licence notice is actually made of. */
16
16
  export const YEAR = '2026';