@virmator/help 13.0.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-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/README.md +12 -0
- package/dist/help-message.d.ts +62 -0
- package/dist/help-message.js +192 -0
- package/dist/help.d.ts +26 -0
- package/dist/help.js +22 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +46 -0
package/LICENSE-CC0
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
CC0 1.0 Universal
|
|
2
|
+
|
|
3
|
+
Creative Commons Legal Code
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 electrovir
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { VirmatorPlugin, VirmatorPluginCliCommands } from '@virmator/core';
|
|
2
|
+
/** Different syntaxes for each supported help message target environment. */
|
|
3
|
+
export declare enum HelpMessageSyntax {
|
|
4
|
+
Cli = "cli",
|
|
5
|
+
Markdown = "markdown"
|
|
6
|
+
}
|
|
7
|
+
/** Generate a help message from a list of {@link VirmatorPlugin} instances. */
|
|
8
|
+
export declare function generateHelpMessageFromPlugins(plugins: ReadonlyArray<Readonly<Pick<VirmatorPlugin, 'cliCommands'>>>, syntax: HelpMessageSyntax, hideVirmatorExplanations?: boolean, cliWrapIfMoreThanThisManyColumns?: number): string;
|
|
9
|
+
/**
|
|
10
|
+
* Generate a help message directly from {@link VirmatorPluginCliCommands}. Used by
|
|
11
|
+
* {@link generateHelpMessageFromPlugins}.
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateHelpMessage(cliCommands: ReadonlyArray<Readonly<VirmatorPluginCliCommands>>, syntax: HelpMessageSyntax, hideVirmatorExplanations?: boolean, cliWrapIfMoreThanThisManyColumns?: number): string;
|
|
14
|
+
/** All supported formats for help messages. */
|
|
15
|
+
export declare const formats: {
|
|
16
|
+
readonly h1: {
|
|
17
|
+
readonly cli: string;
|
|
18
|
+
readonly markdown: "# ";
|
|
19
|
+
};
|
|
20
|
+
readonly h2: {
|
|
21
|
+
readonly cli: string;
|
|
22
|
+
readonly markdown: "## ";
|
|
23
|
+
};
|
|
24
|
+
readonly bold: {
|
|
25
|
+
readonly cli: string;
|
|
26
|
+
readonly markdown: "**";
|
|
27
|
+
};
|
|
28
|
+
readonly unBold: {
|
|
29
|
+
readonly cli: string;
|
|
30
|
+
readonly markdown: "**";
|
|
31
|
+
};
|
|
32
|
+
readonly code: {
|
|
33
|
+
readonly cli: string;
|
|
34
|
+
readonly markdown: "`";
|
|
35
|
+
};
|
|
36
|
+
readonly unCode: {
|
|
37
|
+
readonly cli: string;
|
|
38
|
+
readonly markdown: "`";
|
|
39
|
+
};
|
|
40
|
+
readonly reset: {
|
|
41
|
+
readonly cli: string;
|
|
42
|
+
readonly markdown: "";
|
|
43
|
+
};
|
|
44
|
+
readonly indent: {
|
|
45
|
+
readonly cli: " ";
|
|
46
|
+
readonly markdown: " ";
|
|
47
|
+
};
|
|
48
|
+
readonly bullet: {
|
|
49
|
+
readonly cli: "- ";
|
|
50
|
+
readonly markdown: "- ";
|
|
51
|
+
};
|
|
52
|
+
readonly escape: {
|
|
53
|
+
readonly cli: "";
|
|
54
|
+
readonly markdown: "\\";
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
/** Help message formatter. */
|
|
58
|
+
export type Formatter = Record<keyof typeof formats, string>;
|
|
59
|
+
/** Create a help message formatter based on a specific syntax. */
|
|
60
|
+
export declare function createFormatter(syntax: HelpMessageSyntax): Formatter;
|
|
61
|
+
/** Wrap lines to within the specified limit. */
|
|
62
|
+
export declare function wrapLines(input: string, limit: number, format: Formatter): string;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { collapseWhiteSpace, getObjectTypedEntries, isTruthy, mapObjectValues, safeMatch, } from '@augment-vir/common';
|
|
2
|
+
import { logColors, toPosixPath } from '@augment-vir/node-js';
|
|
3
|
+
import { virmatorFlags, } from '@virmator/core';
|
|
4
|
+
/** Different syntaxes for each supported help message target environment. */
|
|
5
|
+
export var HelpMessageSyntax;
|
|
6
|
+
(function (HelpMessageSyntax) {
|
|
7
|
+
HelpMessageSyntax["Cli"] = "cli";
|
|
8
|
+
HelpMessageSyntax["Markdown"] = "markdown";
|
|
9
|
+
})(HelpMessageSyntax || (HelpMessageSyntax = {}));
|
|
10
|
+
function flattenCommands(cliCommands) {
|
|
11
|
+
return cliCommands.reduce((accum, commands) => {
|
|
12
|
+
Object.assign(accum, commands);
|
|
13
|
+
return accum;
|
|
14
|
+
}, {});
|
|
15
|
+
}
|
|
16
|
+
/** Generate a help message from a list of {@link VirmatorPlugin} instances. */
|
|
17
|
+
export function generateHelpMessageFromPlugins(plugins, syntax, hideVirmatorExplanations = false, cliWrapIfMoreThanThisManyColumns = 100) {
|
|
18
|
+
return generateHelpMessage(plugins.map((plugin) => plugin.cliCommands), syntax, hideVirmatorExplanations, cliWrapIfMoreThanThisManyColumns);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate a help message directly from {@link VirmatorPluginCliCommands}. Used by
|
|
22
|
+
* {@link generateHelpMessageFromPlugins}.
|
|
23
|
+
*/
|
|
24
|
+
export function generateHelpMessage(cliCommands, syntax, hideVirmatorExplanations = false, cliWrapIfMoreThanThisManyColumns = 100) {
|
|
25
|
+
const allCommands = flattenCommands(cliCommands);
|
|
26
|
+
const format = createFormatter(syntax);
|
|
27
|
+
const commandsMessage = getObjectTypedEntries(allCommands)
|
|
28
|
+
.sort((a, b) => {
|
|
29
|
+
return a[0].localeCompare(b[0]);
|
|
30
|
+
})
|
|
31
|
+
.map(([commandName, command,]) => {
|
|
32
|
+
return commandToHelpString(commandName, command, format, 0);
|
|
33
|
+
})
|
|
34
|
+
.join('\n\n');
|
|
35
|
+
const commandsText = `${format.h2}Available commands${format.reset}\n\n${commandsMessage}`.trim();
|
|
36
|
+
const helpMessage = hideVirmatorExplanations
|
|
37
|
+
? commandsText + '\n'
|
|
38
|
+
: combineHelpMessage(commandsText, format).trim() + '\n';
|
|
39
|
+
return syntax === HelpMessageSyntax.Cli
|
|
40
|
+
? wrapLines(helpMessage, cliWrapIfMoreThanThisManyColumns, format)
|
|
41
|
+
: helpMessage;
|
|
42
|
+
}
|
|
43
|
+
/** All supported formats for help messages. */
|
|
44
|
+
export const formats = {
|
|
45
|
+
h1: {
|
|
46
|
+
[HelpMessageSyntax.Cli]: logColors.info,
|
|
47
|
+
[HelpMessageSyntax.Markdown]: '# ',
|
|
48
|
+
},
|
|
49
|
+
h2: {
|
|
50
|
+
[HelpMessageSyntax.Cli]: `${logColors.bold}${logColors.info}`,
|
|
51
|
+
[HelpMessageSyntax.Markdown]: '## ',
|
|
52
|
+
},
|
|
53
|
+
bold: {
|
|
54
|
+
[HelpMessageSyntax.Cli]: logColors.bold,
|
|
55
|
+
[HelpMessageSyntax.Markdown]: '**',
|
|
56
|
+
},
|
|
57
|
+
unBold: {
|
|
58
|
+
[HelpMessageSyntax.Cli]: logColors['normal-weight'],
|
|
59
|
+
[HelpMessageSyntax.Markdown]: '**',
|
|
60
|
+
},
|
|
61
|
+
code: {
|
|
62
|
+
[HelpMessageSyntax.Cli]: logColors.info,
|
|
63
|
+
[HelpMessageSyntax.Markdown]: '`',
|
|
64
|
+
},
|
|
65
|
+
unCode: {
|
|
66
|
+
[HelpMessageSyntax.Cli]: logColors.reset,
|
|
67
|
+
[HelpMessageSyntax.Markdown]: '`',
|
|
68
|
+
},
|
|
69
|
+
reset: {
|
|
70
|
+
[HelpMessageSyntax.Cli]: logColors.reset,
|
|
71
|
+
[HelpMessageSyntax.Markdown]: '',
|
|
72
|
+
},
|
|
73
|
+
indent: {
|
|
74
|
+
[HelpMessageSyntax.Cli]: ' ',
|
|
75
|
+
[HelpMessageSyntax.Markdown]: ' ',
|
|
76
|
+
},
|
|
77
|
+
bullet: {
|
|
78
|
+
[HelpMessageSyntax.Cli]: '- ',
|
|
79
|
+
[HelpMessageSyntax.Markdown]: '- ',
|
|
80
|
+
},
|
|
81
|
+
escape: {
|
|
82
|
+
[HelpMessageSyntax.Cli]: '',
|
|
83
|
+
[HelpMessageSyntax.Markdown]: '\\',
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
/** Create a help message formatter based on a specific syntax. */
|
|
87
|
+
export function createFormatter(syntax) {
|
|
88
|
+
return mapObjectValues(formats, (key, entry) => {
|
|
89
|
+
return entry[syntax];
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function code(input, format) {
|
|
93
|
+
return `${format.code}${input}${format.unCode}`;
|
|
94
|
+
}
|
|
95
|
+
function bold(input, format) {
|
|
96
|
+
return `${format.bold}${input}${format.unBold}`;
|
|
97
|
+
}
|
|
98
|
+
function flagToHelpString(flagName, description, format) {
|
|
99
|
+
return `${format.bullet}${bold(flagName, format)}: ${collapseWhiteSpace(description)}`;
|
|
100
|
+
}
|
|
101
|
+
function flagsToHelpString(flags, format) {
|
|
102
|
+
return getObjectTypedEntries(flags)
|
|
103
|
+
.map(([flagName, entry,]) => flagToHelpString(flagName, entry.doc, format))
|
|
104
|
+
.join('\n');
|
|
105
|
+
}
|
|
106
|
+
function commandToHelpString(commandName, command, format,
|
|
107
|
+
/** Used for sub commands. Set to 0 for top level commands. */
|
|
108
|
+
indentCount) {
|
|
109
|
+
const title = `${indent(indentCount, format)}${format.bullet}${bold(commandName, format)}${format.reset}`;
|
|
110
|
+
const description = commandDocToString(command, format, indentCount);
|
|
111
|
+
const subCommands = getObjectTypedEntries(command.subCommands || {}).map(([subCommandName, subCommand,]) => commandToHelpString(subCommandName, subCommand, format, indentCount + 2));
|
|
112
|
+
const subCommandsBlock = subCommands.length
|
|
113
|
+
? `\n${indent(indentCount + 1, format)}${format.bullet}Sub Commands\n\n${subCommands.join('\n\n')}`
|
|
114
|
+
: '';
|
|
115
|
+
return `${title}\n\n${description}${subCommandsBlock}`;
|
|
116
|
+
}
|
|
117
|
+
function indent(count, format) {
|
|
118
|
+
return format.indent.repeat(count);
|
|
119
|
+
}
|
|
120
|
+
function docEntryToString(entry, indentCount, useBullets, format) {
|
|
121
|
+
const title = entry.title ? `${entry.title}: ` : '';
|
|
122
|
+
const trimmedEntry = collapseWhiteSpace(entry.content);
|
|
123
|
+
const content = useBullets ? code(trimmedEntry, format) : trimmedEntry;
|
|
124
|
+
return `${indent(indentCount + 1, format)}${useBullets ? format.bullet : ''}${title}${content}`;
|
|
125
|
+
}
|
|
126
|
+
function commandDocToString(command, format, indentCount) {
|
|
127
|
+
const sections = command.doc.sections.map((section) => docEntryToString({ content: section }, indentCount, false, format));
|
|
128
|
+
const examples = command.doc.examples.map((example) => docEntryToString(example, indentCount + 1, true, format));
|
|
129
|
+
const exampleBlock = examples.length
|
|
130
|
+
? `${indent(indentCount + 1, format)}${format.bullet}Examples\n${examples.join('\n')}`
|
|
131
|
+
: '';
|
|
132
|
+
const configs = Object.values(command.configFiles || {}).map((configFile) => {
|
|
133
|
+
const escaped = toPosixPath(configFile.copyToPath).replaceAll(/(_)/g, `${format.escape}$1`);
|
|
134
|
+
return `${indent(indentCount + 2, format)}${format.bullet}${escaped}`;
|
|
135
|
+
});
|
|
136
|
+
const configsBlock = configs.length
|
|
137
|
+
? `${indent(indentCount + 1, format)}${format.bullet}Configs\n${configs.join('\n')}`
|
|
138
|
+
: '';
|
|
139
|
+
const deps = Object.keys(command.npmDeps || {}).map((npmDepName) => {
|
|
140
|
+
return `${indent(indentCount + 2, format)}${format.bullet}[${npmDepName}](https://npmjs.com/package/${npmDepName})`;
|
|
141
|
+
});
|
|
142
|
+
const depsBlock = deps.length
|
|
143
|
+
? `${indent(indentCount + 1, format)}${format.bullet}Deps\n${deps.join('\n')}`
|
|
144
|
+
: '';
|
|
145
|
+
const blocks = [
|
|
146
|
+
sections.length ? sections.join('\n\n') + '\n' : '',
|
|
147
|
+
exampleBlock,
|
|
148
|
+
configsBlock,
|
|
149
|
+
depsBlock,
|
|
150
|
+
].filter(isTruthy);
|
|
151
|
+
return blocks.join('\n');
|
|
152
|
+
}
|
|
153
|
+
function combineHelpMessage(commandsText, format) {
|
|
154
|
+
const flagsText = flagsToHelpString(virmatorFlags, format);
|
|
155
|
+
return `${format.h1}virmator usage${format.reset}\n\n${code('[npx] virmator [--flags] command subCommand [...optional args]', format)}\n\n${format.bullet}${code('npx', format)} is needed when the command is run directly from the terminal (not called from within an npm script) unless virmator has been globally installed (which I recommend against).
|
|
156
|
+
${format.bullet}${code('[--flags]', format)} is any of the optional virmator flags. See Virmator Flags below.
|
|
157
|
+
${format.bullet}${code('command', format)}, ${code('subCommand', format)}, and ${code('[...optional args]', format)} depend on the specific command you're running. See Available Commands below.\n\n${commandsText}\n\n${format.h2}Virmator Flags${format.reset}\n\nAll virmator flags are optional and typically not needed.\n\n${flagsText}`;
|
|
158
|
+
}
|
|
159
|
+
function getIndent(line, format) {
|
|
160
|
+
/** This is an edge case for type guarding. */
|
|
161
|
+
/* node:coverage ignore next */
|
|
162
|
+
const indent = safeMatch(line, /^(\s*)/)[0] || '';
|
|
163
|
+
const startsWithBullet = line.trim().startsWith(format.bullet);
|
|
164
|
+
return [
|
|
165
|
+
indent,
|
|
166
|
+
startsWithBullet ? ' '.repeat(format.bullet.length) : '',
|
|
167
|
+
].join('');
|
|
168
|
+
}
|
|
169
|
+
/** Wrap lines to within the specified limit. */
|
|
170
|
+
export function wrapLines(input, limit, format) {
|
|
171
|
+
const lines = input.split('\n');
|
|
172
|
+
// using a for loop because the length of the array will get modified while iterating through it
|
|
173
|
+
for (let index = 0; index < lines.length; index++) {
|
|
174
|
+
const line = lines[index];
|
|
175
|
+
if (line && line.length > limit) {
|
|
176
|
+
const replacementLine = line.slice(0, limit);
|
|
177
|
+
lines[index] = replacementLine.trimEnd();
|
|
178
|
+
let wrappedPart = line.slice(limit);
|
|
179
|
+
// didn't wrap on a space, we need to shift a word down
|
|
180
|
+
if (!replacementLine.endsWith(' ') && !wrappedPart.startsWith(' ')) {
|
|
181
|
+
/** This is an edge case for type guarding. */
|
|
182
|
+
/* node:coverage ignore next */
|
|
183
|
+
const lastWord = safeMatch(replacementLine, /(\s\S+$)/)[0] || '';
|
|
184
|
+
lines[index] = replacementLine.slice(0, -1 * lastWord.length).trimEnd();
|
|
185
|
+
wrappedPart = `${lastWord}${wrappedPart.trim()}`;
|
|
186
|
+
}
|
|
187
|
+
const currentIndent = getIndent(line, format);
|
|
188
|
+
lines.splice(index + 1, 0, `${currentIndent}${wrappedPart.trim()}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return lines.join('\n').trimEnd();
|
|
192
|
+
}
|
package/dist/help.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** A virmator plugin for printing help messages from other plugins. */
|
|
2
|
+
export declare const virmatorHelpPlugin: Readonly<Readonly<{
|
|
3
|
+
name: string;
|
|
4
|
+
cliCommands: NoInfer<{
|
|
5
|
+
readonly help: {
|
|
6
|
+
readonly doc: {
|
|
7
|
+
readonly examples: readonly [{
|
|
8
|
+
readonly content: "virmator help";
|
|
9
|
+
}];
|
|
10
|
+
readonly sections: readonly ["Prints help messages for all supported plugins/commands."];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
}> & {
|
|
15
|
+
pluginPackageRootPath: string;
|
|
16
|
+
executor: import("@virmator/core").VirmatorPluginExecutor<NoInfer<{
|
|
17
|
+
readonly help: {
|
|
18
|
+
readonly doc: {
|
|
19
|
+
readonly examples: readonly [{
|
|
20
|
+
readonly content: "virmator help";
|
|
21
|
+
}];
|
|
22
|
+
readonly sections: readonly ["Prints help messages for all supported plugins/commands."];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}>>;
|
|
26
|
+
}>;
|
package/dist/help.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineVirmatorPlugin } from '@virmator/core';
|
|
2
|
+
import { generateHelpMessageFromPlugins, HelpMessageSyntax } from './help-message';
|
|
3
|
+
/** A virmator plugin for printing help messages from other plugins. */
|
|
4
|
+
export const virmatorHelpPlugin = defineVirmatorPlugin(import.meta.dirname, {
|
|
5
|
+
name: 'Help',
|
|
6
|
+
cliCommands: {
|
|
7
|
+
help: {
|
|
8
|
+
doc: {
|
|
9
|
+
examples: [
|
|
10
|
+
{
|
|
11
|
+
content: 'virmator help',
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
sections: [
|
|
15
|
+
'Prints help messages for all supported plugins/commands.',
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
}, ({ virmator: { allPlugins }, log }) => {
|
|
21
|
+
log.plain(generateHelpMessageFromPlugins(allPlugins, HelpMessageSyntax.Cli));
|
|
22
|
+
});
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@virmator/help",
|
|
3
|
+
"version": "13.0.0",
|
|
4
|
+
"description": "Default help plugin for virmator.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"virmator",
|
|
7
|
+
"cli",
|
|
8
|
+
"help"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/electrovir/virmator",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/electrovir/virmator/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/electrovir/virmator.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "(MIT or CC0 1.0)",
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "electrovir",
|
|
21
|
+
"url": "https://github.com/electrovir"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "dist/index.js",
|
|
25
|
+
"module": "dist/index.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"compile": "virmator compile",
|
|
29
|
+
"test": "virmator test node",
|
|
30
|
+
"test:coverage": "npm test coverage",
|
|
31
|
+
"test:update": "npm test update"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@augment-vir/common": "^29.3.0",
|
|
35
|
+
"@augment-vir/node-js": "^29.3.0",
|
|
36
|
+
"run-time-assertions": "^1.5.2"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^22.1.0",
|
|
40
|
+
"c8": "^10.1.2",
|
|
41
|
+
"istanbul-smart-text-reporter": "^1.1.4"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|