@virmator/help 14.26.0 → 14.27.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.
@@ -1,16 +1,33 @@
1
+ import { type PartialWithUndefined } from '@augment-vir/common';
1
2
  import { type VirmatorPlugin, type VirmatorPluginCliCommands } from '@virmator/core';
2
3
  /** Different syntaxes for each supported help message target environment. */
3
4
  export declare enum HelpMessageSyntax {
4
5
  Cli = "cli",
5
6
  Markdown = "markdown"
6
7
  }
8
+ /** Inputs for {@link generateHelpMessageFromPlugins}. */
9
+ export type GenerateHelpMessageFromPluginsParams = {
10
+ plugins: ReadonlyArray<Readonly<Pick<VirmatorPlugin, 'cliCommands'>>>;
11
+ syntax: HelpMessageSyntax;
12
+ } & PartialWithUndefined<{
13
+ hideVirmatorExplanations: boolean;
14
+ cliWrapIfMoreThanThisManyColumns: number;
15
+ }>;
7
16
  /** Generate a help message from a list of `VirmatorPlugin` instances. */
8
- export declare function generateHelpMessageFromPlugins(plugins: ReadonlyArray<Readonly<Pick<VirmatorPlugin, 'cliCommands'>>>, syntax: HelpMessageSyntax, hideVirmatorExplanations?: boolean, cliWrapIfMoreThanThisManyColumns?: number): string;
17
+ export declare function generateHelpMessageFromPlugins({ plugins, syntax, hideVirmatorExplanations, cliWrapIfMoreThanThisManyColumns, }: Readonly<GenerateHelpMessageFromPluginsParams>): string;
18
+ /** Inputs for {@link generateHelpMessage}. */
19
+ export type GenerateHelpMessageParams = {
20
+ cliCommands: ReadonlyArray<Readonly<VirmatorPluginCliCommands>>;
21
+ syntax: HelpMessageSyntax;
22
+ } & PartialWithUndefined<{
23
+ hideVirmatorExplanations: boolean;
24
+ cliWrapIfMoreThanThisManyColumns: number;
25
+ }>;
9
26
  /**
10
27
  * Generate a help message directly from `VirmatorPluginCliCommands`. Used by
11
28
  * {@link generateHelpMessageFromPlugins}.
12
29
  */
13
- export declare function generateHelpMessage(cliCommands: ReadonlyArray<Readonly<VirmatorPluginCliCommands>>, syntax: HelpMessageSyntax, hideVirmatorExplanations?: boolean, cliWrapIfMoreThanThisManyColumns?: number): string;
30
+ export declare function generateHelpMessage({ cliCommands, syntax, hideVirmatorExplanations, cliWrapIfMoreThanThisManyColumns, }: Readonly<GenerateHelpMessageParams>): string;
14
31
  /** All supported formats for help messages. */
15
32
  export declare const formats: {
16
33
  readonly h1: {
@@ -15,14 +15,19 @@ function flattenCommands(cliCommands) {
15
15
  }, {});
16
16
  }
17
17
  /** Generate a help message from a list of `VirmatorPlugin` instances. */
18
- export function generateHelpMessageFromPlugins(plugins, syntax, hideVirmatorExplanations = false, cliWrapIfMoreThanThisManyColumns = 100) {
19
- return generateHelpMessage(plugins.map((plugin) => plugin.cliCommands), syntax, hideVirmatorExplanations, cliWrapIfMoreThanThisManyColumns);
18
+ export function generateHelpMessageFromPlugins({ plugins, syntax, hideVirmatorExplanations = false, cliWrapIfMoreThanThisManyColumns = 100, }) {
19
+ return generateHelpMessage({
20
+ cliCommands: plugins.map((plugin) => plugin.cliCommands),
21
+ syntax,
22
+ hideVirmatorExplanations,
23
+ cliWrapIfMoreThanThisManyColumns,
24
+ });
20
25
  }
21
26
  /**
22
27
  * Generate a help message directly from `VirmatorPluginCliCommands`. Used by
23
28
  * {@link generateHelpMessageFromPlugins}.
24
29
  */
25
- export function generateHelpMessage(cliCommands, syntax, hideVirmatorExplanations = false, cliWrapIfMoreThanThisManyColumns = 100) {
30
+ export function generateHelpMessage({ cliCommands, syntax, hideVirmatorExplanations = false, cliWrapIfMoreThanThisManyColumns = 100, }) {
26
31
  const allCommands = flattenCommands(cliCommands);
27
32
  const format = createFormatter(syntax);
28
33
  const commandsMessage = getObjectTypedEntries(allCommands)
@@ -30,7 +35,12 @@ export function generateHelpMessage(cliCommands, syntax, hideVirmatorExplanation
30
35
  return a[0].localeCompare(b[0]);
31
36
  })
32
37
  .map(([commandName, command,]) => {
33
- return commandToHelpString(commandName, command, format, 0);
38
+ return commandToHelpString({
39
+ commandName,
40
+ command,
41
+ format,
42
+ indentCount: 0,
43
+ });
34
44
  })
35
45
  .join('\n\n');
36
46
  const commandsText = `${format.h2}Available commands${format.reset}\n\n${commandsMessage}`.trim();
@@ -96,20 +106,27 @@ function code(input, format) {
96
106
  function bold(input, format) {
97
107
  return `${format.bold}${input}${format.unBold}`;
98
108
  }
99
- function flagToHelpString(flagName, description, format) {
109
+ function flagToHelpString({ flagName, description, format, }) {
100
110
  return `${format.bullet}${bold(flagName, format)}: ${collapseWhiteSpace(description)}`;
101
111
  }
102
112
  function flagsToHelpString(flags, format) {
103
113
  return getObjectTypedEntries(flags)
104
- .map(([flagName, entry,]) => flagToHelpString(flagName, entry.doc, format))
114
+ .map(([flagName, entry,]) => flagToHelpString({
115
+ flagName,
116
+ description: entry.doc,
117
+ format,
118
+ }))
105
119
  .join('\n');
106
120
  }
107
- function commandToHelpString(commandName, command, format,
108
- /** Used for sub commands. Set to 0 for top level commands. */
109
- indentCount) {
121
+ function commandToHelpString({ commandName, command, format, indentCount, }) {
110
122
  const title = `${indent(indentCount, format)}${format.bullet}${bold(commandName, format)}${format.reset}`;
111
123
  const description = commandDocToString(command, format, indentCount);
112
- const subCommands = getObjectTypedEntries(command.subCommands || {}).map(([subCommandName, subCommand,]) => commandToHelpString(subCommandName, subCommand, format, indentCount + 2));
124
+ const subCommands = getObjectTypedEntries(command.subCommands || {}).map(([subCommandName, subCommand,]) => commandToHelpString({
125
+ commandName: subCommandName,
126
+ command: subCommand,
127
+ format,
128
+ indentCount: indentCount + 2,
129
+ }));
113
130
  const subCommandsBlock = subCommands.length
114
131
  ? `\n${indent(indentCount + 1, format)}${format.bullet}Sub Commands\n\n${subCommands.join('\n\n')}`
115
132
  : '';
@@ -118,7 +135,7 @@ indentCount) {
118
135
  function indent(count, format) {
119
136
  return format.indent.repeat(count);
120
137
  }
121
- function docEntryToString(entry, indentCount, useBullets, format) {
138
+ function docEntryToString({ entry, indentCount, useBullets, format, }) {
122
139
  const title = entry.title ? `${entry.title}: ` : '';
123
140
  const trimmedEntry = collapseWhiteSpace(entry.content);
124
141
  const content = useBullets ? code(trimmedEntry, format) : trimmedEntry;
@@ -126,9 +143,19 @@ function docEntryToString(entry, indentCount, useBullets, format) {
126
143
  }
127
144
  function commandDocToString(command, format, indentCount) {
128
145
  const sections = command.doc.sections.map((section) => docEntryToString({
129
- content: section,
130
- }, indentCount, false, format));
131
- const examples = command.doc.examples.map((example) => docEntryToString(example, indentCount + 1, true, format));
146
+ entry: {
147
+ content: section,
148
+ },
149
+ indentCount,
150
+ useBullets: false,
151
+ format,
152
+ }));
153
+ const examples = command.doc.examples.map((example) => docEntryToString({
154
+ entry: example,
155
+ indentCount: indentCount + 1,
156
+ useBullets: true,
157
+ format,
158
+ }));
132
159
  const exampleBlock = examples.length
133
160
  ? `${indent(indentCount + 1, format)}${format.bullet}Examples\n${examples.join('\n')}`
134
161
  : '';
package/dist/help.js CHANGED
@@ -18,5 +18,8 @@ export const virmatorHelpPlugin = defineVirmatorPlugin(import.meta.dirname, {
18
18
  },
19
19
  },
20
20
  }, ({ virmator: { allPlugins }, log }) => {
21
- log.plain(generateHelpMessageFromPlugins(allPlugins, HelpMessageSyntax.Cli));
21
+ log.plain(generateHelpMessageFromPlugins({
22
+ plugins: allPlugins,
23
+ syntax: HelpMessageSyntax.Cli,
24
+ }));
22
25
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virmator/help",
3
- "version": "14.26.0",
3
+ "version": "14.27.0",
4
4
  "description": "Default help plugin for virmator.",
5
5
  "keywords": [
6
6
  "virmator",
@@ -35,7 +35,7 @@
35
35
  "@augment-vir/assert": "^31.72.1",
36
36
  "@augment-vir/common": "^31.72.1",
37
37
  "@augment-vir/node": "^31.72.1",
38
- "@virmator/core": "^14.26.0"
38
+ "@virmator/core": "^14.27.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@augment-vir/test": "^31.72.1",