@flowscripter/dynamic-cli-framework-api 1.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.
Files changed (174) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/dist/index.d.ts +74 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +29 -0
  6. package/dist/src/BaseCLIFeatureOptions.d.ts +12 -0
  7. package/dist/src/BaseCLIFeatureOptions.d.ts.map +1 -0
  8. package/dist/src/BaseCLIFeatureOptions.js +0 -0
  9. package/dist/src/CLI.d.ts +17 -0
  10. package/dist/src/CLI.d.ts.map +1 -0
  11. package/dist/src/CLI.js +0 -0
  12. package/dist/src/CLIConfig.d.ts +22 -0
  13. package/dist/src/CLIConfig.d.ts.map +1 -0
  14. package/dist/src/CLIConfig.js +0 -0
  15. package/dist/src/Context.d.ts +23 -0
  16. package/dist/src/Context.d.ts.map +1 -0
  17. package/dist/src/Context.js +0 -0
  18. package/dist/src/ParseResult.d.ts +33 -0
  19. package/dist/src/ParseResult.d.ts.map +1 -0
  20. package/dist/src/ParseResult.js +0 -0
  21. package/dist/src/RunResult.d.ts +128 -0
  22. package/dist/src/RunResult.d.ts.map +1 -0
  23. package/dist/src/RunResult.js +73 -0
  24. package/dist/src/argument/Argument.d.ts +62 -0
  25. package/dist/src/argument/Argument.d.ts.map +1 -0
  26. package/dist/src/argument/Argument.js +0 -0
  27. package/dist/src/argument/ArgumentValueTypes.d.ts +68 -0
  28. package/dist/src/argument/ArgumentValueTypes.d.ts.map +1 -0
  29. package/dist/src/argument/ArgumentValueTypes.js +18 -0
  30. package/dist/src/argument/ComplexOption.d.ts +21 -0
  31. package/dist/src/argument/ComplexOption.d.ts.map +1 -0
  32. package/dist/src/argument/ComplexOption.js +1 -0
  33. package/dist/src/argument/GlobalCommandArgument.d.ts +16 -0
  34. package/dist/src/argument/GlobalCommandArgument.d.ts.map +1 -0
  35. package/dist/src/argument/GlobalCommandArgument.js +0 -0
  36. package/dist/src/argument/Option.d.ts +29 -0
  37. package/dist/src/argument/Option.d.ts.map +1 -0
  38. package/dist/src/argument/Option.js +0 -0
  39. package/dist/src/argument/Positional.d.ts +26 -0
  40. package/dist/src/argument/Positional.d.ts.map +1 -0
  41. package/dist/src/argument/Positional.js +0 -0
  42. package/dist/src/argument/SubCommandArgument.d.ts +18 -0
  43. package/dist/src/argument/SubCommandArgument.d.ts.map +1 -0
  44. package/dist/src/argument/SubCommandArgument.js +1 -0
  45. package/dist/src/command/Command.d.ts +26 -0
  46. package/dist/src/command/Command.d.ts.map +1 -0
  47. package/dist/src/command/Command.js +0 -0
  48. package/dist/src/command/GlobalCommand.d.ts +28 -0
  49. package/dist/src/command/GlobalCommand.d.ts.map +1 -0
  50. package/dist/src/command/GlobalCommand.js +0 -0
  51. package/dist/src/command/GlobalModifierCommand.d.ts +12 -0
  52. package/dist/src/command/GlobalModifierCommand.d.ts.map +1 -0
  53. package/dist/src/command/GlobalModifierCommand.js +0 -0
  54. package/dist/src/command/GroupCommand.d.ts +19 -0
  55. package/dist/src/command/GroupCommand.d.ts.map +1 -0
  56. package/dist/src/command/GroupCommand.js +0 -0
  57. package/dist/src/command/SubCommand.d.ts +37 -0
  58. package/dist/src/command/SubCommand.d.ts.map +1 -0
  59. package/dist/src/command/SubCommand.js +0 -0
  60. package/dist/src/command/UsageExample.d.ts +20 -0
  61. package/dist/src/command/UsageExample.d.ts.map +1 -0
  62. package/dist/src/command/UsageExample.js +0 -0
  63. package/dist/src/plugin/CLIPlugin.d.ts +32 -0
  64. package/dist/src/plugin/CLIPlugin.d.ts.map +1 -0
  65. package/dist/src/plugin/CLIPlugin.js +2 -0
  66. package/dist/src/plugin/CommandFactory.d.ts +23 -0
  67. package/dist/src/plugin/CommandFactory.d.ts.map +1 -0
  68. package/dist/src/plugin/CommandFactory.js +7 -0
  69. package/dist/src/plugin/ServiceProviderFactory.d.ts +25 -0
  70. package/dist/src/plugin/ServiceProviderFactory.d.ts.map +1 -0
  71. package/dist/src/plugin/ServiceProviderFactory.js +7 -0
  72. package/dist/src/plugin/createCLIPlugin.d.ts +14 -0
  73. package/dist/src/plugin/createCLIPlugin.d.ts.map +1 -0
  74. package/dist/src/plugin/createCLIPlugin.js +30 -0
  75. package/dist/src/registry/CommandRegistry.d.ts +89 -0
  76. package/dist/src/registry/CommandRegistry.d.ts.map +1 -0
  77. package/dist/src/registry/CommandRegistry.js +0 -0
  78. package/dist/src/registry/ServiceProviderRegistry.d.ts +11 -0
  79. package/dist/src/registry/ServiceProviderRegistry.d.ts.map +1 -0
  80. package/dist/src/registry/ServiceProviderRegistry.js +0 -0
  81. package/dist/src/service/ServiceProvider.d.ts +47 -0
  82. package/dist/src/service/ServiceProvider.d.ts.map +1 -0
  83. package/dist/src/service/ServiceProvider.js +0 -0
  84. package/dist/src/service/core/ArgumentPrompterService.d.ts +6 -0
  85. package/dist/src/service/core/ArgumentPrompterService.d.ts.map +1 -0
  86. package/dist/src/service/core/ArgumentPrompterService.js +1 -0
  87. package/dist/src/service/core/AsciiBannerGeneratorService.d.ts +59 -0
  88. package/dist/src/service/core/AsciiBannerGeneratorService.d.ts.map +1 -0
  89. package/dist/src/service/core/AsciiBannerGeneratorService.js +1 -0
  90. package/dist/src/service/core/CompletionService.d.ts +22 -0
  91. package/dist/src/service/core/CompletionService.d.ts.map +1 -0
  92. package/dist/src/service/core/CompletionService.js +8 -0
  93. package/dist/src/service/core/DataDumpGeneratorService.d.ts +22 -0
  94. package/dist/src/service/core/DataDumpGeneratorService.d.ts.map +1 -0
  95. package/dist/src/service/core/DataDumpGeneratorService.js +7 -0
  96. package/dist/src/service/core/ImagePrinterService.d.ts +21 -0
  97. package/dist/src/service/core/ImagePrinterService.d.ts.map +1 -0
  98. package/dist/src/service/core/ImagePrinterService.js +1 -0
  99. package/dist/src/service/core/KeyValueService.d.ts +40 -0
  100. package/dist/src/service/core/KeyValueService.d.ts.map +1 -0
  101. package/dist/src/service/core/KeyValueService.js +7 -0
  102. package/dist/src/service/core/PluginService.d.ts +56 -0
  103. package/dist/src/service/core/PluginService.d.ts.map +1 -0
  104. package/dist/src/service/core/PluginService.js +6 -0
  105. package/dist/src/service/core/PrettyPrinterService.d.ts +35 -0
  106. package/dist/src/service/core/PrettyPrinterService.d.ts.map +1 -0
  107. package/dist/src/service/core/PrettyPrinterService.js +1 -0
  108. package/dist/src/service/core/PrinterService.d.ts +380 -0
  109. package/dist/src/service/core/PrinterService.d.ts.map +1 -0
  110. package/dist/src/service/core/PrinterService.js +42 -0
  111. package/dist/src/service/core/PrompterService.d.ts +35 -0
  112. package/dist/src/service/core/PrompterService.d.ts.map +1 -0
  113. package/dist/src/service/core/PrompterService.js +10 -0
  114. package/dist/src/service/core/SecretService.d.ts +25 -0
  115. package/dist/src/service/core/SecretService.d.ts.map +1 -0
  116. package/dist/src/service/core/SecretService.js +0 -0
  117. package/dist/src/service/core/ShutdownService.d.ts +24 -0
  118. package/dist/src/service/core/ShutdownService.d.ts.map +1 -0
  119. package/dist/src/service/core/ShutdownService.js +1 -0
  120. package/dist/src/service/core/SyntaxHighlighterService.d.ts +49 -0
  121. package/dist/src/service/core/SyntaxHighlighterService.d.ts.map +1 -0
  122. package/dist/src/service/core/SyntaxHighlighterService.js +1 -0
  123. package/dist/src/service/core/Table.d.ts +18 -0
  124. package/dist/src/service/core/Table.d.ts.map +1 -0
  125. package/dist/src/service/core/Table.js +49 -0
  126. package/dist/src/service/core/TableGeneratorService.d.ts +32 -0
  127. package/dist/src/service/core/TableGeneratorService.d.ts.map +1 -0
  128. package/dist/src/service/core/TableGeneratorService.js +7 -0
  129. package/dist/src/service/core/TreePrinterService.d.ts +9 -0
  130. package/dist/src/service/core/TreePrinterService.d.ts.map +1 -0
  131. package/dist/src/service/core/TreePrinterService.js +1 -0
  132. package/index.ts +138 -0
  133. package/package.json +66 -0
  134. package/src/CLI.ts +17 -0
  135. package/src/CLIConfig.ts +24 -0
  136. package/src/Context.ts +25 -0
  137. package/src/ParseResult.ts +40 -0
  138. package/src/RunResult.ts +158 -0
  139. package/src/argument/Argument.ts +75 -0
  140. package/src/argument/ArgumentValueTypes.ts +80 -0
  141. package/src/argument/ComplexOption.ts +27 -0
  142. package/src/argument/GlobalCommandArgument.ts +17 -0
  143. package/src/argument/Option.ts +32 -0
  144. package/src/argument/Positional.ts +27 -0
  145. package/src/argument/SubCommandArgument.ts +20 -0
  146. package/src/command/Command.ts +28 -0
  147. package/src/command/GlobalCommand.ts +30 -0
  148. package/src/command/GlobalModifierCommand.ts +12 -0
  149. package/src/command/GroupCommand.ts +20 -0
  150. package/src/command/SubCommand.ts +41 -0
  151. package/src/command/UsageExample.ts +21 -0
  152. package/src/plugin/CLIPlugin.ts +36 -0
  153. package/src/plugin/CommandFactory.ts +25 -0
  154. package/src/plugin/ServiceProviderFactory.ts +27 -0
  155. package/src/plugin/createCLIPlugin.ts +47 -0
  156. package/src/registry/CommandRegistry.ts +116 -0
  157. package/src/registry/ServiceProviderRegistry.ts +11 -0
  158. package/src/service/ServiceProvider.ts +52 -0
  159. package/src/service/core/ArgumentPrompterService.ts +8 -0
  160. package/src/service/core/AsciiBannerGeneratorService.ts +69 -0
  161. package/src/service/core/CompletionService.ts +32 -0
  162. package/src/service/core/DataDumpGeneratorService.ts +27 -0
  163. package/src/service/core/ImagePrinterService.ts +25 -0
  164. package/src/service/core/KeyValueService.ts +44 -0
  165. package/src/service/core/PluginService.ts +64 -0
  166. package/src/service/core/PrettyPrinterService.ts +39 -0
  167. package/src/service/core/PrinterService.ts +446 -0
  168. package/src/service/core/PrompterService.ts +42 -0
  169. package/src/service/core/SecretService.ts +27 -0
  170. package/src/service/core/ShutdownService.ts +27 -0
  171. package/src/service/core/SyntaxHighlighterService.ts +54 -0
  172. package/src/service/core/Table.ts +67 -0
  173. package/src/service/core/TableGeneratorService.ts +39 -0
  174. package/src/service/core/TreePrinterService.ts +10 -0
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The type of single {@link Argument} values which are supported.
3
+ *
4
+ * NOTE: JavaScript does not have a special runtime value for INTEGER so this is covered by `number`.
5
+ * NOTE: `string` is also used for PASSWORD values.
6
+ */
7
+ export type ArgumentSingleValueType = number | string | boolean;
8
+
9
+ /**
10
+ * The type of the value to be parsed as an argument can be: `boolean`, `number` or `string` or an array of these.
11
+ */
12
+ export type ArgumentValueType = ArgumentSingleValueType | Array<ArgumentSingleValueType>;
13
+
14
+ /**
15
+ * A container object for populated argument values.
16
+ *
17
+ * The following are all valid examples:
18
+ *
19
+ * * `{ }`
20
+ * * `{ foo: 1 }`
21
+ * * `{ foo: true }`
22
+ * * `{ foo: 'bar' }`
23
+ * * `{ foo: [ 1, 2 ] }`
24
+ * * `{ foo: [ true, true ] }`
25
+ * * `{ foo: [ 'bar', 'gar' ] }`
26
+ * * `{ foo: { a: 1 } }`
27
+ * * `{ foo: { a: { b: 'c'} } }`
28
+ * * `{ foo: [ { a: { b: 'c'} }, { a: { b: 'c'} } ] }`
29
+ *
30
+ * An array of arrays is not allowed, so the following is an INVALID example:
31
+ *
32
+ * * `{ foo: [ [ 1, 2 ], [3, 4 ] ] }`
33
+ */
34
+ export type ArgumentValues = {
35
+ [argName: string]: ArgumentValueType | ArgumentValues | Array<ArgumentValues>;
36
+ };
37
+
38
+ /**
39
+ * Enum of possible {@link Argument} value types.
40
+ */
41
+ export enum ArgumentValueTypeName {
42
+ STRING = 0,
43
+ NUMBER = 1,
44
+ INTEGER = 2,
45
+ BOOLEAN = 3,
46
+ SECRET = 4,
47
+ }
48
+
49
+ /**
50
+ * Only possible value for {@link ComplexOption.type}.
51
+ */
52
+ export enum ComplexValueTypeName {
53
+ COMPLEX = 5,
54
+ }
55
+
56
+ /**
57
+ * Populated single value type is very similar to {@link ArgumentSingleValueType} but allows for an illegal
58
+ * undefined value.
59
+ */
60
+ export type PopulatedArgumentSingleValueType = ArgumentSingleValueType | undefined;
61
+
62
+ /**
63
+ * Populated argument value types are very similar to {@link ArgumentValueType} but allow for illegal
64
+ * undefined values.
65
+ */
66
+ export type PopulatedArgumentValueType =
67
+ | PopulatedArgumentSingleValueType
68
+ | Array<PopulatedArgumentSingleValueType>;
69
+
70
+ /**
71
+ * Populated values are very similar to {@link ArgumentValues} but allow for illegal
72
+ * undefined properties and array entries.
73
+ */
74
+ export interface PopulatedArgumentValues {
75
+ [argName: string]:
76
+ | PopulatedArgumentValueType
77
+ | PopulatedArgumentValues
78
+ | Array<PopulatedArgumentValues | undefined>
79
+ | undefined;
80
+ }
@@ -0,0 +1,27 @@
1
+ import type Option from "./Option.ts";
2
+ import type { ArgumentValues, ComplexValueTypeName } from "./ArgumentValueTypes.ts";
3
+
4
+ export const MAXIMUM_COMPLEX_OPTION_NESTING_DEPTH = 10;
5
+
6
+ /**
7
+ * A container option argument for defining {@link SubCommand} nested argument hierarchies.
8
+ */
9
+ export default interface ComplexOption extends Omit<
10
+ Option,
11
+ "type" | "defaultValue" | "allowableValues"
12
+ > {
13
+ /**
14
+ * Type of the argument value.
15
+ */
16
+ readonly type: ComplexValueTypeName;
17
+
18
+ /**
19
+ * List of child {@link Option} properties.
20
+ */
21
+ readonly properties: ReadonlyArray<Option | ComplexOption>;
22
+
23
+ /**
24
+ * Default value for the argument if not specified.
25
+ */
26
+ readonly defaultValue?: ArgumentValues | Array<ArgumentValues>;
27
+ }
@@ -0,0 +1,17 @@
1
+ import type Argument from "./Argument.ts";
2
+ import type { ArgumentSingleValueType } from "./ArgumentValueTypes.ts";
3
+
4
+ /**
5
+ * Interface to be implemented by a single {@link Argument} defined by a {@link GlobalCommand}.
6
+ */
7
+ export default interface GlobalCommandArgument extends Argument {
8
+ /**
9
+ * Default value for the argument if not specified.
10
+ */
11
+ readonly defaultValue?: ArgumentSingleValueType;
12
+
13
+ /**
14
+ * If this is `true` the argument does not need to be specified nor have a default value. The default is `false`.
15
+ */
16
+ readonly isOptional?: boolean;
17
+ }
@@ -0,0 +1,32 @@
1
+ import type { ArgumentValueType } from "./ArgumentValueTypes.ts";
2
+ import type SubCommandArgument from "./SubCommandArgument.ts";
3
+
4
+ /**
5
+ * Interface for {@link SubCommand} option arguments.
6
+ */
7
+ export default interface Option extends SubCommandArgument {
8
+ /**
9
+ * Optional short alias for the option.
10
+ *
11
+ * Must consist of a single alphanumeric non-whitespace ASCII character.
12
+ */
13
+ readonly shortAlias?: string;
14
+
15
+ /**
16
+ * Default value for the argument if not specified.
17
+ */
18
+ readonly defaultValue?: ArgumentValueType;
19
+
20
+ /**
21
+ * If this is `true` the option does not need to be specified nor have a default value.
22
+ */
23
+ readonly isOptional?: boolean;
24
+
25
+ /**
26
+ * If this is `true` the option can be specified multiple times and all values will be returned in an array
27
+ * matching the order provided.
28
+ *
29
+ * NOTE: If {@link isOptional} is `false`, at least one instance of the option must be specified.
30
+ */
31
+ readonly isArray?: boolean;
32
+ }
@@ -0,0 +1,27 @@
1
+ import type SubCommandArgument from "./SubCommandArgument.ts";
2
+
3
+ /**
4
+ * Interface for {@link SubCommand} positional arguments.
5
+ */
6
+ export default interface Positional extends SubCommandArgument {
7
+ /**
8
+ * If this is `true` the argument can be specified one or multiple times and all values will be returned in
9
+ * an array matching the order provided.
10
+ *
11
+ * NOTE: If {@link isVarargOptional} is `true`, the argument can specified zero, one or multiple times.
12
+ *
13
+ * NOTE: There can be only one positional with this set and it must be the last the last item if there
14
+ * are multiple positionals defined.
15
+ */
16
+ readonly isVarargMultiple?: boolean;
17
+
18
+ /**
19
+ * If this is `true` the argument can be specified zero or once i.e. it does not need to be specified.
20
+ *
21
+ * NOTE: If {@link isVarargMultiple} is `true`, the argument can specified zero, one or multiple times.
22
+ *
23
+ * NOTE: There can be only one positional with this set and it must be the last the last item if there
24
+ * are multiple positionals defined.
25
+ */
26
+ readonly isVarargOptional?: boolean;
27
+ }
@@ -0,0 +1,20 @@
1
+ import type Argument from "./Argument.ts";
2
+
3
+ export const MAXIMUM_ARGUMENT_ARRAY_SIZE = 255;
4
+
5
+ /**
6
+ * Interface to be implemented by all {@link SubCommand} arguments.
7
+ */
8
+ export default interface SubCommandArgument extends Argument {
9
+ /**
10
+ * Name of the argument.
11
+ *
12
+ * Must consist of alphanumeric non-whitespace ASCII or `_` and `-` characters. Cannot start with `-`.
13
+ */
14
+ readonly name: string;
15
+
16
+ /**
17
+ * Optional description of the argument.
18
+ */
19
+ readonly description?: string;
20
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Common interface for all command types.
3
+ */
4
+ export default interface Command {
5
+ /**
6
+ * Name of the command.
7
+ *
8
+ * Must consist of alphanumeric non-whitespace ASCII or `_` and `-` characters. Cannot start with `-`.
9
+ */
10
+ readonly name: string;
11
+
12
+ /**
13
+ * Optional description of the command.
14
+ */
15
+ readonly description?: string;
16
+
17
+ /**
18
+ * Optionally enable support for populating argument values via configuration. If this is `true` then
19
+ * default argument values may be sourced using a configuration source provided by the CLI runtime.
20
+ */
21
+ readonly enableConfiguration?: boolean;
22
+
23
+ /**
24
+ * Optionally hide the command from generic help listings. The command remains registered and
25
+ * executable, and its own usage help (`help <command>`) is still shown if explicitly requested.
26
+ */
27
+ readonly disableGenericHelpDisplay?: boolean;
28
+ }
@@ -0,0 +1,30 @@
1
+ import type Command from "./Command.ts";
2
+ import type GlobalCommandArgument from "../argument/GlobalCommandArgument.ts";
3
+ import type Context from "../Context.ts";
4
+ import type { ArgumentSingleValueType } from "../argument/ArgumentValueTypes.ts";
5
+
6
+ /**
7
+ * Interface for a global command.
8
+ */
9
+ export default interface GlobalCommand extends Command {
10
+ /**
11
+ * Optional short alias for the global command.
12
+ *
13
+ * Must consist of a single alphanumeric non-whitespace ASCII character.
14
+ */
15
+ readonly shortAlias?: string;
16
+
17
+ /**
18
+ * Optional {@link GlobalCommandArgument} for the command.
19
+ */
20
+ readonly argument?: GlobalCommandArgument;
21
+
22
+ /**
23
+ * Execute the command.
24
+ *
25
+ * @param context the {@link Context} in which to execute the command.
26
+ * @param argumentValue optional argument value for the command. This will be populated unless
27
+ * the command's {@link GlobalCommandArgument} is optional and the argument value was not provided.
28
+ */
29
+ execute(context: Context, argumentValue?: ArgumentSingleValueType): Promise<void>;
30
+ }
@@ -0,0 +1,12 @@
1
+ import type GlobalCommand from "./GlobalCommand.ts";
2
+
3
+ /**
4
+ * Interface for a global modifier command.
5
+ */
6
+ export default interface GlobalModifierCommand extends GlobalCommand {
7
+ /**
8
+ * Used to determine the order in which multiple global modifier command instances
9
+ * parsed from the provided arguments will be executed. Higher values will execute before lower values.
10
+ */
11
+ readonly executePriority: number;
12
+ }
@@ -0,0 +1,20 @@
1
+ import type SubCommand from "./SubCommand.ts";
2
+ import type Command from "./Command.ts";
3
+ import type Context from "../Context.ts";
4
+
5
+ /**
6
+ * Interface for a group command.
7
+ */
8
+ export default interface GroupCommand extends Command {
9
+ /**
10
+ * Array of {@link SubCommand} instances for this group command. Must contain at least one sub-command.
11
+ */
12
+ readonly memberSubCommands: ReadonlyArray<SubCommand>;
13
+
14
+ /**
15
+ * Execute the command.
16
+ *
17
+ * @param context the {@link Context} in which to execute the command.
18
+ */
19
+ execute(context: Context): Promise<void>;
20
+ }
@@ -0,0 +1,41 @@
1
+ import type Command from "./Command.ts";
2
+ import type Option from "../argument/Option.ts";
3
+ import type Positional from "../argument/Positional.ts";
4
+ import type UsageExample from "./UsageExample.ts";
5
+ import type ComplexOption from "../argument/ComplexOption.ts";
6
+ import type { ArgumentValues } from "../argument/ArgumentValueTypes.ts";
7
+ import type Context from "../Context.ts";
8
+
9
+ /**
10
+ * Interface for a sub-command.
11
+ */
12
+ export default interface SubCommand extends Command {
13
+ /**
14
+ * {@link Option} or {@link ComplexOption} argument definitions for the sub-command.
15
+ */
16
+ readonly options: ReadonlyArray<Option | ComplexOption>;
17
+
18
+ /**
19
+ * {@link Positional} argument definitions for the sub-command.
20
+ */
21
+ readonly positionals: ReadonlyArray<Positional>;
22
+
23
+ /**
24
+ * Optional grouping topic of the command for structuring of help output.
25
+ */
26
+ readonly helpTopic?: string;
27
+
28
+ /**
29
+ * Optional usage examples for the command to support help output.
30
+ */
31
+ readonly usageExamples?: ReadonlyArray<UsageExample>;
32
+
33
+ /**
34
+ * Execute the command.
35
+ *
36
+ * @param context the {@link Context} in which to execute the command.
37
+ * @param argumentValues the argument values for the command. This may be empty if
38
+ * the command's {@link Option} and {@link Positional} instances are all optional and no argument values were provided.
39
+ */
40
+ execute(context: Context, argumentValues: ArgumentValues): Promise<void>;
41
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A usage example for a {@link SubCommand} to be used in help output.
3
+ */
4
+ export default interface UsageExample {
5
+ /**
6
+ * The example arguments used to generate an example invocation.
7
+ *
8
+ * This should not include the CLI or command name.
9
+ */
10
+ readonly exampleArguments: string;
11
+
12
+ /**
13
+ * Optional description of the command example.
14
+ */
15
+ readonly description?: string;
16
+
17
+ /**
18
+ * Optional output result of executing the example command.
19
+ */
20
+ readonly output?: ReadonlyArray<string>;
21
+ }
@@ -0,0 +1,36 @@
1
+ import type { Plugin, ExtensionDescriptor } from "@flowscripter/dynamic-plugin-framework";
2
+ import type CommandFactory from "./CommandFactory.ts";
3
+ import { DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT } from "./CommandFactory.ts";
4
+ import type ServiceProviderFactory from "./ServiceProviderFactory.ts";
5
+ import { DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT } from "./ServiceProviderFactory.ts";
6
+
7
+ /**
8
+ * {@link ExtensionDescriptor} for a {@link CommandFactory} extension.
9
+ */
10
+ export interface CommandFactoryExtensionDescriptor extends ExtensionDescriptor {
11
+ readonly extensionPoint: typeof DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT;
12
+ readonly factory: {
13
+ create(hostData?: Map<string, string>): Promise<CommandFactory>;
14
+ };
15
+ }
16
+
17
+ /**
18
+ * {@link ExtensionDescriptor} for a {@link ServiceProviderFactory} extension.
19
+ */
20
+ export interface ServiceProviderFactoryExtensionDescriptor extends ExtensionDescriptor {
21
+ readonly extensionPoint: typeof DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT;
22
+ readonly factory: {
23
+ create(hostData?: Map<string, string>): Promise<ServiceProviderFactory>;
24
+ };
25
+ }
26
+
27
+ /**
28
+ * A {@link Plugin} for `DynamicPluginRuntimeCLI` (see dynamic-cli-framework) whose
29
+ * {@link extensionDescriptors} are limited to the {@link CommandFactory} and
30
+ * {@link ServiceProviderFactory} extension points.
31
+ */
32
+ export default interface CLIPlugin extends Plugin {
33
+ readonly extensionDescriptors: ReadonlyArray<
34
+ CommandFactoryExtensionDescriptor | ServiceProviderFactoryExtensionDescriptor
35
+ >;
36
+ }
@@ -0,0 +1,25 @@
1
+ import type Command from "../command/Command.ts";
2
+
3
+ /**
4
+ * Extension point identifier for {@link CommandFactory} extensions.
5
+ *
6
+ * Plugins register against this extension point to supply {@link Command} instances
7
+ * that are added to the CLI before execution begins.
8
+ */
9
+ export const DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT =
10
+ "DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY";
11
+
12
+ /**
13
+ * Extension interface implemented by a plugin to provide {@link Command} instances.
14
+ *
15
+ * A plugin registers an {@link CommandFactory} against
16
+ * {@link DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT}. On startup,
17
+ * `DynamicPluginRuntimeCLI` (see dynamic-cli-framework) instantiates each factory
18
+ * and adds the returned commands to the CLI registry before the runner executes.
19
+ */
20
+ export default interface CommandFactory {
21
+ /**
22
+ * Return the {@link Command} instances provided by this factory.
23
+ */
24
+ getCommands(): ReadonlyArray<Command>;
25
+ }
@@ -0,0 +1,27 @@
1
+ import type { ServiceProvider } from "../service/ServiceProvider.ts";
2
+
3
+ /**
4
+ * Extension point identifier for {@link ServiceProviderFactory} extensions.
5
+ *
6
+ * Plugins register against this extension point to supply {@link ServiceProvider} instances
7
+ * that are initialised by the runner as part of the normal service lifecycle.
8
+ */
9
+ export const DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT =
10
+ "DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY";
11
+
12
+ /**
13
+ * Extension interface implemented by a plugin to provide {@link ServiceProvider} instances.
14
+ *
15
+ * A plugin registers a {@link ServiceProviderFactory} against
16
+ * {@link DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT}. On startup,
17
+ * `DynamicPluginRuntimeCLI` (see dynamic-cli-framework) instantiates each factory
18
+ * and adds the returned service providers to the CLI registry before the runner
19
+ * executes, so they participate in the full initialization lifecycle (including
20
+ * {@link GlobalModifierCommand} scanning and {@link ServiceProvider.initService}).
21
+ */
22
+ export default interface ServiceProviderFactory {
23
+ /**
24
+ * Return the {@link ServiceProvider} instances provided by this factory.
25
+ */
26
+ getServiceProviders(): ReadonlyArray<ServiceProvider>;
27
+ }
@@ -0,0 +1,47 @@
1
+ import type CommandFactory from "./CommandFactory.ts";
2
+ import { DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT } from "./CommandFactory.ts";
3
+ import type ServiceProviderFactory from "./ServiceProviderFactory.ts";
4
+ import { DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT } from "./ServiceProviderFactory.ts";
5
+ import type CLIPlugin from "./CLIPlugin.ts";
6
+
7
+ export interface CLIPluginOptions {
8
+ readonly commandFactory?: CommandFactory | (() => Promise<CommandFactory>);
9
+ readonly serviceProviderFactory?:
10
+ | ServiceProviderFactory
11
+ | (() => Promise<ServiceProviderFactory>);
12
+ readonly pluginData?: ReadonlyMap<string, string>;
13
+ }
14
+
15
+ /**
16
+ * Build a {@link CLIPlugin} from optional {@link CommandFactory} and {@link ServiceProviderFactory}
17
+ * instances (or factory functions), without needing to hand-construct extension descriptors.
18
+ */
19
+ export default function createCLIPlugin(options: CLIPluginOptions): CLIPlugin {
20
+ const extensionDescriptors: CLIPlugin["extensionDescriptors"][number][] = [];
21
+
22
+ if (options.commandFactory) {
23
+ const commandFactory = options.commandFactory;
24
+ extensionDescriptors.push({
25
+ extensionPoint: DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT,
26
+ factory: {
27
+ create: async () =>
28
+ typeof commandFactory === "function" ? commandFactory() : commandFactory,
29
+ },
30
+ });
31
+ }
32
+
33
+ if (options.serviceProviderFactory) {
34
+ const serviceProviderFactory = options.serviceProviderFactory;
35
+ extensionDescriptors.push({
36
+ extensionPoint: DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT,
37
+ factory: {
38
+ create: async () =>
39
+ typeof serviceProviderFactory === "function"
40
+ ? serviceProviderFactory()
41
+ : serviceProviderFactory,
42
+ },
43
+ });
44
+ }
45
+
46
+ return { extensionDescriptors, pluginData: options.pluginData };
47
+ }
@@ -0,0 +1,116 @@
1
+ import type GroupCommand from "../command/GroupCommand.ts";
2
+ import type SubCommand from "../command/SubCommand.ts";
3
+ import type GlobalCommand from "../command/GlobalCommand.ts";
4
+ import type GlobalModifierCommand from "../command/GlobalModifierCommand.ts";
5
+ import type Command from "../command/Command.ts";
6
+
7
+ /**
8
+ * Interface used by a {@link CLI} to register {@link Command} instances.
9
+ */
10
+ export default interface CommandRegistry {
11
+ /**
12
+ * Get all registered {@link SubCommand} instances.
13
+ */
14
+ getSubCommands(): ReadonlyArray<SubCommand>;
15
+
16
+ /**
17
+ * Get all registered {@link GroupCommand} instances.
18
+ */
19
+ getGroupCommands(): ReadonlyArray<GroupCommand>;
20
+
21
+ /**
22
+ * Get all registered {@link GlobalCommand} instances.
23
+ */
24
+ getGlobalCommands(): ReadonlyArray<GlobalCommand>;
25
+
26
+ /**
27
+ * Get all registered {@link GlobalModifierCommand} instances.
28
+ */
29
+ getGlobalModifierCommands(): ReadonlyArray<GlobalModifierCommand>;
30
+
31
+ /**
32
+ * Get a registered {@link SubCommand} by name.
33
+ */
34
+ getSubCommandByName(name: string): SubCommand | undefined;
35
+
36
+ /**
37
+ * Get a registered {@link GroupCommand} by name.
38
+ */
39
+ getGroupCommandByName(name: string): GroupCommand | undefined;
40
+
41
+ /**
42
+ * Get a registered {@link GroupCommand} and member {@link SubCommand} by
43
+ * combined name e.g. `<group-command-name>:<member-sub-command-name>`.
44
+ */
45
+ getGroupCommandAndMemberSubCommandByJoinedName(
46
+ getGroupCommandAndMemberSubCommandByName: string,
47
+ ): { groupCommand: GroupCommand; command: SubCommand } | undefined;
48
+
49
+ /**
50
+ * Get a registered {@link GlobalCommand} by name.
51
+ */
52
+ getGlobalCommandByName(name: string): GlobalCommand | undefined;
53
+
54
+ /**
55
+ * Get a registered {@link GlobalCommand} by short alias.
56
+ */
57
+ // getGlobalCommandByShortAlias(shortAlias: string): GlobalCommand | undefined;
58
+
59
+ /**
60
+ * Get a registered {@link GlobalModifierCommand} by name.
61
+ */
62
+ getGlobalModifierCommandByName(name: string): GlobalModifierCommand | undefined;
63
+
64
+ /**
65
+ * Get a registered {@link GlobalModifierCommand} by short alias.
66
+ */
67
+ // getGlobalModifierCommandByShortAlias(
68
+ // shortAlias: string,
69
+ // ): GlobalModifierCommand | undefined;
70
+
71
+ /**
72
+ * Get a map of all registered {@link GroupCommand} and member {@link SubCommand} instance combinations by
73
+ * combined name e.g. `<group-command-name>:<member-sub-command-name>`.
74
+ */
75
+ getGroupAndMemberCommandsByJoinedName(): ReadonlyMap<
76
+ string,
77
+ { groupCommand: GroupCommand; command: SubCommand }
78
+ >;
79
+
80
+ /**
81
+ * Get a map of all registered {@link GlobalModifierCommand} instances by name provided by the specified service.
82
+ */
83
+ getGlobalModifierCommandsByNameProvidedByService(
84
+ serviceId: string,
85
+ ): ReadonlyMap<string, GlobalModifierCommand>;
86
+
87
+ /**
88
+ * Get a map of all registered {@link GlobalModifierCommand} instances by short alias provided by the specified service.
89
+ */
90
+ getGlobalModifierCommandsByShortAliasProvidedByService(
91
+ serviceId: string,
92
+ ): ReadonlyMap<string, GlobalModifierCommand>;
93
+
94
+ /**
95
+ * Get a map of all registered {@link GlobalModifierCommand} instances by name not provided by a service.
96
+ */
97
+ getGlobalModifierCommandsByNameNotProvidedByService(): ReadonlyMap<string, GlobalModifierCommand>;
98
+
99
+ /**
100
+ * Get a map of all registered {@link GlobalModifierCommand} instances by short alias not provided by a service.
101
+ */
102
+ getGlobalModifierCommandsByShortAliasNotProvidedByService(): ReadonlyMap<
103
+ string,
104
+ GlobalModifierCommand
105
+ >;
106
+
107
+ /**
108
+ * Get a map of all registered non-modifier {@link Command} instances by name.
109
+ */
110
+ getNonModifierCommandsByName(): ReadonlyMap<string, Command>;
111
+
112
+ /**
113
+ * Get a map of all registered {@link GlobalCommand} instances by short alias.
114
+ */
115
+ getGlobalCommandsByShortAlias(): ReadonlyMap<string, GlobalCommand>;
116
+ }
@@ -0,0 +1,11 @@
1
+ import type { ServiceProvider } from "../service/ServiceProvider.ts";
2
+
3
+ /**
4
+ * Interface used by a {@link CLI} to register {@link ServiceProvider} instances.
5
+ */
6
+ export default interface ServiceProviderRegistry {
7
+ /**
8
+ * Return all {@link ServiceProvider} instances registered in order of descending {@link ServiceProvider.servicePriority}
9
+ */
10
+ getServiceProviders(): ReadonlyArray<ServiceProvider>;
11
+ }