@bemoje/cli 0.0.2

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 (120) hide show
  1. package/README.md +34 -0
  2. package/index.cjs.d.ts +1 -0
  3. package/index.cjs.js +2682 -0
  4. package/index.esm.js +2558 -0
  5. package/package.json +36 -0
  6. package/src/core/CommandBuilder/ArgumentBuilder.d.ts +21 -0
  7. package/src/core/CommandBuilder/ArgumentReader.d.ts +15 -0
  8. package/src/core/CommandBuilder/Base.d.ts +5 -0
  9. package/src/core/CommandBuilder/CommandBuilder.d.ts +80 -0
  10. package/src/core/CommandBuilder/CommandBuilder.example.d.ts +1 -0
  11. package/src/core/CommandBuilder/CommandBuilderMetaData.d.ts +17 -0
  12. package/src/core/CommandBuilder/CommandFeatureSelector.d.ts +26 -0
  13. package/src/core/CommandBuilder/ErrorParser.d.ts +15 -0
  14. package/src/core/CommandBuilder/OptionBuilder.d.ts +27 -0
  15. package/src/core/CommandBuilder/OptionReader.d.ts +24 -0
  16. package/src/core/CommandBuilder/OutputManager.d.ts +47 -0
  17. package/src/core/CommandBuilder/assertCommandNameNotReserved.d.ts +1 -0
  18. package/src/core/CommandBuilder/ensureBackRefToCommandBuilder.d.ts +7 -0
  19. package/src/core/CommandBuilder/features/action/actionWrapper.d.ts +5 -0
  20. package/src/core/CommandBuilder/features/action/combineVariadicArgs.d.ts +3 -0
  21. package/src/core/CommandBuilder/features/action/debugLogArgsOpts.d.ts +4 -0
  22. package/src/core/CommandBuilder/features/action/deleteOptionsWithDefaultOrNoValue.d.ts +3 -0
  23. package/src/core/CommandBuilder/features/action/getPresetArgsAndOpts.d.ts +3 -0
  24. package/src/core/CommandBuilder/features/action/handleError.d.ts +2 -0
  25. package/src/core/CommandBuilder/features/action/handleOutputOptions.d.ts +2 -0
  26. package/src/core/CommandBuilder/features/action/optsWithGlobalsParsed.d.ts +2 -0
  27. package/src/core/CommandBuilder/features/action/padArgsWithUndefinedUntilExpectedLength.d.ts +3 -0
  28. package/src/core/CommandBuilder/features/action/parseArguments.d.ts +2 -0
  29. package/src/core/CommandBuilder/features/action/parseOptions.d.ts +6 -0
  30. package/src/core/CommandBuilder/features/action/parsedValidArgsOptsWithPresets.d.ts +2 -0
  31. package/src/core/CommandBuilder/features/action/parsedValidArgsWithPresets.d.ts +2 -0
  32. package/src/core/CommandBuilder/features/action/parsedValidOptsWithPresets.d.ts +3 -0
  33. package/src/core/CommandBuilder/features/addConfigCommands.d.ts +3 -0
  34. package/src/core/CommandBuilder/features/addPresetsCommands.d.ts +3 -0
  35. package/src/core/CommandBuilder/features/addUtilCommands.d.ts +2 -0
  36. package/src/core/CommandBuilder/features/assertNoDuplicateCommandNames.d.ts +2 -0
  37. package/src/core/CommandBuilder/features/assertNoDuplicateOptionNames.d.ts +2 -0
  38. package/src/core/CommandBuilder/features/autoAssignMissingOptionFlags.d.ts +14 -0
  39. package/src/core/CommandBuilder/features/autoAssignSubCommandAliases.d.ts +13 -0
  40. package/src/core/CommandBuilder/features/formatTableForTerminal.d.ts +1 -0
  41. package/src/core/CommandBuilder/features/getClosestNonNativeParent.d.ts +2 -0
  42. package/src/core/CommandBuilder/getGlobalOptions.d.ts +3 -0
  43. package/src/core/CommandBuilder/getOwnAndGlobalOptions.d.ts +3 -0
  44. package/src/core/CommandBuilder/initializeCommand.d.ts +2 -0
  45. package/src/core/db/AbstractJsonFileSection.d.ts +45 -0
  46. package/src/core/db/ConfigSection.d.ts +19 -0
  47. package/src/core/db/JsonDB.d.ts +19 -0
  48. package/src/core/db/JsonFile.d.ts +25 -0
  49. package/src/core/db/JsonFileError.d.ts +6 -0
  50. package/src/core/db/PresetsSection.d.ts +14 -0
  51. package/src/core/help/configureHelp.d.ts +2 -0
  52. package/src/core/util/MethodDisabler.d.ts +42 -0
  53. package/src/core/util/arrAssign.d.ts +1 -0
  54. package/src/core/util/assertPresetArgsOptional.d.ts +3 -0
  55. package/src/core/util/assertValidArguments.d.ts +6 -0
  56. package/src/core/util/assertValidOptions.d.ts +6 -0
  57. package/src/core/util/assertValidPreset.d.ts +3 -0
  58. package/src/core/util/commandExists.d.ts +5 -0
  59. package/src/core/util/commandLocation.d.ts +5 -0
  60. package/src/core/util/createArrayMerger.d.ts +1 -0
  61. package/src/core/util/createObjectMerger.d.ts +2 -0
  62. package/src/core/util/errorToString.d.ts +1 -0
  63. package/src/core/util/escapeShellCommandArgument.d.ts +5 -0
  64. package/src/core/util/forEachChildRecursive.d.ts +4 -0
  65. package/src/core/util/getARGV.d.ts +1 -0
  66. package/src/core/util/getAncestors.d.ts +7 -0
  67. package/src/core/util/getChildren.d.ts +4 -0
  68. package/src/core/util/getJsonFilepath.d.ts +2 -0
  69. package/src/core/util/getOptionArgumentName.d.ts +5 -0
  70. package/src/core/util/getRootCommand.d.ts +5 -0
  71. package/src/core/util/getSiblings.d.ts +5 -0
  72. package/src/core/util/hasVariadicArguments.d.ts +5 -0
  73. package/src/core/util/objAssign.d.ts +1 -0
  74. package/src/core/util/objDestroy.d.ts +2 -0
  75. package/src/core/util/optHasArgument.d.ts +2 -0
  76. package/src/core/util/prefixArray.d.ts +5 -0
  77. package/src/core/util/prefixString.d.ts +5 -0
  78. package/src/core/util/prefixStringsRecursive.d.ts +5 -0
  79. package/src/core/util/realizeLazyProperty.d.ts +1 -0
  80. package/src/core/util/renderOptionFlags.d.ts +6 -0
  81. package/src/core/util/setOptionLongName.d.ts +6 -0
  82. package/src/core/util/setOptionShortName.d.ts +6 -0
  83. package/src/core/util/splitCombinedArgvShorts.d.ts +1 -0
  84. package/src/core/util/walkAncestors.d.ts +7 -0
  85. package/src/core/util/walkChildren.d.ts +4 -0
  86. package/src/core/util/walkSiblings.d.ts +5 -0
  87. package/src/index.d.ts +113 -0
  88. package/src/parsers/createBooleanParser.d.ts +7 -0
  89. package/src/parsers/createTupleListParser.d.ts +11 -0
  90. package/src/parsers/createTypedListParser.d.ts +11 -0
  91. package/src/parsers/parseBoolean.d.ts +10 -0
  92. package/src/parsers/parseInteger.d.ts +1 -0
  93. package/src/parsers/parseNumber.d.ts +1 -0
  94. package/src/parsers/parseString.d.ts +1 -0
  95. package/src/parsers/selector/AbstractStringParserSelector.d.ts +17 -0
  96. package/src/parsers/selector/ArgumentParserSelector.d.ts +7 -0
  97. package/src/parsers/selector/OptionArgumentParserSelector.d.ts +7 -0
  98. package/src/types/IDefinePropertyOptions.d.ts +9 -0
  99. package/src/types/IPreset.d.ts +14 -0
  100. package/src/types/IPresets.d.ts +6 -0
  101. package/src/types/TStringParser.d.ts +1 -0
  102. package/src/types/TValidator.d.ts +2 -0
  103. package/src/validators/createLengthValidator.d.ts +7 -0
  104. package/src/validators/createTypedArrayValidator.d.ts +11 -0
  105. package/src/validators/isArray.d.ts +1 -0
  106. package/src/validators/isBoolean.d.ts +1 -0
  107. package/src/validators/isInteger.d.ts +1 -0
  108. package/src/validators/isIntegerArray.d.ts +4 -0
  109. package/src/validators/isNamedFunction.d.ts +5 -0
  110. package/src/validators/isNamedFunctionArray.d.ts +1 -0
  111. package/src/validators/isNull.d.ts +1 -0
  112. package/src/validators/isNumber.d.ts +1 -0
  113. package/src/validators/isNumberArray.d.ts +4 -0
  114. package/src/validators/isNumericString.d.ts +1 -0
  115. package/src/validators/isString.d.ts +1 -0
  116. package/src/validators/isStringArray.d.ts +4 -0
  117. package/src/validators/isStringWithNoSpacesOrDashes.d.ts +1 -0
  118. package/src/validators/selector/ArgumentValidatorSelector.d.ts +6 -0
  119. package/src/validators/selector/OptionArgumentValidatorSelector.d.ts +6 -0
  120. package/src/validators/selector/ValidatorSelector.d.ts +17 -0
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@bemoje/cli",
3
+ "version": "0.0.2",
4
+ "dependencies": {
5
+ "@bemoje/util": "latest",
6
+ "cli-table": "^0.3.11",
7
+ "commander": "^11.1.0",
8
+ "lookpath": "^1.2.2"
9
+ },
10
+ "type": "commonjs",
11
+ "main": "./index.cjs.js",
12
+ "module": "./index.esm.js",
13
+ "author": {
14
+ "name": "Benjamin Møller Jensen",
15
+ "email": "bemoje@bemoje.net",
16
+ "url": "https://github.com/bemoje/"
17
+ },
18
+ "license": "MIT",
19
+ "keywords": [],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/bemoje/tsmono.git"
23
+ },
24
+ "funding": {
25
+ "type": "patreon",
26
+ "url": "https://www.patreon.com/user?u=40752770"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/bemoje/tsmono/issues"
30
+ },
31
+ "homepage": "https://github.com/bemoje/tsmono",
32
+ "devDependencies": {
33
+ "@types/cli-table": "^0.3.4",
34
+ "@types/prompts": "^2.4.9"
35
+ }
36
+ }
@@ -0,0 +1,21 @@
1
+ import { Argument } from 'commander';
2
+ import { ArgumentParserSelector } from '../../parsers/selector/ArgumentParserSelector';
3
+ import { ArgumentReader } from './ArgumentReader';
4
+ import { ArgumentValidatorSelector } from '../../validators/selector/ArgumentValidatorSelector';
5
+ import { Base } from './Base';
6
+ import { CommandBuilder } from './CommandBuilder';
7
+ /**
8
+ * Wrapper around the @see Argument class, for more intuitive construction.
9
+ */
10
+ export declare class ArgumentBuilder extends Base {
11
+ readonly cmd: CommandBuilder;
12
+ readonly $: Argument;
13
+ readonly index: number;
14
+ constructor(cmd: CommandBuilder, name: string);
15
+ description(string: string): this;
16
+ default(value: unknown, description?: string): this;
17
+ choices(values: readonly string[]): this;
18
+ get parser(): ArgumentParserSelector;
19
+ get validator(): ArgumentValidatorSelector;
20
+ get get(): ArgumentReader;
21
+ }
@@ -0,0 +1,15 @@
1
+ import { ArgumentBuilder } from './ArgumentBuilder';
2
+ import { Base } from './Base';
3
+ export declare class ArgumentReader extends Base {
4
+ protected readonly parent: ArgumentBuilder;
5
+ constructor(parent: ArgumentBuilder);
6
+ get $(): import("commander").Argument;
7
+ get argument(): import("commander").Argument;
8
+ get name(): string;
9
+ get choices(): string[] | undefined;
10
+ get default(): any;
11
+ get description(): string;
12
+ get variadic(): boolean;
13
+ get required(): boolean;
14
+ get optional(): boolean;
15
+ }
@@ -0,0 +1,5 @@
1
+ export declare class Base {
2
+ static nextIndex: Record<string, number>;
3
+ id: number;
4
+ constructor();
5
+ }
@@ -0,0 +1,80 @@
1
+ import { Any, JsonValue } from '@bemoje/util';
2
+ import { ArgumentBuilder } from './ArgumentBuilder';
3
+ import { Base } from './Base';
4
+ import { Command, CommanderError, ErrorOptions } from 'commander';
5
+ import { CommandBuilderMetaData } from './CommandBuilderMetaData';
6
+ import { CommandFeatureSelector } from './CommandFeatureSelector';
7
+ import { IConfigDefinePropertyOptions } from '../../types/IDefinePropertyOptions';
8
+ import { IPresetPartial } from '../../types/IPreset';
9
+ import { JsonFile } from '../db/JsonFile';
10
+ import { OptionBuilder } from './OptionBuilder';
11
+ /**
12
+ * Wrapper around the @see Command class, for more intuitive construction.
13
+ */
14
+ export declare class CommandBuilder extends Base {
15
+ static dataDirectory: string;
16
+ readonly $: Command;
17
+ readonly parent: CommandBuilder | null;
18
+ readonly meta: CommandBuilderMetaData;
19
+ readonly get: CommandReader;
20
+ readonly features: CommandFeatureSelector;
21
+ constructor(name: string, callback?: (cmd: CommandBuilder) => void, parent?: CommandBuilder | null);
22
+ get db(): JsonFile;
23
+ get name(): string;
24
+ version(string: string): this;
25
+ alias(alias: string): this;
26
+ aliases(...aliases: string[]): this;
27
+ get isRoot(): boolean;
28
+ get arguments(): readonly import("commander").Argument[];
29
+ get options(): readonly import("commander").Option[];
30
+ enableBuiltinOptions(options?: {
31
+ help?: true;
32
+ debug?: true;
33
+ disableColor?: true;
34
+ disableStderr?: true;
35
+ disableStdout?: true;
36
+ }): void;
37
+ outputHelp(): void;
38
+ /**
39
+ * Display error message and exit (or call exitOverride).
40
+ */
41
+ outputUserError(message: string, options?: ErrorOptions): void;
42
+ description(...lines: string[]): this;
43
+ allowExcessArguments(bool?: boolean): this;
44
+ allowUnknownOption(bool?: boolean): this;
45
+ /**
46
+ * Register callback to use as replacement for calling process.exit.
47
+ */
48
+ exitOverride(callback?: (err: CommanderError) => never | void): this;
49
+ get root(): CommandBuilder;
50
+ /**
51
+ * Display error message and exit (or call exitOverride).
52
+ */
53
+ outputDebugInfo(event: string, getProps?: () => Record<string, unknown>): void;
54
+ hideGlobalOptions(...names: string[]): this;
55
+ unhideGlobalOptions(...names: string[]): this;
56
+ argument(name: string, description?: string): this;
57
+ argument(name: string, cb: (opt: ArgumentBuilder, cmd: this) => void): this;
58
+ option(flags: string, description?: string): this;
59
+ option(flags: string, cb?: (opt: OptionBuilder, cmd: this) => void): this;
60
+ globalOption(flags: string, description?: string): this;
61
+ globalOption(flags: string, cb?: (opt: OptionBuilder, cmd: this) => void): this;
62
+ command(name: string, cb: (cmd: CommandBuilder) => void): this;
63
+ nativeCommand(name: string, cb: (cmd: CommandBuilder) => void): this;
64
+ action<T extends (...args: Any[]) => Promise<void>>(fn: T): this;
65
+ config(key: string, entry: IConfigDefinePropertyOptions<JsonValue>): this;
66
+ preset(name: string, preset: IPresetPartial): this;
67
+ createMain(): (argv?: string[]) => Promise<void>;
68
+ }
69
+ export declare function CLI(name: string, callback: (cmd: CommandBuilder) => void): CommandBuilder;
70
+ export declare class CommandReader extends Base {
71
+ protected readonly cmd: CommandBuilder;
72
+ constructor(cmd: CommandBuilder);
73
+ get action(): ((...args: any[]) => Promise<void>) | undefined;
74
+ get description(): string;
75
+ get summary(): string;
76
+ get version(): string | undefined;
77
+ get alias(): string;
78
+ get aliases(): string[];
79
+ get renderHelp(): string;
80
+ }
@@ -0,0 +1,17 @@
1
+ import { Any } from '@bemoje/util';
2
+ import { Base } from './Base';
3
+ import { CommandBuilder } from './CommandBuilder';
4
+ import { Option } from 'commander';
5
+ import { TStringParser } from '../../types/TStringParser';
6
+ import { TValidator } from '../../types/TValidator';
7
+ export declare class CommandBuilderMetaData extends Base {
8
+ subcommands: CommandBuilder[];
9
+ globalOptions: Option[];
10
+ hiddenGlobalOptions: Set<Option>;
11
+ isNative: boolean;
12
+ actionHandler?: (...args: Any[]) => Promise<void>;
13
+ get argParsers(): TStringParser<Any>[];
14
+ get argValidators(): TValidator<Any>[][];
15
+ get optParsers(): Record<string, TStringParser<Any>>;
16
+ get optValidators(): Record<string, TValidator<Any>[]>;
17
+ }
@@ -0,0 +1,26 @@
1
+ import { Base } from './Base';
2
+ import { CommandBuilder } from './CommandBuilder';
3
+ /**
4
+ *
5
+ */
6
+ export declare class CommandFeatureSelector extends Base {
7
+ protected readonly cmd: CommandBuilder;
8
+ protected _utils: boolean;
9
+ protected _config: boolean;
10
+ protected _presets: boolean;
11
+ protected _autoAssignMissingOptionFlags: boolean;
12
+ protected _autoAssignSubCommandAliases: boolean;
13
+ constructor(cmd: CommandBuilder);
14
+ protected debugToggle(info: Record<string, boolean>): void;
15
+ utils(boolean?: boolean): this;
16
+ config(boolean?: boolean): this;
17
+ presets(boolean?: boolean): this;
18
+ autoAssignMissingOptionFlags(boolean?: boolean): this;
19
+ autoAssignSubCommandAliases(boolean?: boolean): this;
20
+ all(boolean?: boolean): CommandBuilder;
21
+ get isUtilsEnabled(): boolean;
22
+ get isConfigEnabled(): boolean;
23
+ get isPresetsEnabled(): boolean;
24
+ get isAutoAssignMissingOptionFlagsEnabled(): boolean;
25
+ get isAutoAssignSubCommandAliasesEnabled(): boolean;
26
+ }
@@ -0,0 +1,15 @@
1
+ export declare class ErrorParser {
2
+ readonly error: Error;
3
+ constructor(error: unknown);
4
+ get name(): string;
5
+ get message(): string;
6
+ get stack(): string;
7
+ summary(): string;
8
+ parseStackFrames(): [string, string][];
9
+ prettyStack(parsedStackFrames?: [string, string][]): string;
10
+ toObject(): any;
11
+ toJSON(): any;
12
+ }
13
+ export declare function errPrettyStack(error: Error, parsedStackFrames?: [string, string][]): string;
14
+ export declare function errParseStack(stack: string): [string, string][];
15
+ export declare function errToObject(error: Error): any;
@@ -0,0 +1,27 @@
1
+ import { Base } from './Base';
2
+ import { CommandBuilder } from './CommandBuilder';
3
+ import { Option, OptionValues } from 'commander';
4
+ import { OptionArgumentParserSelector } from '../../parsers/selector/OptionArgumentParserSelector';
5
+ import { OptionArgumentValidatorSelector } from '../../validators/selector/OptionArgumentValidatorSelector';
6
+ import { OptionReader } from './OptionReader';
7
+ /**
8
+ * Wrapper around the @see Option class, for more intuitive construction.
9
+ * @remarks Options are one of boolean, negated, required argument, or optional argument.
10
+ */
11
+ export declare class OptionBuilder extends Base {
12
+ readonly cmd: CommandBuilder;
13
+ readonly $: Option;
14
+ constructor(cmd: CommandBuilder, flags: string);
15
+ description(string: string): this;
16
+ hideHelp(hide?: boolean): this;
17
+ hidden(hidden?: boolean): this;
18
+ default(value: unknown, description?: string): this;
19
+ choices(values: readonly string[]): this;
20
+ conflicts(names: string | string[]): this;
21
+ implies(optionValues: OptionValues): this;
22
+ env(name: string): this;
23
+ short(short: string): this;
24
+ get parser(): OptionArgumentParserSelector;
25
+ get validator(): OptionArgumentValidatorSelector;
26
+ get get(): OptionReader;
27
+ }
@@ -0,0 +1,24 @@
1
+ import { Base } from './Base';
2
+ import { OptionBuilder } from './OptionBuilder';
3
+ export declare class OptionReader extends Base {
4
+ protected readonly parent: OptionBuilder;
5
+ constructor(parent: OptionBuilder);
6
+ get $(): import("commander").Option;
7
+ get option(): import("commander").Option;
8
+ get description(): string;
9
+ get optional(): boolean;
10
+ get mandatory(): boolean;
11
+ get hidden(): boolean;
12
+ get variadic(): boolean;
13
+ get short(): string | undefined;
14
+ get long(): string | undefined;
15
+ get default(): any;
16
+ get choices(): string[] | undefined;
17
+ get env(): string | undefined;
18
+ get flags(): string;
19
+ get name(): string;
20
+ get attributeName(): string;
21
+ get fullDescription(): string;
22
+ get defaultValueDescription(): string | undefined;
23
+ get hasArgument(): boolean;
24
+ }
@@ -0,0 +1,47 @@
1
+ import { Any } from '@bemoje/util';
2
+ import { MethodDisabler } from '../util/MethodDisabler';
3
+ /**
4
+ *
5
+ */
6
+ export declare class OutputManager {
7
+ private static instance;
8
+ static getInstance(): OutputManager;
9
+ readonly colors: {
10
+ enable: () => void;
11
+ disable: () => void;
12
+ reset: (this: any, txt: string) => any;
13
+ bold: (this: any, txt: string) => any;
14
+ dim: (this: any, txt: string) => any;
15
+ italic: (this: any, txt: string) => any;
16
+ underline: (this: any, txt: string) => any;
17
+ inverse: (this: any, txt: string) => any;
18
+ hidden: (this: any, txt: string) => any;
19
+ strikethrough: (this: any, txt: string) => any;
20
+ black: (this: any, txt: string) => any;
21
+ red: (this: any, txt: string) => any;
22
+ green: (this: any, txt: string) => any;
23
+ yellow: (this: any, txt: string) => any;
24
+ blue: (this: any, txt: string) => any;
25
+ magenta: (this: any, txt: string) => any;
26
+ cyan: (this: any, txt: string) => any;
27
+ white: (this: any, txt: string) => any;
28
+ gray: (this: any, txt: string) => any;
29
+ grey: (this: any, txt: string) => any;
30
+ bgBlack: (this: any, txt: string) => any;
31
+ bgRed: (this: any, txt: string) => any;
32
+ bgGreen: (this: any, txt: string) => any;
33
+ bgYellow: (this: any, txt: string) => any;
34
+ bgBlue: (this: any, txt: string) => any;
35
+ bgMagenta: (this: any, txt: string) => any;
36
+ bgCyan: (this: any, txt: string) => any;
37
+ bgWhite: (this: any, txt: string) => any;
38
+ };
39
+ readonly stdout: MethodDisabler;
40
+ readonly stderr: MethodDisabler;
41
+ readonly debug: MethodDisabler;
42
+ debugMsgs: (() => Any)[];
43
+ private constructor();
44
+ reset(): this;
45
+ outputDebug(fn: () => Any): void;
46
+ outputDebugMessages(): void;
47
+ }
@@ -0,0 +1 @@
1
+ export declare function assertCommandNameNotReserved(name: string): void;
@@ -0,0 +1,7 @@
1
+ import { CommandBuilder } from './CommandBuilder';
2
+ export declare function ensureBackRefToCommandBuilder(cmd: CommandBuilder): void;
3
+ declare module 'commander' {
4
+ interface Command {
5
+ get builder(): CommandBuilder;
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ import { CommandBuilder } from '../../CommandBuilder';
2
+ /**
3
+ *
4
+ */
5
+ export declare function actionWrapper(cmd: CommandBuilder): void;
@@ -0,0 +1,3 @@
1
+ import { Any } from '@bemoje/util';
2
+ import { CommandBuilder } from '../../CommandBuilder';
3
+ export declare function combineVariadicArgs(cmd: CommandBuilder, result: Any[]): any[];
@@ -0,0 +1,4 @@
1
+ import { Any } from '@bemoje/util';
2
+ import { CommandBuilder } from '../../CommandBuilder';
3
+ import { OptionValues } from 'commander';
4
+ export declare function debugLogArgsOpts(cb: CommandBuilder, args: Any[], opts: OptionValues, presetArgs: string[][], presetOpts: OptionValues[], presetOrder: string[]): void;
@@ -0,0 +1,3 @@
1
+ import { CommandBuilder } from '../../CommandBuilder';
2
+ import { OptionValues } from 'commander';
3
+ export declare function deleteOptionsWithDefaultOrNoValue(cmd: CommandBuilder, opts: OptionValues): OptionValues;
@@ -0,0 +1,3 @@
1
+ import { CommandBuilder } from '../../CommandBuilder';
2
+ import { OptionValues } from 'commander';
3
+ export declare function getPresetArgsAndOpts(cmd: CommandBuilder): [presetArgs: string[][], presetOpts: OptionValues[], presetOrder: string[]];
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../../CommandBuilder';
2
+ export declare function handleError(cmd: CommandBuilder, error: unknown): void;
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../../CommandBuilder';
2
+ export declare function handleOutputOptions(cmd: CommandBuilder): void;
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../../CommandBuilder';
2
+ export declare function optsWithGlobalsParsed(cmd: CommandBuilder): import("commander").OptionValues;
@@ -0,0 +1,3 @@
1
+ import { Any } from '@bemoje/util';
2
+ import { CommandBuilder } from '../../CommandBuilder';
3
+ export declare function padArgsWithUndefinedUntilExpectedLength(cmd: CommandBuilder, args: Any[]): any[];
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../../CommandBuilder';
2
+ export declare function parseArguments(cmd: CommandBuilder, args: string[]): any[];
@@ -0,0 +1,6 @@
1
+ import { CommandBuilder } from '../../CommandBuilder';
2
+ import { OptionValues } from 'commander';
3
+ /**
4
+ * Parses (and validates) options using the parsers defined in the command builder.
5
+ */
6
+ export declare function parseOptions(cmd: CommandBuilder, opts: OptionValues): OptionValues;
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../../CommandBuilder';
2
+ export declare function parsedValidArgsOptsWithPresets(cmd: CommandBuilder): any[];
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../../CommandBuilder';
2
+ export declare function parsedValidArgsWithPresets<T>(cmd: CommandBuilder, presetArgs: T[][]): any[];
@@ -0,0 +1,3 @@
1
+ import { CommandBuilder } from '../../CommandBuilder';
2
+ import { OptionValues } from 'commander';
3
+ export declare function parsedValidOptsWithPresets(cb: CommandBuilder, presetOpts: OptionValues[]): any;
@@ -0,0 +1,3 @@
1
+ import { CommandBuilder } from '../CommandBuilder';
2
+ export declare function addConfigCommands(cmd: CommandBuilder): void;
3
+ export declare const createConfig: (config: CommandBuilder) => void;
@@ -0,0 +1,3 @@
1
+ import { CommandBuilder } from '../CommandBuilder';
2
+ export declare function addPresetsCommands(cmd: CommandBuilder): void;
3
+ export declare const createPresets: (presets: CommandBuilder) => void;
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../CommandBuilder';
2
+ export declare function addUtilCommands(cmd: CommandBuilder): void;
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../CommandBuilder';
2
+ export declare function assertNoDuplicateCommandNames(cmd: CommandBuilder): void;
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../CommandBuilder';
2
+ export declare function assertNoDuplicateOptionNames(cmd: CommandBuilder): void;
@@ -0,0 +1,14 @@
1
+ import { CommandBuilder } from '../CommandBuilder';
2
+ /**
3
+ * Automatically set 'short' and 'long' names to options that don't have one assigned yet.
4
+ *
5
+ * First, it tries to assign a short name based on the first letter of the option's attribute name
6
+ * Both lower and upper case are tried. If these is not available, the next letter of the option name is tried.
7
+ *
8
+ * If none of the letters of the option name are available, the option is skipped until all other
9
+ * options have had letters from their names attempted assigned.
10
+ * Those that remain are assigned the first available letter of the alphabet + 0-9.
11
+ * If there are 64 options for the command and no more alphanumeric characters are available,
12
+ * the option is not assigned a short name.
13
+ */
14
+ export declare function autoAssignMissingOptionFlags(cmd: CommandBuilder): void;
@@ -0,0 +1,13 @@
1
+ import { CommandBuilder } from '../CommandBuilder';
2
+ /**
3
+ * Makes aliases for the command.
4
+ * The idea is to be able to navigate the command tree by only typing the first letter(s) of the command names.
5
+ *
6
+ * Example: A command 'cola' would get these aliases: ['c', 'co', 'col'].
7
+ * However, if there are namespace clashes with sibling subcommands that start with the same letter,
8
+ * eg. like 'cola' and 'coal' where the first two letters clash, cola's aliases are reduced to only ['col'] and similarly for 'coal'.
9
+ *
10
+ * This method creates the aliases, ensuring there are no clashes with sublings, why it is important that the
11
+ * entire command tree is built before invoking this method.
12
+ */
13
+ export declare function autoAssignSubCommandAliases(cmd: CommandBuilder): void;
@@ -0,0 +1 @@
1
+ export declare function formatTableForTerminal(rows: string[][], headers?: string[]): string;
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../CommandBuilder';
2
+ export declare function getClosestNonNativeParent(cmd: CommandBuilder): CommandBuilder;
@@ -0,0 +1,3 @@
1
+ import { CommandBuilder } from './CommandBuilder';
2
+ import { Option } from 'commander';
3
+ export declare function getGlobalOptions(cmd: CommandBuilder): Option[];
@@ -0,0 +1,3 @@
1
+ import { CommandBuilder } from './CommandBuilder';
2
+ import { Option } from 'commander';
3
+ export declare function getOwnAndGlobalOptions(cmd: CommandBuilder): Option[];
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from './CommandBuilder';
2
+ export declare function initializeCommand(cmd: CommandBuilder, callback?: (cmd: CommandBuilder) => void): CommandBuilder;
@@ -0,0 +1,45 @@
1
+ import { Any, JsonValue } from '@bemoje/util';
2
+ import { Base } from '../CommandBuilder/Base';
3
+ import { JsonFile } from './JsonFile';
4
+ /**
5
+ * A class that represents the a section of the JSON file used as simple database.
6
+ */
7
+ export declare abstract class AbstractJsonFileSection<Val = JsonValue> extends Base {
8
+ protected readonly file: JsonFile;
9
+ protected readonly name: string;
10
+ protected readonly hasFixedKeysForUser: boolean;
11
+ protected isInitialized: boolean;
12
+ protected isInitializing: boolean;
13
+ protected readonly _defaultValues: Record<string, Val>;
14
+ /**
15
+ * @param file The parent JsonFile instance.
16
+ * @param name The name of the section.
17
+ */
18
+ constructor(file: JsonFile, name: string, hasFixedKeysForUser: boolean);
19
+ abstract assertValid(key: string, value: Val): void;
20
+ abstract defineProperty(key: string, options: Any): void;
21
+ abstract initialize(save?: boolean): void | string;
22
+ get defaultValues(): Record<string, Val>;
23
+ /**
24
+ * Get the db lookup prefix for this section.
25
+ * @param key An optional key to append to the prefix.
26
+ */
27
+ protected prefix(key?: string): string;
28
+ get<T extends Val = Val>(key: string): T;
29
+ getAll(): typeof this.defaultValues;
30
+ count(): number;
31
+ set(key: string, value: Val, save?: boolean): void;
32
+ setAll(values: typeof this.defaultValues, save?: boolean): void;
33
+ reset(key: string, save?: boolean): void;
34
+ resetAll(save?: boolean): void;
35
+ /**
36
+ * Actions:
37
+ * - save the database to disk
38
+ * - verify that the JSON file is valid JSON data
39
+ * - format as human readable with 2 indents
40
+ */
41
+ protected save(): void;
42
+ delete(key: string, save?: boolean): void;
43
+ deleteAll(save?: boolean): void;
44
+ edit(editor?: string): void;
45
+ }
@@ -0,0 +1,19 @@
1
+ import { AbstractJsonFileSection } from './AbstractJsonFileSection';
2
+ import { JsonValue } from '@bemoje/util';
3
+ import { IConfigDefinePropertyOptions } from '../../types/IDefinePropertyOptions';
4
+ import { JsonFile } from './JsonFile';
5
+ import { TStringParser } from '../../types/TStringParser';
6
+ import { TValidator } from '../../types/TValidator';
7
+ /**
8
+ * A class that represents the user-config section of the JSON file used as simple database.
9
+ */
10
+ export declare class ConfigSection<Val extends JsonValue = JsonValue> extends AbstractJsonFileSection<Val> {
11
+ readonly descriptions: Record<string, string>;
12
+ readonly validators: Record<string, TValidator<Val>>;
13
+ readonly parsers: Record<string, TStringParser<Val>>;
14
+ constructor(file: JsonFile, name: string, hasFixedKeysForUser?: boolean);
15
+ assertValid(key: string, value: Val): void;
16
+ defineProperty(key: string, options: IConfigDefinePropertyOptions<Val>): void;
17
+ initialize(save?: boolean): void;
18
+ get keys(): string[];
19
+ }
@@ -0,0 +1,19 @@
1
+ import { JsonObject, JsonValue } from '@bemoje/util';
2
+ import { Base } from '../CommandBuilder/Base';
3
+ import { JsonFile } from './JsonFile';
4
+ export declare class JsonDB extends Base {
5
+ protected readonly file: JsonFile;
6
+ protected data: JsonObject;
7
+ readonly save: () => void;
8
+ /**
9
+ * @param filepath The path to the JSON file.
10
+ */
11
+ constructor(file: JsonFile);
12
+ get filepath(): string;
13
+ set(prefix?: string, value?: JsonValue, save?: boolean): void;
14
+ get<T = JsonValue>(prefix?: string): T;
15
+ getSafe<T = JsonValue>(prefix?: string): T | undefined;
16
+ has(prefix?: string): boolean;
17
+ delete(prefix?: string, save?: boolean): void;
18
+ protected cloneDeep(obj: JsonValue): any;
19
+ }
@@ -0,0 +1,25 @@
1
+ import { Base } from '../CommandBuilder/Base';
2
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
3
+ import { ConfigSection } from './ConfigSection';
4
+ import { JsonDB } from './JsonDB';
5
+ import { PresetsSection } from './PresetsSection';
6
+ /**
7
+ * A class that represents the JSON file used as a simple database.
8
+ */
9
+ export declare class JsonFile extends Base {
10
+ readonly cmd: CommandBuilder;
11
+ db: JsonDB;
12
+ /**
13
+ * @param cmd The parent CommandBuilder instance.
14
+ */
15
+ constructor(cmd: CommandBuilder);
16
+ /**
17
+ * A lazy-loaded instance of the `config` section of the JSON file.
18
+ * Upon first property access, it is stored as a property on the instance.
19
+ */
20
+ get config(): ConfigSection<import("dist/packages/util/src").JsonValue>;
21
+ /**
22
+ * A lazy-loaded instance of the `presets` section of the JSON file.
23
+ */
24
+ get presets(): PresetsSection;
25
+ }
@@ -0,0 +1,6 @@
1
+ import { XtError } from '@bemoje/util';
2
+ /**
3
+ * An error class for errors related to the JSON file used as simple database.
4
+ */
5
+ export declare class JsonFileError extends XtError {
6
+ }
@@ -0,0 +1,14 @@
1
+ import { AbstractJsonFileSection } from './AbstractJsonFileSection';
2
+ import { IPreset } from '../../types/IPreset';
3
+ import { JsonFile } from './JsonFile';
4
+ /**
5
+ * A class that represents the user-presets section of the JSON file used as simple database.
6
+ */
7
+ export declare class PresetsSection extends AbstractJsonFileSection<IPreset> {
8
+ constructor(file: JsonFile, name: string, hasFixedKeysForUser?: boolean);
9
+ assertValid(key: string, value: IPreset): void;
10
+ defineProperty(key: string, options: IPreset): void;
11
+ initialize(save?: boolean): void;
12
+ delete(name: string, save?: boolean): void;
13
+ setAll(presets: typeof this.defaultValues, save?: boolean): Promise<void>;
14
+ }
@@ -0,0 +1,2 @@
1
+ import { CommandBuilder } from '../CommandBuilder/CommandBuilder';
2
+ export declare function configureHelp(cmd: CommandBuilder): void;