talented-args 0.2.5-beta → 0.3.0-beta

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 (70) hide show
  1. package/README.md +485 -14
  2. package/dist/clipboard.d.ts +10 -0
  3. package/dist/clipboard.js +79 -0
  4. package/dist/clipboard.js.map +1 -0
  5. package/dist/compile.d.ts +67 -0
  6. package/dist/compile.js +188 -0
  7. package/dist/compile.js.map +1 -0
  8. package/dist/descriptors.d.ts +322 -0
  9. package/dist/descriptors.js +362 -0
  10. package/dist/descriptors.js.map +1 -0
  11. package/dist/display.d.ts +31 -0
  12. package/dist/display.js +235 -0
  13. package/dist/display.js.map +1 -0
  14. package/dist/errors.d.ts +34 -17
  15. package/dist/errors.js +61 -75
  16. package/dist/errors.js.map +1 -1
  17. package/dist/index.d.ts +10 -6
  18. package/dist/index.js +8 -9
  19. package/dist/index.js.map +1 -1
  20. package/dist/options.d.ts +69 -41
  21. package/dist/options.js +198 -31
  22. package/dist/options.js.map +1 -1
  23. package/dist/parse.d.ts +70 -0
  24. package/dist/parse.js +551 -0
  25. package/dist/parse.js.map +1 -0
  26. package/dist/program.d.ts +125 -0
  27. package/dist/program.js +337 -0
  28. package/dist/program.js.map +1 -0
  29. package/dist/remember.d.ts +71 -0
  30. package/dist/remember.js +216 -0
  31. package/dist/remember.js.map +1 -0
  32. package/dist/styling.d.ts +38 -9
  33. package/dist/styling.js +155 -75
  34. package/dist/styling.js.map +1 -1
  35. package/dist/terminal.d.ts +205 -0
  36. package/dist/terminal.js +152 -0
  37. package/dist/terminal.js.map +1 -0
  38. package/dist/tools.d.ts +35 -31
  39. package/dist/tools.js +68 -140
  40. package/dist/tools.js.map +1 -1
  41. package/dist/tui.d.ts +96 -0
  42. package/dist/tui.js +397 -0
  43. package/dist/tui.js.map +1 -0
  44. package/dist/tui_layout.d.ts +152 -0
  45. package/dist/tui_layout.js +554 -0
  46. package/dist/tui_layout.js.map +1 -0
  47. package/dist/tui_model.d.ts +149 -0
  48. package/dist/tui_model.js +666 -0
  49. package/dist/tui_model.js.map +1 -0
  50. package/package.json +18 -14
  51. package/.eslintrc.js +0 -24
  52. package/.idea/codeStyles/Project.xml +0 -364
  53. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  54. package/.idea/compiler.xml +0 -7
  55. package/.idea/encodings.xml +0 -6
  56. package/.idea/inspectionProfiles/Project_Default.xml +0 -12
  57. package/.idea/jsLibraryMappings.xml +0 -6
  58. package/.idea/modules.xml +0 -8
  59. package/.idea/prettier.xml +0 -8
  60. package/.idea/talented-args.iml +0 -11
  61. package/.idea/vcs.xml +0 -6
  62. package/.prettierrc.yaml +0 -4
  63. package/dist/definitions.d.ts +0 -70
  64. package/dist/definitions.js +0 -38
  65. package/dist/definitions.js.map +0 -1
  66. package/dist/main.d.ts +0 -33
  67. package/dist/main.js +0 -313
  68. package/dist/main.js.map +0 -1
  69. package/jest.config.js +0 -4
  70. package/tsconfig.json +0 -18
package/dist/errors.d.ts CHANGED
@@ -5,25 +5,42 @@ export declare class TalentedArgsError extends Error {
5
5
  status: number;
6
6
  constructor(message: string, status: number);
7
7
  }
8
- export declare class InvalidCommandError extends TalentedArgsError {
9
- command: string;
10
- available: string[];
11
- constructor(command: string, available: string[]);
12
- }
13
- export declare class InvalidArgDefinitionError extends TalentedArgsError {
14
- reason: string;
15
- constructor(reason: string);
16
- }
17
- export declare class OptionsValidationError extends TalentedArgsError {
8
+ /**
9
+ * Invalid library options or argument definitions, such as conflicting option names.
10
+ * Also used for unsupported converter results and invalid help requests.
11
+ */
12
+ export declare class DefinitionError extends TalentedArgsError {
18
13
  reason: string;
19
14
  constructor(reason: string);
20
15
  }
21
- export declare class DefinitionValidationError extends TalentedArgsError {
22
- reason: string;
23
- constructor(reason: string);
16
+ export declare const USAGE_ERROR_CODES: readonly ["unknown_command", "unknown_option", "missing_value", "unexpected_value", "unexpected_argument", "duplicate_option", "invalid_value", "missing_required", "not_interactive"];
17
+ export type IUsageErrorCode = (typeof USAGE_ERROR_CODES)[number];
18
+ /** One error in the supplied command line. */
19
+ export interface IUsageIssue {
20
+ code: IUsageErrorCode;
21
+ /** Plain text explanation without terminal styling. */
22
+ message: string;
23
+ /** Option name associated with the issue, such as `--port`, or `null` if none applies. */
24
+ option: string | null;
24
25
  }
25
- export declare class InvalidConsoleColorError extends TalentedArgsError {
26
- style: string;
27
- supported_values: string[];
28
- constructor(style: string, supported_values: string[]);
26
+ /**
27
+ * The supplied command line is invalid.
28
+ * `parse()` throws this error. `parseOrDie()` prints its issues and exits with code 1.
29
+ */
30
+ export declare class UsageError extends TalentedArgsError {
31
+ issues: readonly [IUsageIssue, ...IUsageIssue[]];
32
+ /** Error code of the first issue. */
33
+ code: IUsageErrorCode;
34
+ /** Option name of the first issue, or `null` if none applies. */
35
+ option: string | null;
36
+ constructor(issues: readonly [IUsageIssue, ...IUsageIssue[]]);
29
37
  }
38
+ /** Process exit codes used by `parseOrDie()`. */
39
+ export declare const EXIT_CODES: {
40
+ readonly help: 0;
41
+ /** Interactive mode copied the command line without running it. */
42
+ readonly copied: 0;
43
+ readonly usage: 1;
44
+ /** Interactive mode was cancelled. Matches the shell exit code for Ctrl-C. */
45
+ readonly cancelled: 130;
46
+ };
package/dist/errors.js CHANGED
@@ -1,86 +1,72 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.InvalidConsoleColorError = exports.DefinitionValidationError = exports.OptionsValidationError = exports.InvalidArgDefinitionError = exports.InvalidCommandError = exports.TalentedArgsError = void 0;
19
- var TalentedArgsError = /** @class */ (function (_super) {
20
- __extends(TalentedArgsError, _super);
21
- function TalentedArgsError(message, status) {
22
- var _this = _super.call(this, message) || this;
3
+ exports.EXIT_CODES = exports.UsageError = exports.USAGE_ERROR_CODES = exports.DefinitionError = exports.TalentedArgsError = void 0;
4
+ class TalentedArgsError extends Error {
5
+ /** Error name, derived from constructor. This is the primary distinguishing characteristic between errors */
6
+ name;
7
+ /** Status code, roughly matches HTTP error codes */
8
+ status;
9
+ constructor(message, status) {
10
+ super(message);
23
11
  // Make message and stack appear when error is JSON-ified
24
- Object.defineProperties(_this, {
12
+ Object.defineProperties(this, {
25
13
  message: { enumerable: true, writable: true },
26
14
  stack: { enumerable: true, writable: true },
27
15
  });
28
- _this.status = status;
29
- return _this;
16
+ this.name = new.target.name;
17
+ this.status = status;
30
18
  }
31
- return TalentedArgsError;
32
- }(Error));
19
+ }
33
20
  exports.TalentedArgsError = TalentedArgsError;
34
- var InvalidCommandError = /** @class */ (function (_super) {
35
- __extends(InvalidCommandError, _super);
36
- function InvalidCommandError(command, available) {
37
- var _this = _super.call(this, "Invalid command: ".concat(command, ". Must be one of\" ").concat(available.map(function (x) { return "\"".concat(x, "\""); }).join(', ')), 500) || this;
38
- _this.command = command;
39
- _this.available = available;
40
- return _this;
21
+ /**
22
+ * Invalid library options or argument definitions, such as conflicting option names.
23
+ * Also used for unsupported converter results and invalid help requests.
24
+ */
25
+ class DefinitionError extends TalentedArgsError {
26
+ reason;
27
+ constructor(reason) {
28
+ super(`Invalid definition: ${reason}`, 500);
29
+ this.reason = reason;
41
30
  }
42
- return InvalidCommandError;
43
- }(TalentedArgsError));
44
- exports.InvalidCommandError = InvalidCommandError;
45
- var InvalidArgDefinitionError = /** @class */ (function (_super) {
46
- __extends(InvalidArgDefinitionError, _super);
47
- function InvalidArgDefinitionError(reason) {
48
- var _this = _super.call(this, "Invalid arg definition: ".concat(reason), 500) || this;
49
- _this.reason = reason;
50
- return _this;
31
+ }
32
+ exports.DefinitionError = DefinitionError;
33
+ exports.USAGE_ERROR_CODES = [
34
+ 'unknown_command',
35
+ 'unknown_option',
36
+ 'missing_value',
37
+ 'unexpected_value',
38
+ 'unexpected_argument',
39
+ 'duplicate_option',
40
+ 'invalid_value',
41
+ 'missing_required',
42
+ 'not_interactive',
43
+ ];
44
+ /**
45
+ * The supplied command line is invalid.
46
+ * `parse()` throws this error. `parseOrDie()` prints its issues and exits with code 1.
47
+ */
48
+ class UsageError extends TalentedArgsError {
49
+ issues;
50
+ /** Error code of the first issue. */
51
+ code;
52
+ /** Option name of the first issue, or `null` if none applies. */
53
+ option;
54
+ constructor(issues) {
55
+ super(issues.map(issue => issue.message).join('\n'), 400);
56
+ this.issues = issues;
57
+ this.code = issues[0].code;
58
+ this.option = issues[0].option;
51
59
  }
52
- return InvalidArgDefinitionError;
53
- }(TalentedArgsError));
54
- exports.InvalidArgDefinitionError = InvalidArgDefinitionError;
55
- var OptionsValidationError = /** @class */ (function (_super) {
56
- __extends(OptionsValidationError, _super);
57
- function OptionsValidationError(reason) {
58
- var _this = _super.call(this, "Options validation error: ".concat(reason), 500) || this;
59
- _this.reason = reason;
60
- return _this;
61
- }
62
- return OptionsValidationError;
63
- }(TalentedArgsError));
64
- exports.OptionsValidationError = OptionsValidationError;
65
- var DefinitionValidationError = /** @class */ (function (_super) {
66
- __extends(DefinitionValidationError, _super);
67
- function DefinitionValidationError(reason) {
68
- var _this = _super.call(this, "Definition validation error: ".concat(reason), 500) || this;
69
- _this.reason = reason;
70
- return _this;
71
- }
72
- return DefinitionValidationError;
73
- }(TalentedArgsError));
74
- exports.DefinitionValidationError = DefinitionValidationError;
75
- var InvalidConsoleColorError = /** @class */ (function (_super) {
76
- __extends(InvalidConsoleColorError, _super);
77
- function InvalidConsoleColorError(style, supported_values) {
78
- var _this = _super.call(this, "Invalid value for a console color style: \"".concat(style, "\". These are the supported values: ").concat(supported_values.join(', ')), 500) || this;
79
- _this.style = style;
80
- _this.supported_values = supported_values;
81
- return _this;
82
- }
83
- return InvalidConsoleColorError;
84
- }(TalentedArgsError));
85
- exports.InvalidConsoleColorError = InvalidConsoleColorError;
60
+ }
61
+ exports.UsageError = UsageError;
62
+ // *********************************************************************************************************************
63
+ /** Process exit codes used by `parseOrDie()`. */
64
+ exports.EXIT_CODES = {
65
+ help: 0,
66
+ /** Interactive mode copied the command line without running it. */
67
+ copied: 0,
68
+ usage: 1,
69
+ /** Interactive mode was cancelled. Matches the shell exit code for Ctrl-C. */
70
+ cancelled: 130,
71
+ };
86
72
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;IAAuC,qCAAK;IAO1C,2BAAY,OAAe,EAAE,MAAc;QAA3C,YACE,kBAAM,OAAO,CAAC,SASf;QAPC,yDAAyD;QACzD,MAAM,CAAC,gBAAgB,CAAC,KAAI,EAAE;YAC5B,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC7C,KAAK,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC5C,CAAC,CAAC;QAEH,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;;IACvB,CAAC;IACH,wBAAC;AAAD,CAAC,AAlBD,CAAuC,KAAK,GAkB3C;AAlBY,8CAAiB;AAoB9B;IAAyC,uCAAiB;IACxD,6BAAmB,OAAe,EAAS,SAAmB;QAA9D,YACE,kBACE,2BAAoB,OAAO,gCAAqB,SAAS,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,YAAI,CAAC,OAAG,EAAR,CAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAE,E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GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACjC,CAAC;CACF;AAZD,gCAYC;AAED,wHAAwH;AAExH,iDAAiD;AACpC,QAAA,UAAU,GAAG;IACxB,IAAI,EAAE,CAAC;IACP,mEAAmE;IACnE,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;IACR,8EAA8E;IAC9E,SAAS,EAAE,GAAG;CACN,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
- import { IArgDefinition as TalentedArgDefinition } from './definitions';
2
- import { DefinitionValidationError as TalentedArgsDefinitionValidationError, TalentedArgsError, InvalidArgDefinitionError as TalentedArgsInvalidArgDefinitionError, InvalidCommandError as TalentedArgsInvalidCommandError, OptionsValidationError as TalentedArgsOptionsValidationError } from './errors';
3
- import { TalentedArgs, IParsedArgs as TalentedParsedArgs } from './main';
4
- import { ICommandOption as TalentedArgCommandOption, IOptions as TalentedArgOptions, ICommandsLookup as TalentedArgsCommandsLookup } from './options';
5
- export { TalentedArgs, TalentedParsedArgs, TalentedArgDefinition, TalentedArgOptions, TalentedArgCommandOption, TalentedArgsCommandsLookup, TalentedArgsError, TalentedArgsDefinitionValidationError, TalentedArgsInvalidArgDefinitionError, TalentedArgsInvalidCommandError, TalentedArgsOptionsValidationError, };
6
- export default TalentedArgs;
1
+ import { Arg as TalentedArg, IConverter as TalentedArgConverter, IMultipleOptions as TalentedArgMultipleOptions, IOptionName as TalentedArgName, IOptionNames as TalentedArgNames, IBuilder as TalentedArgsBuilder, Command as TalentedArgsCommand, ICommandDescription as TalentedArgsCommandDescription, IGroupShape as TalentedArgsGroupShape, IGuidedShape as TalentedArgsGuidedShape, IMeta as TalentedArgsMeta, IParsed as TalentedArgsParsedShape, IShape as TalentedArgsShape, FlagArg as TalentedFlagArg, ListArg as TalentedListArg, ValueArg as TalentedValueArg } from './descriptors';
2
+ import { EXIT_CODES as TALENTED_ARGS_EXIT_CODES, DefinitionError as TalentedArgsDefinitionError, TalentedArgsError, UsageError as TalentedArgsUsageError, IUsageErrorCode as TalentedArgsUsageErrorCode, IUsageIssue as TalentedArgsUsageIssue } from './errors';
3
+ import { IOptions as TalentedArgOptions } from './options';
4
+ import { TalentedArgs, IHelpOptions as TalentedArgsHelpOptions, IParseResult as TalentedArgsParseResult, IParsedArgs as TalentedParsedArgs, talentedArgs } from './program';
5
+ import { IRememberStore as TalentedArgsRememberStore, IRemembered as TalentedArgsRemembered, IRememberedValue as TalentedArgsRememberedValue, IRememberedValues as TalentedArgsRememberedValues } from './remember';
6
+ import { IConsoleColor as TalentedArgsConsoleColor, IConsoleStyle as TalentedArgsConsoleStyle, IStyleSpec as TalentedArgsStyleSpec } from './styling';
7
+ export { talentedArgs, TalentedArgsError, TalentedArgsDefinitionError, TalentedArgsUsageError };
8
+ export { TALENTED_ARGS_EXIT_CODES };
9
+ export type { TalentedArgs, TalentedParsedArgs, TalentedArgOptions, TalentedArgsBuilder, TalentedArgsHelpOptions, TalentedArgsParseResult, TalentedArg, TalentedValueArg, TalentedListArg, TalentedFlagArg, TalentedArgsCommand, TalentedArgsCommandDescription, TalentedArgConverter, TalentedArgMultipleOptions, TalentedArgName, TalentedArgNames, TalentedArgsShape, TalentedArgsGroupShape, TalentedArgsGuidedShape, TalentedArgsMeta, TalentedArgsParsedShape, TalentedArgsConsoleColor, TalentedArgsConsoleStyle, TalentedArgsStyleSpec, TalentedArgsUsageErrorCode, TalentedArgsUsageIssue, TalentedArgsRemembered, TalentedArgsRememberedValue, TalentedArgsRememberedValues, TalentedArgsRememberStore, };
10
+ export default talentedArgs;
package/dist/index.js CHANGED
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TalentedArgsOptionsValidationError = exports.TalentedArgsInvalidCommandError = exports.TalentedArgsInvalidArgDefinitionError = exports.TalentedArgsDefinitionValidationError = exports.TalentedArgsError = exports.TalentedArgs = void 0;
4
- var errors_1 = require("./errors");
5
- Object.defineProperty(exports, "TalentedArgsDefinitionValidationError", { enumerable: true, get: function () { return errors_1.DefinitionValidationError; } });
3
+ exports.TALENTED_ARGS_EXIT_CODES = exports.TalentedArgsUsageError = exports.TalentedArgsDefinitionError = exports.TalentedArgsError = exports.talentedArgs = void 0;
4
+ const errors_1 = require("./errors");
5
+ Object.defineProperty(exports, "TALENTED_ARGS_EXIT_CODES", { enumerable: true, get: function () { return errors_1.EXIT_CODES; } });
6
+ Object.defineProperty(exports, "TalentedArgsDefinitionError", { enumerable: true, get: function () { return errors_1.DefinitionError; } });
6
7
  Object.defineProperty(exports, "TalentedArgsError", { enumerable: true, get: function () { return errors_1.TalentedArgsError; } });
7
- Object.defineProperty(exports, "TalentedArgsInvalidArgDefinitionError", { enumerable: true, get: function () { return errors_1.InvalidArgDefinitionError; } });
8
- Object.defineProperty(exports, "TalentedArgsInvalidCommandError", { enumerable: true, get: function () { return errors_1.InvalidCommandError; } });
9
- Object.defineProperty(exports, "TalentedArgsOptionsValidationError", { enumerable: true, get: function () { return errors_1.OptionsValidationError; } });
10
- var main_1 = require("./main");
11
- Object.defineProperty(exports, "TalentedArgs", { enumerable: true, get: function () { return main_1.TalentedArgs; } });
12
- exports.default = main_1.TalentedArgs;
8
+ Object.defineProperty(exports, "TalentedArgsUsageError", { enumerable: true, get: function () { return errors_1.UsageError; } });
9
+ const program_1 = require("./program");
10
+ Object.defineProperty(exports, "talentedArgs", { enumerable: true, get: function () { return program_1.talentedArgs; } });
11
+ exports.default = program_1.talentedArgs;
13
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,mCAMkB;AAgBhB,sHArB6B,kCAAqC,OAqB7B;AADrC,kGAnBA,0BAAiB,OAmBA;AAEjB,sHApB6B,kCAAqC,OAoB7B;AACrC,gHApBuB,4BAA+B,OAoBvB;AAC/B,mHApB0B,+BAAkC,OAoB1B;AAlBpC,+BAAyE;AAQvE,6FARO,mBAAY,OAQP;AAad,kBAAe,mBAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAkBA,qCAOkB;AAsBT,yGA5BO,mBAAwB,OA4BP;AADS,4GA1BrB,wBAA2B,OA0BqB;AAA9C,kGAzBrB,0BAAiB,OAyBqB;AAA+B,uGAxBvD,mBAAsB,OAwBuD;AAnB7F,uCAMmB;AAaV,6FAdP,sBAAY,OAcO;AAsCrB,kBAAe,sBAAY,CAAC"}
package/dist/options.d.ts CHANGED
@@ -1,62 +1,90 @@
1
- import { IArgDefinition } from './definitions';
2
- import { IStyleSpec } from './styling';
3
- import { StringKeys } from './tools';
4
- export interface ICommandOption {
1
+ import { IRememberStore } from './remember';
2
+ import { IResolvedStyles, IStyleSpec } from './styling';
3
+ /** Behavior when a program has commands but no command was supplied. */
4
+ export type IMissingCommandPolicy = 'tui' | 'error' | 'none';
5
+ export declare const MISSING_COMMAND_POLICIES: readonly IMissingCommandPolicy[];
6
+ export interface IOptions {
5
7
  /**
6
- * Short command description, displayed in the command list
8
+ * Program name shown in help and interactive mode.
9
+ * Defaults to the name in the application's nearest readable `package.json`.
7
10
  */
8
- summary: string;
9
- /**
10
- * Longer text, with further command details. Displayed instead of description when you bring up command-specific help.
11
- */
12
- details?: string;
13
- }
14
- export declare type ICommandsLookup = {
15
- [key: string]: string | ICommandOption;
16
- };
17
- export interface IOptions<TName, TDestination, TCommands extends ICommandsLookup = never, TDef extends IArgDefinition<TName, TDestination, any, StringKeys<TCommands>> = IArgDefinition<TName, TDestination, any, StringKeys<TCommands>>> {
18
- /**
19
- * Program title. If not provided, it will be loaded from package.json.
20
- */
21
- title?: string;
11
+ name?: string | undefined;
22
12
  /**
23
13
  * Name of the executable that is called when running this program. If not provided, we determine it automatically
24
14
  * (but this might be inaccurate, depending on how your app is structured)
25
15
  */
26
- executable?: string;
16
+ executable?: string | undefined;
27
17
  /**
28
18
  * Program description. If not provided, it will be loaded from package.json.
29
19
  */
30
- description?: string;
20
+ description?: string | undefined;
31
21
  /**
32
22
  * Program version. If not provided, it will be loaded from package.json.
33
23
  */
34
- version?: string;
35
- /**
36
- * List of initial arg definitions. Can also be provided later.
37
- */
38
- defs?: Array<TDef>;
39
- /**
40
- * Lookup of supported commands towards their options. You can also set just string, which will become description.
41
- */
42
- commands?: TCommands;
24
+ version?: string | undefined;
43
25
  /**
44
- * If true, instead of showing the help screen, we will allow the program to run without any command.
26
+ * Path to the file with ASCII art logo of the product, to be displayed to the right of the help screen
45
27
  */
46
- allowNoCommand?: boolean;
28
+ logoPath?: string | undefined;
47
29
  /**
48
- * Path to the file with ASCII art logo of the product, to be displayed to the right of the help screen
49
- * @type {string}
30
+ * Optionally override default styling. Set null if you want to disable all the defaults.
31
+ * Set null for any particular style to disable that style only.
50
32
  */
51
- logo_path?: string;
33
+ styles?: IStyleSpec | null | undefined;
52
34
  /**
53
- * Definition to use for triggering the help screen. It comes with a reasonable default. Set to null to disable.
35
+ * Behavior when the program has commands but the user supplies none.
36
+ *
37
+ * - `'tui'`: open interactive mode when a suitable terminal is available.
38
+ * Otherwise, print help and exit with code 1. This is the default.
39
+ * - `'error'`: print help and exit with code 1.
40
+ * - `'none'`: return common arguments without a command property.
41
+ * Use `ta.meta()` to detect this case and decide what your program should do.
42
+ *
43
+ * `--interactive` explicitly requests the editor regardless of this policy.
54
44
  */
55
- help?: Omit<IArgDefinition<TName, TDestination, any, StringKeys<TCommands>>, 'command' | 'destination'>;
45
+ missingCommandPolicy?: IMissingCommandPolicy | undefined;
56
46
  /**
57
- * Optionally override default styling. Set null if you want to disable all the defaults.
58
- * Set null for any particular style to disable that style only.
47
+ * Restore the saved command and option values when interactive mode opens.
48
+ * Save them when the user runs or copies a command. Sensitive values are never saved.
49
+ *
50
+ * - `true`: use the system's default state file, typically
51
+ * `~/.local/state/<name>/interactive.json` on Linux.
52
+ * - A string: use that file path, resolved from the current working directory.
53
+ * - An object: use its `load()` and optional `save()` methods.
54
+ * Omit `save()` to prefill values without saving changes.
55
+ * - `false` or omitted: disable remembering.
59
56
  */
60
- styles?: IStyleSpec;
57
+ remember?: boolean | string | IRememberStore | undefined;
58
+ }
59
+ export interface INormalizedOptions {
60
+ readonly name: string | undefined;
61
+ readonly executable: string | undefined;
62
+ readonly description: string | undefined;
63
+ readonly version: string | undefined;
64
+ readonly logoPath: string | undefined;
65
+ readonly styles: IResolvedStyles;
66
+ readonly missingCommandPolicy: IMissingCommandPolicy;
67
+ /** Default state file, custom path, or custom store. `null` disables remembering. */
68
+ readonly remember: true | string | IRememberStore | null;
69
+ }
70
+ export declare function normalizeAndValidateOptions(rawOptions: unknown): INormalizedOptions;
71
+ export interface IAppInfo {
72
+ readonly title: string;
73
+ readonly description: string;
74
+ readonly version: string;
75
+ /** Logo lines with shared indentation, trailing spaces, and surrounding blank lines removed. */
76
+ readonly logo: readonly string[];
61
77
  }
62
- export declare function normalizeAndValidateOptions<TName, TDestination, TCommands extends ICommandsLookup>(rawOptions: IOptions<TName, TDestination, TCommands>): IOptions<TName, TDestination, TCommands, IArgDefinition<TName, TDestination, any, StringKeys<TCommands>>>;
78
+ /** Package name of the application script, or `undefined` if none is found. */
79
+ export declare function getPackageName(mainFilename: string | undefined): string | undefined;
80
+ /**
81
+ * Prepare logo text for display. Remove a leading byte order mark and terminal escape codes,
82
+ * expand tabs to spaces, and remove other nonprinting control characters.
83
+ * Trim surrounding blank lines, trailing spaces, and shared indentation.
84
+ */
85
+ export declare function cleanLogo(content: string): string[];
86
+ /**
87
+ * Load application display metadata and the logo.
88
+ * Called lazily when help or interactive mode needs them.
89
+ */
90
+ export declare function getAppInfo(options: INormalizedOptions, mainFilename: string | undefined): IAppInfo;