@optique/core 0.5.0-dev.80 → 0.5.0-dev.83

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/dist/facade.cjs CHANGED
@@ -14,30 +14,18 @@ const require_parser = require('./parser.cjs');
14
14
  function createHelpParser(mode) {
15
15
  const helpCommand = require_primitives.command("help", require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "COMMAND" }))), { description: require_message.message`Show help information.` });
16
16
  const helpOption = require_primitives.flag("--help", { description: require_message.message`Show help information.` });
17
- const _contextualHelpParser = require_constructs.object({
18
- help: require_primitives.constant(true),
19
- version: require_primitives.constant(false),
20
- commands: require_modifiers.multiple(require_primitives.argument(require_valueparser.string({
21
- metavar: "COMMAND",
22
- pattern: /^[^-].*$/
23
- }))),
24
- __help: require_primitives.flag("--help")
25
- });
26
17
  switch (mode) {
27
18
  case "command": return {
28
19
  helpCommand,
29
- helpOption: null,
30
- contextualHelpParser: null
20
+ helpOption: null
31
21
  };
32
22
  case "option": return {
33
23
  helpCommand: null,
34
- helpOption,
35
- contextualHelpParser: null
24
+ helpOption
36
25
  };
37
26
  case "both": return {
38
27
  helpCommand,
39
- helpOption,
40
- contextualHelpParser: null
28
+ helpOption
41
29
  };
42
30
  }
43
31
  }
@@ -78,44 +66,49 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers) {
78
66
  const { buffer, optionsTerminated } = context;
79
67
  if (optionsTerminated) return {
80
68
  success: false,
81
- error: require_message.message`Options terminated`,
69
+ error: require_message.message`Options terminated.`,
82
70
  consumed: 0
83
71
  };
84
72
  let helpFound = false;
85
73
  let helpIndex = -1;
86
- let helpCount = 0;
87
74
  let versionIndex = -1;
88
75
  for (let i = 0; i < buffer.length; i++) {
89
76
  if (buffer[i] === "--") break;
90
77
  if (buffer[i] === "--help") {
91
78
  helpFound = true;
92
79
  helpIndex = i;
93
- helpCount++;
94
80
  }
95
81
  if (buffer[i] === "--version") versionIndex = i;
96
82
  }
97
83
  if (helpFound && versionIndex > helpIndex) return {
98
84
  success: false,
99
- error: require_message.message`Version option wins`,
85
+ error: require_message.message`Version option wins.`,
100
86
  consumed: 0
101
87
  };
102
- if (helpFound) return {
103
- success: true,
104
- next: {
105
- ...context,
106
- buffer: [],
107
- state: {
108
- help: true,
109
- version: false,
110
- commands: [],
111
- helpFlag: true
112
- }
113
- },
114
- consumed: buffer.slice(0)
115
- };
88
+ if (helpFound) {
89
+ const commands = [];
90
+ for (let i = 0; i < helpIndex; i++) {
91
+ const arg = buffer[i];
92
+ if (!arg.startsWith("-")) commands.push(arg);
93
+ }
94
+ return {
95
+ success: true,
96
+ next: {
97
+ ...context,
98
+ buffer: [],
99
+ state: {
100
+ help: true,
101
+ version: false,
102
+ commands,
103
+ helpFlag: true
104
+ }
105
+ },
106
+ consumed: buffer.slice(0)
107
+ };
108
+ }
116
109
  return {
117
110
  success: false,
118
- error: require_message.message`Flag --help not found`,
111
+ error: require_message.message`Flag ${require_message.optionName("--help")} not found.`,
119
112
  consumed: 0
120
113
  };
121
114
  },
@@ -142,25 +135,23 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers) {
142
135
  const { buffer, optionsTerminated } = context;
143
136
  if (optionsTerminated) return {
144
137
  success: false,
145
- error: require_message.message`Options terminated`,
138
+ error: require_message.message`Options terminated.`,
146
139
  consumed: 0
147
140
  };
148
141
  let versionFound = false;
149
142
  let versionIndex = -1;
150
- let versionCount = 0;
151
143
  let helpIndex = -1;
152
144
  for (let i = 0; i < buffer.length; i++) {
153
145
  if (buffer[i] === "--") break;
154
146
  if (buffer[i] === "--version") {
155
147
  versionFound = true;
156
148
  versionIndex = i;
157
- versionCount++;
158
149
  }
159
150
  if (buffer[i] === "--help") helpIndex = i;
160
151
  }
161
152
  if (versionFound && helpIndex > versionIndex) return {
162
153
  success: false,
163
- error: require_message.message`Help option wins`,
154
+ error: require_message.message`Help option wins.`,
164
155
  consumed: 0
165
156
  };
166
157
  if (versionFound) return {
@@ -178,7 +169,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers) {
178
169
  };
179
170
  return {
180
171
  success: false,
181
- error: require_message.message`Flag --version not found`,
172
+ error: require_message.message`Flag ${require_message.optionName("--version")} not found.`,
182
173
  consumed: 0
183
174
  };
184
175
  },
@@ -205,7 +196,6 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers) {
205
196
  version: require_primitives.constant(false),
206
197
  commands: helpParsers.helpCommand
207
198
  }));
208
- if (helpParsers.contextualHelpParser) parsers.push(helpParsers.contextualHelpParser);
209
199
  parsers.push(require_constructs.object({
210
200
  help: require_primitives.constant(false),
211
201
  version: require_primitives.constant(false),
@@ -297,8 +287,7 @@ function run(parser, programName, args, options = {}) {
297
287
  const version = options.version ? versionMode : "none";
298
288
  const helpParsers = help === "none" ? {
299
289
  helpCommand: null,
300
- helpOption: null,
301
- contextualHelpParser: null
290
+ helpOption: null
302
291
  } : createHelpParser(help);
303
292
  const versionParsers = version === "none" ? {
304
293
  versionCommand: null,
package/dist/facade.js CHANGED
@@ -1,4 +1,4 @@
1
- import { formatMessage, message } from "./message.js";
1
+ import { formatMessage, message, optionName } from "./message.js";
2
2
  import { longestMatch, object } from "./constructs.js";
3
3
  import { formatUsage } from "./usage.js";
4
4
  import { formatDocPage } from "./doc.js";
@@ -14,30 +14,18 @@ import { getDocPage, parse } from "./parser.js";
14
14
  function createHelpParser(mode) {
15
15
  const helpCommand = command("help", multiple(argument(string({ metavar: "COMMAND" }))), { description: message`Show help information.` });
16
16
  const helpOption = flag("--help", { description: message`Show help information.` });
17
- const _contextualHelpParser = object({
18
- help: constant(true),
19
- version: constant(false),
20
- commands: multiple(argument(string({
21
- metavar: "COMMAND",
22
- pattern: /^[^-].*$/
23
- }))),
24
- __help: flag("--help")
25
- });
26
17
  switch (mode) {
27
18
  case "command": return {
28
19
  helpCommand,
29
- helpOption: null,
30
- contextualHelpParser: null
20
+ helpOption: null
31
21
  };
32
22
  case "option": return {
33
23
  helpCommand: null,
34
- helpOption,
35
- contextualHelpParser: null
24
+ helpOption
36
25
  };
37
26
  case "both": return {
38
27
  helpCommand,
39
- helpOption,
40
- contextualHelpParser: null
28
+ helpOption
41
29
  };
42
30
  }
43
31
  }
@@ -78,44 +66,49 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers) {
78
66
  const { buffer, optionsTerminated } = context;
79
67
  if (optionsTerminated) return {
80
68
  success: false,
81
- error: message`Options terminated`,
69
+ error: message`Options terminated.`,
82
70
  consumed: 0
83
71
  };
84
72
  let helpFound = false;
85
73
  let helpIndex = -1;
86
- let helpCount = 0;
87
74
  let versionIndex = -1;
88
75
  for (let i = 0; i < buffer.length; i++) {
89
76
  if (buffer[i] === "--") break;
90
77
  if (buffer[i] === "--help") {
91
78
  helpFound = true;
92
79
  helpIndex = i;
93
- helpCount++;
94
80
  }
95
81
  if (buffer[i] === "--version") versionIndex = i;
96
82
  }
97
83
  if (helpFound && versionIndex > helpIndex) return {
98
84
  success: false,
99
- error: message`Version option wins`,
85
+ error: message`Version option wins.`,
100
86
  consumed: 0
101
87
  };
102
- if (helpFound) return {
103
- success: true,
104
- next: {
105
- ...context,
106
- buffer: [],
107
- state: {
108
- help: true,
109
- version: false,
110
- commands: [],
111
- helpFlag: true
112
- }
113
- },
114
- consumed: buffer.slice(0)
115
- };
88
+ if (helpFound) {
89
+ const commands = [];
90
+ for (let i = 0; i < helpIndex; i++) {
91
+ const arg = buffer[i];
92
+ if (!arg.startsWith("-")) commands.push(arg);
93
+ }
94
+ return {
95
+ success: true,
96
+ next: {
97
+ ...context,
98
+ buffer: [],
99
+ state: {
100
+ help: true,
101
+ version: false,
102
+ commands,
103
+ helpFlag: true
104
+ }
105
+ },
106
+ consumed: buffer.slice(0)
107
+ };
108
+ }
116
109
  return {
117
110
  success: false,
118
- error: message`Flag --help not found`,
111
+ error: message`Flag ${optionName("--help")} not found.`,
119
112
  consumed: 0
120
113
  };
121
114
  },
@@ -142,25 +135,23 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers) {
142
135
  const { buffer, optionsTerminated } = context;
143
136
  if (optionsTerminated) return {
144
137
  success: false,
145
- error: message`Options terminated`,
138
+ error: message`Options terminated.`,
146
139
  consumed: 0
147
140
  };
148
141
  let versionFound = false;
149
142
  let versionIndex = -1;
150
- let versionCount = 0;
151
143
  let helpIndex = -1;
152
144
  for (let i = 0; i < buffer.length; i++) {
153
145
  if (buffer[i] === "--") break;
154
146
  if (buffer[i] === "--version") {
155
147
  versionFound = true;
156
148
  versionIndex = i;
157
- versionCount++;
158
149
  }
159
150
  if (buffer[i] === "--help") helpIndex = i;
160
151
  }
161
152
  if (versionFound && helpIndex > versionIndex) return {
162
153
  success: false,
163
- error: message`Help option wins`,
154
+ error: message`Help option wins.`,
164
155
  consumed: 0
165
156
  };
166
157
  if (versionFound) return {
@@ -178,7 +169,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers) {
178
169
  };
179
170
  return {
180
171
  success: false,
181
- error: message`Flag --version not found`,
172
+ error: message`Flag ${optionName("--version")} not found.`,
182
173
  consumed: 0
183
174
  };
184
175
  },
@@ -205,7 +196,6 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers) {
205
196
  version: constant(false),
206
197
  commands: helpParsers.helpCommand
207
198
  }));
208
- if (helpParsers.contextualHelpParser) parsers.push(helpParsers.contextualHelpParser);
209
199
  parsers.push(object({
210
200
  help: constant(false),
211
201
  version: constant(false),
@@ -297,8 +287,7 @@ function run(parser, programName, args, options = {}) {
297
287
  const version = options.version ? versionMode : "none";
298
288
  const helpParsers = help === "none" ? {
299
289
  helpCommand: null,
300
- helpOption: null,
301
- contextualHelpParser: null
290
+ helpOption: null
302
291
  } : createHelpParser(help);
303
292
  const versionParsers = version === "none" ? {
304
293
  versionCommand: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.5.0-dev.80+65e05a5c",
3
+ "version": "0.5.0-dev.83+21daa467",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",