@optique/man 0.10.7 → 1.0.0-dev.1109
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/README.md +12 -3
- package/dist/cli.cjs +136 -36
- package/dist/cli.js +124 -24
- package/dist/{generator-zoVk04OH.cjs → generator-RyVL5b_V.cjs} +32 -32
- package/dist/{generator-CCa36YC2.js → generator-YM0drazb.js} +31 -2
- package/dist/index.cjs +5 -3
- package/dist/index.d.cts +12 -9
- package/dist/index.d.ts +12 -9
- package/dist/index.js +4 -4
- package/dist/{man-BMb0Vyt9.d.cts → man-B1Q2mhit.d.ts} +34 -3
- package/dist/man-BE1OY_lJ.js +386 -0
- package/dist/man-CkvscTlM.cjs +432 -0
- package/dist/{man-tclTvdWs.d.ts → man-DKwa47XV.d.cts} +33 -2
- package/dist/man.cjs +2 -2
- package/dist/man.d.cts +1 -1
- package/dist/man.d.ts +1 -1
- package/dist/man.js +2 -2
- package/dist/{roff-C_MiRXVS.js → roff-CCdIQO7B.js} +47 -6
- package/dist/{roff-72Am6STB.d.cts → roff-COeDIWWF.d.cts} +49 -2
- package/dist/{roff-B36zMxYc.d.ts → roff-CgYQDHBN.d.ts} +49 -2
- package/dist/{roff-EpcecLXU.cjs → roff-DJ-LkRXl.cjs} +58 -5
- package/dist/roff.cjs +3 -1
- package/dist/roff.d.cts +2 -2
- package/dist/roff.d.ts +2 -2
- package/dist/roff.js +2 -2
- package/package.json +3 -3
- package/dist/man-DGnow1Jr.cjs +0 -235
- package/dist/man-Leuf7kOn.js +0 -218
|
@@ -1,18 +1,42 @@
|
|
|
1
|
-
import { formatDocPageAsMan } from "./man-
|
|
1
|
+
import { formatDocPageAsMan } from "./man-BE1OY_lJ.js";
|
|
2
2
|
import { getDocPageAsync, getDocPageSync } from "@optique/core/parser";
|
|
3
3
|
|
|
4
4
|
//#region src/generator.ts
|
|
5
5
|
/**
|
|
6
|
+
* Checks if the given value looks like a {@link Parser} at runtime.
|
|
7
|
+
*/
|
|
8
|
+
function isParser(value) {
|
|
9
|
+
try {
|
|
10
|
+
if (value == null || typeof value !== "object") return false;
|
|
11
|
+
const p = value;
|
|
12
|
+
return "parse" in p && typeof p.parse === "function" && "complete" in p && typeof p.complete === "function" && "$mode" in p && (p.$mode === "sync" || p.$mode === "async") && "usage" in p && Array.isArray(p.usage) && "initialState" in p && "suggest" in p && typeof p.suggest === "function" && "getDocFragments" in p && typeof p.getDocFragments === "function";
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
6
18
|
* Checks if the given value is a {@link Program} object.
|
|
7
19
|
*/
|
|
8
20
|
function isProgram(value) {
|
|
9
|
-
|
|
21
|
+
try {
|
|
22
|
+
return typeof value === "object" && value !== null && "parser" in value && "metadata" in value && typeof value.metadata === "object" && value.metadata !== null && "name" in value.metadata && typeof value.metadata.name === "string";
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validates that the extracted parser is a genuine Optique parser.
|
|
29
|
+
* @throws {TypeError} If the value is not a valid Parser.
|
|
30
|
+
*/
|
|
31
|
+
function validateParser(value) {
|
|
32
|
+
if (!isParser(value)) throw new TypeError("The given value is not a valid Parser or Program.");
|
|
10
33
|
}
|
|
11
34
|
/**
|
|
12
35
|
* Extracts parser and merged options from a parser or program.
|
|
13
36
|
*/
|
|
14
37
|
function extractParserAndOptions(parserOrProgram, options) {
|
|
15
38
|
if (isProgram(parserOrProgram)) {
|
|
39
|
+
validateParser(parserOrProgram.parser);
|
|
16
40
|
const { metadata } = parserOrProgram;
|
|
17
41
|
const programOptions = options;
|
|
18
42
|
return {
|
|
@@ -26,6 +50,9 @@ function extractParserAndOptions(parserOrProgram, options) {
|
|
|
26
50
|
author: programOptions.author ?? metadata.author,
|
|
27
51
|
bugs: programOptions.bugs ?? metadata.bugs,
|
|
28
52
|
examples: programOptions.examples ?? metadata.examples,
|
|
53
|
+
brief: programOptions.brief ?? metadata.brief,
|
|
54
|
+
description: programOptions.description ?? metadata.description,
|
|
55
|
+
footer: programOptions.footer ?? metadata.footer,
|
|
29
56
|
seeAlso: programOptions.seeAlso,
|
|
30
57
|
environment: programOptions.environment,
|
|
31
58
|
files: programOptions.files,
|
|
@@ -33,6 +60,7 @@ function extractParserAndOptions(parserOrProgram, options) {
|
|
|
33
60
|
}
|
|
34
61
|
};
|
|
35
62
|
}
|
|
63
|
+
validateParser(parserOrProgram);
|
|
36
64
|
return {
|
|
37
65
|
parser: parserOrProgram,
|
|
38
66
|
mergedOptions: options
|
|
@@ -40,6 +68,7 @@ function extractParserAndOptions(parserOrProgram, options) {
|
|
|
40
68
|
}
|
|
41
69
|
function generateManPageSync(parserOrProgram, options) {
|
|
42
70
|
const { parser, mergedOptions } = extractParserAndOptions(parserOrProgram, options);
|
|
71
|
+
if (parser.$mode === "async") throw new TypeError("Cannot use an async parser with generateManPageSync(). Use generateManPageAsync() or generateManPage() instead.");
|
|
43
72
|
const docPage = getDocPageSync(parser) ?? { sections: [] };
|
|
44
73
|
return formatDocPageAsMan(docPage, mergedOptions);
|
|
45
74
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_roff = require('./roff-
|
|
3
|
-
const
|
|
1
|
+
const require_man = require('./man-CkvscTlM.cjs');
|
|
2
|
+
const require_roff = require('./roff-DJ-LkRXl.cjs');
|
|
3
|
+
const require_generator = require('./generator-RyVL5b_V.cjs');
|
|
4
4
|
|
|
5
5
|
exports.escapeHyphens = require_roff.escapeHyphens;
|
|
6
|
+
exports.escapeQuotedValue = require_roff.escapeQuotedValue;
|
|
7
|
+
exports.escapeRequestArg = require_roff.escapeRequestArg;
|
|
6
8
|
exports.escapeRoff = require_roff.escapeRoff;
|
|
7
9
|
exports.formatDateForMan = require_man.formatDateForMan;
|
|
8
10
|
exports.formatDocPageAsMan = require_man.formatDocPageAsMan;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { escapeHyphens, escapeRoff, formatMessageAsRoff } from "./roff-
|
|
2
|
-
import { ManPageOptions, formatDateForMan, formatDocPageAsMan, formatUsageTermAsRoff } from "./man-
|
|
1
|
+
import { RoffFormatOptions, escapeHyphens, escapeQuotedValue, escapeRequestArg, escapeRoff, formatMessageAsRoff } from "./roff-COeDIWWF.cjs";
|
|
2
|
+
import { ManPageOptions, formatDateForMan, formatDocPageAsMan, formatUsageTermAsRoff } from "./man-DKwa47XV.cjs";
|
|
3
3
|
import { Mode, ModeValue, Parser } from "@optique/core/parser";
|
|
4
4
|
import { Program } from "@optique/core/program";
|
|
5
5
|
|
|
@@ -14,10 +14,10 @@ interface GenerateManPageOptions extends ManPageOptions {}
|
|
|
14
14
|
/**
|
|
15
15
|
* Options for generating a man page from a {@link Program}.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* metadata
|
|
20
|
-
*
|
|
17
|
+
* For Program inputs, `name`, `version`, `author`, `bugs`, `examples`,
|
|
18
|
+
* `brief`, `description`, and `footer` default to values from
|
|
19
|
+
* `program.metadata`.
|
|
20
|
+
* These fields are optional here and may be provided to override metadata.
|
|
21
21
|
*
|
|
22
22
|
* @since 0.10.0
|
|
23
23
|
*/
|
|
@@ -48,9 +48,10 @@ interface GenerateManPageProgramOptions extends Partial<Omit<ManPageOptions, "se
|
|
|
48
48
|
* console.log(manPage);
|
|
49
49
|
* ```
|
|
50
50
|
*
|
|
51
|
-
* @param
|
|
51
|
+
* @param parserOrProgram The parser or program to generate documentation from.
|
|
52
52
|
* @param options The man page generation options.
|
|
53
53
|
* @returns The complete man page in roff format.
|
|
54
|
+
* @throws {TypeError} If the input is not a valid Parser or Program.
|
|
54
55
|
* @since 0.10.0
|
|
55
56
|
*/
|
|
56
57
|
declare function generateManPageSync<T>(program: Program<"sync", T>, options: GenerateManPageProgramOptions): string;
|
|
@@ -78,9 +79,10 @@ declare function generateManPageSync(parser: Parser<"sync", unknown, unknown>, o
|
|
|
78
79
|
* });
|
|
79
80
|
* ```
|
|
80
81
|
*
|
|
81
|
-
* @param
|
|
82
|
+
* @param parserOrProgram The parser or program to generate documentation from.
|
|
82
83
|
* @param options The man page generation options.
|
|
83
84
|
* @returns A promise that resolves to the complete man page in roff format.
|
|
85
|
+
* @throws {TypeError} If the input is not a valid Parser or Program.
|
|
84
86
|
* @since 0.10.0
|
|
85
87
|
*/
|
|
86
88
|
declare function generateManPageAsync<M extends Mode, T>(program: Program<M, T>, options: GenerateManPageProgramOptions): Promise<string>;
|
|
@@ -148,6 +150,7 @@ declare function generateManPageAsync<M extends Mode>(parser: Parser<M, unknown,
|
|
|
148
150
|
* @param parserOrProgram The parser or program to generate documentation from.
|
|
149
151
|
* @param options The man page generation options.
|
|
150
152
|
* @returns The complete man page in roff format, or a Promise for async parsers.
|
|
153
|
+
* @throws {TypeError} If the input is not a valid Parser or Program.
|
|
151
154
|
* @since 0.10.0
|
|
152
155
|
*/
|
|
153
156
|
declare function generateManPage<T>(program: Program<"sync", T>, options: GenerateManPageProgramOptions): string;
|
|
@@ -156,4 +159,4 @@ declare function generateManPage(parser: Parser<"sync", unknown, unknown>, optio
|
|
|
156
159
|
declare function generateManPage(parser: Parser<"async", unknown, unknown>, options: GenerateManPageOptions): Promise<string>;
|
|
157
160
|
declare function generateManPage<M extends Mode>(parser: Parser<M, unknown, unknown>, options: GenerateManPageOptions): ModeValue<M, string>;
|
|
158
161
|
//#endregion
|
|
159
|
-
export { type GenerateManPageOptions, type GenerateManPageProgramOptions, type ManPageOptions, escapeHyphens, escapeRoff, formatDateForMan, formatDocPageAsMan, formatMessageAsRoff, formatUsageTermAsRoff, generateManPage, generateManPageAsync, generateManPageSync };
|
|
162
|
+
export { type GenerateManPageOptions, type GenerateManPageProgramOptions, type ManPageOptions, type RoffFormatOptions, escapeHyphens, escapeQuotedValue, escapeRequestArg, escapeRoff, formatDateForMan, formatDocPageAsMan, formatMessageAsRoff, formatUsageTermAsRoff, generateManPage, generateManPageAsync, generateManPageSync };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { escapeHyphens, escapeRoff, formatMessageAsRoff } from "./roff-
|
|
2
|
-
import { ManPageOptions, formatDateForMan, formatDocPageAsMan, formatUsageTermAsRoff } from "./man-
|
|
1
|
+
import { RoffFormatOptions, escapeHyphens, escapeQuotedValue, escapeRequestArg, escapeRoff, formatMessageAsRoff } from "./roff-CgYQDHBN.js";
|
|
2
|
+
import { ManPageOptions, formatDateForMan, formatDocPageAsMan, formatUsageTermAsRoff } from "./man-B1Q2mhit.js";
|
|
3
3
|
import { Program } from "@optique/core/program";
|
|
4
4
|
import { Mode, ModeValue, Parser } from "@optique/core/parser";
|
|
5
5
|
|
|
@@ -14,10 +14,10 @@ interface GenerateManPageOptions extends ManPageOptions {}
|
|
|
14
14
|
/**
|
|
15
15
|
* Options for generating a man page from a {@link Program}.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* metadata
|
|
20
|
-
*
|
|
17
|
+
* For Program inputs, `name`, `version`, `author`, `bugs`, `examples`,
|
|
18
|
+
* `brief`, `description`, and `footer` default to values from
|
|
19
|
+
* `program.metadata`.
|
|
20
|
+
* These fields are optional here and may be provided to override metadata.
|
|
21
21
|
*
|
|
22
22
|
* @since 0.10.0
|
|
23
23
|
*/
|
|
@@ -48,9 +48,10 @@ interface GenerateManPageProgramOptions extends Partial<Omit<ManPageOptions, "se
|
|
|
48
48
|
* console.log(manPage);
|
|
49
49
|
* ```
|
|
50
50
|
*
|
|
51
|
-
* @param
|
|
51
|
+
* @param parserOrProgram The parser or program to generate documentation from.
|
|
52
52
|
* @param options The man page generation options.
|
|
53
53
|
* @returns The complete man page in roff format.
|
|
54
|
+
* @throws {TypeError} If the input is not a valid Parser or Program.
|
|
54
55
|
* @since 0.10.0
|
|
55
56
|
*/
|
|
56
57
|
declare function generateManPageSync<T>(program: Program<"sync", T>, options: GenerateManPageProgramOptions): string;
|
|
@@ -78,9 +79,10 @@ declare function generateManPageSync(parser: Parser<"sync", unknown, unknown>, o
|
|
|
78
79
|
* });
|
|
79
80
|
* ```
|
|
80
81
|
*
|
|
81
|
-
* @param
|
|
82
|
+
* @param parserOrProgram The parser or program to generate documentation from.
|
|
82
83
|
* @param options The man page generation options.
|
|
83
84
|
* @returns A promise that resolves to the complete man page in roff format.
|
|
85
|
+
* @throws {TypeError} If the input is not a valid Parser or Program.
|
|
84
86
|
* @since 0.10.0
|
|
85
87
|
*/
|
|
86
88
|
declare function generateManPageAsync<M extends Mode, T>(program: Program<M, T>, options: GenerateManPageProgramOptions): Promise<string>;
|
|
@@ -148,6 +150,7 @@ declare function generateManPageAsync<M extends Mode>(parser: Parser<M, unknown,
|
|
|
148
150
|
* @param parserOrProgram The parser or program to generate documentation from.
|
|
149
151
|
* @param options The man page generation options.
|
|
150
152
|
* @returns The complete man page in roff format, or a Promise for async parsers.
|
|
153
|
+
* @throws {TypeError} If the input is not a valid Parser or Program.
|
|
151
154
|
* @since 0.10.0
|
|
152
155
|
*/
|
|
153
156
|
declare function generateManPage<T>(program: Program<"sync", T>, options: GenerateManPageProgramOptions): string;
|
|
@@ -156,4 +159,4 @@ declare function generateManPage(parser: Parser<"sync", unknown, unknown>, optio
|
|
|
156
159
|
declare function generateManPage(parser: Parser<"async", unknown, unknown>, options: GenerateManPageOptions): Promise<string>;
|
|
157
160
|
declare function generateManPage<M extends Mode>(parser: Parser<M, unknown, unknown>, options: GenerateManPageOptions): ModeValue<M, string>;
|
|
158
161
|
//#endregion
|
|
159
|
-
export { type GenerateManPageOptions, type GenerateManPageProgramOptions, type ManPageOptions, escapeHyphens, escapeRoff, formatDateForMan, formatDocPageAsMan, formatMessageAsRoff, formatUsageTermAsRoff, generateManPage, generateManPageAsync, generateManPageSync };
|
|
162
|
+
export { type GenerateManPageOptions, type GenerateManPageProgramOptions, type ManPageOptions, type RoffFormatOptions, escapeHyphens, escapeQuotedValue, escapeRequestArg, escapeRoff, formatDateForMan, formatDocPageAsMan, formatMessageAsRoff, formatUsageTermAsRoff, generateManPage, generateManPageAsync, generateManPageSync };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { escapeHyphens, escapeRoff, formatMessageAsRoff } from "./roff-
|
|
2
|
-
import { formatDateForMan, formatDocPageAsMan, formatUsageTermAsRoff } from "./man-
|
|
3
|
-
import { generateManPage, generateManPageAsync, generateManPageSync } from "./generator-
|
|
1
|
+
import { escapeHyphens, escapeQuotedValue, escapeRequestArg, escapeRoff, formatMessageAsRoff } from "./roff-CCdIQO7B.js";
|
|
2
|
+
import { formatDateForMan, formatDocPageAsMan, formatUsageTermAsRoff } from "./man-BE1OY_lJ.js";
|
|
3
|
+
import { generateManPage, generateManPageAsync, generateManPageSync } from "./generator-YM0drazb.js";
|
|
4
4
|
|
|
5
|
-
export { escapeHyphens, escapeRoff, formatDateForMan, formatDocPageAsMan, formatMessageAsRoff, formatUsageTermAsRoff, generateManPage, generateManPageAsync, generateManPageSync };
|
|
5
|
+
export { escapeHyphens, escapeQuotedValue, escapeRequestArg, escapeRoff, formatDateForMan, formatDocPageAsMan, formatMessageAsRoff, formatUsageTermAsRoff, generateManPage, generateManPageAsync, generateManPageSync };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Message } from "@optique/core/message";
|
|
2
|
-
import { DocPage, DocSection } from "@optique/core/doc";
|
|
3
2
|
import { UsageTerm } from "@optique/core/usage";
|
|
3
|
+
import { DocPage, DocSection } from "@optique/core/doc";
|
|
4
4
|
|
|
5
5
|
//#region src/man.d.ts
|
|
6
6
|
|
|
@@ -32,7 +32,9 @@ interface ManPageOptions {
|
|
|
32
32
|
readonly section: ManPageSection;
|
|
33
33
|
/**
|
|
34
34
|
* The date to display in the man page footer.
|
|
35
|
-
* If a Date object is provided, it will be formatted as "Month Year"
|
|
35
|
+
* If a `Date` object is provided, it will be formatted as `"Month Year"`
|
|
36
|
+
* using the host's local timezone. For timezone-independent output (e.g.,
|
|
37
|
+
* in CI), pass a pre-formatted string instead.
|
|
36
38
|
* If a string is provided, it will be used as-is.
|
|
37
39
|
*/
|
|
38
40
|
readonly date?: string | Date;
|
|
@@ -62,7 +64,7 @@ interface ManPageOptions {
|
|
|
62
64
|
*/
|
|
63
65
|
readonly seeAlso?: ReadonlyArray<{
|
|
64
66
|
readonly name: string;
|
|
65
|
-
readonly section:
|
|
67
|
+
readonly section: ManPageSection;
|
|
66
68
|
}>;
|
|
67
69
|
/**
|
|
68
70
|
* Environment variables to document in the ENVIRONMENT section.
|
|
@@ -76,12 +78,37 @@ interface ManPageOptions {
|
|
|
76
78
|
* Exit status codes to document in the EXIT STATUS section.
|
|
77
79
|
*/
|
|
78
80
|
readonly exitStatus?: DocSection;
|
|
81
|
+
/**
|
|
82
|
+
* A brief description of the program for the NAME section.
|
|
83
|
+
* Overrides the brief from the {@link DocPage} if both are present.
|
|
84
|
+
* @since 1.0.0
|
|
85
|
+
*/
|
|
86
|
+
readonly brief?: Message;
|
|
87
|
+
/**
|
|
88
|
+
* A detailed description of the program for the DESCRIPTION section.
|
|
89
|
+
* Overrides the description from the {@link DocPage} if both are present.
|
|
90
|
+
* @since 1.0.0
|
|
91
|
+
*/
|
|
92
|
+
readonly description?: Message;
|
|
93
|
+
/**
|
|
94
|
+
* Footer text appended at the end of the man page.
|
|
95
|
+
* Overrides the footer from the {@link DocPage} if both are present.
|
|
96
|
+
* @since 1.0.0
|
|
97
|
+
*/
|
|
98
|
+
readonly footer?: Message;
|
|
79
99
|
}
|
|
80
100
|
/**
|
|
81
101
|
* Formats a date for use in man pages.
|
|
82
102
|
*
|
|
103
|
+
* When a `Date` object is given, the month and year are extracted using
|
|
104
|
+
* the host's local timezone (`getMonth()` / `getFullYear()`). This means
|
|
105
|
+
* the same `Date` instant may produce different output on machines in
|
|
106
|
+
* different timezones. Pass a pre-formatted string (e.g., `"January 2026"`)
|
|
107
|
+
* if you need timezone-independent output.
|
|
108
|
+
*
|
|
83
109
|
* @param date The date to format, or undefined.
|
|
84
110
|
* @returns The formatted date string, or undefined.
|
|
111
|
+
* @throws {RangeError} If the given `Date` object is invalid.
|
|
85
112
|
* @since 0.10.0
|
|
86
113
|
*/
|
|
87
114
|
declare function formatDateForMan(date: string | Date | undefined): string | undefined;
|
|
@@ -90,6 +117,7 @@ declare function formatDateForMan(date: string | Date | undefined): string | und
|
|
|
90
117
|
*
|
|
91
118
|
* @param term The usage term to format.
|
|
92
119
|
* @returns The roff-formatted string.
|
|
120
|
+
* @throws {TypeError} If the term has an unknown type.
|
|
93
121
|
* @since 0.10.0
|
|
94
122
|
*/
|
|
95
123
|
declare function formatUsageTermAsRoff(term: UsageTerm): string;
|
|
@@ -120,6 +148,9 @@ declare function formatUsageTermAsRoff(term: UsageTerm): string;
|
|
|
120
148
|
* @param page The documentation page to format.
|
|
121
149
|
* @param options The man page options.
|
|
122
150
|
* @returns The complete man page in roff format.
|
|
151
|
+
* @throws {TypeError} If the program name is empty.
|
|
152
|
+
* @throws {RangeError} If the section number or any `seeAlso` entry's section
|
|
153
|
+
* number is not a valid man page section (1–8).
|
|
123
154
|
* @since 0.10.0
|
|
124
155
|
*/
|
|
125
156
|
declare function formatDocPageAsMan(page: DocPage, options: ManPageOptions): string;
|