@cloud-copilot/cli 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/README.md +258 -0
- package/dist/cjs/cli.d.ts +140 -0
- package/dist/cjs/cli.d.ts.map +1 -0
- package/dist/cjs/cli.js +546 -0
- package/dist/cjs/cli.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/stdin.d.ts +7 -0
- package/dist/cjs/stdin.d.ts.map +1 -0
- package/dist/cjs/stdin.js +36 -0
- package/dist/cjs/stdin.js.map +1 -0
- package/dist/cjs/utils.d.ts +8 -0
- package/dist/cjs/utils.d.ts.map +1 -0
- package/dist/cjs/utils.js +21 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/cli.d.ts +140 -0
- package/dist/esm/cli.d.ts.map +1 -0
- package/dist/esm/cli.js +541 -0
- package/dist/esm/cli.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/stdin.d.ts +7 -0
- package/dist/esm/stdin.d.ts.map +1 -0
- package/dist/esm/stdin.js +33 -0
- package/dist/esm/stdin.js.map +1 -0
- package/dist/esm/utils.d.ts +8 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +18 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optionally print a message and exit the process with the given exit code.
|
|
3
|
+
*
|
|
4
|
+
* @param exitCode the exit code to use
|
|
5
|
+
* @param message the message to print
|
|
6
|
+
*/
|
|
7
|
+
export declare function exit(exitCode: number, message: string | undefined): void;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,QASjE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exit = exit;
|
|
4
|
+
/**
|
|
5
|
+
* Optionally print a message and exit the process with the given exit code.
|
|
6
|
+
*
|
|
7
|
+
* @param exitCode the exit code to use
|
|
8
|
+
* @param message the message to print
|
|
9
|
+
*/
|
|
10
|
+
function exit(exitCode, message) {
|
|
11
|
+
if (message) {
|
|
12
|
+
if (exitCode === 0) {
|
|
13
|
+
console.log(message);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
console.error(message);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
process.exit(exitCode);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;AAMA,oBASC;AAfD;;;;;GAKG;AACH,SAAgB,IAAI,CAAC,QAAgB,EAAE,OAA2B;IAChE,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;YACnB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QACtB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACxB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AACxB,CAAC"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A boolean argument that has no values.
|
|
3
|
+
*/
|
|
4
|
+
export type BooleanArgument = {
|
|
5
|
+
/**
|
|
6
|
+
* The single character flag for the argument.
|
|
7
|
+
*/
|
|
8
|
+
character: string;
|
|
9
|
+
/**
|
|
10
|
+
* Must be 'none' for a boolean argument.
|
|
11
|
+
*/
|
|
12
|
+
values: 'none';
|
|
13
|
+
/**
|
|
14
|
+
* The description of the argument.
|
|
15
|
+
*/
|
|
16
|
+
description: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A standard argument that has one or more values.
|
|
20
|
+
*/
|
|
21
|
+
export type StandardArgument = {
|
|
22
|
+
/**
|
|
23
|
+
* Whether the argument accepts single or multiple values.
|
|
24
|
+
*/
|
|
25
|
+
values: 'single' | 'multiple';
|
|
26
|
+
/**
|
|
27
|
+
* The type of the values accepted.
|
|
28
|
+
*/
|
|
29
|
+
type: 'string' | 'number';
|
|
30
|
+
/**
|
|
31
|
+
* The description of the argument.
|
|
32
|
+
*/
|
|
33
|
+
description: string;
|
|
34
|
+
};
|
|
35
|
+
export type EnumArgument = {
|
|
36
|
+
/**
|
|
37
|
+
* Whether the argument accepts single or multiple values.
|
|
38
|
+
*/
|
|
39
|
+
values: 'single' | 'multiple';
|
|
40
|
+
/**
|
|
41
|
+
* Must be 'enum' for an enum argument.
|
|
42
|
+
*/
|
|
43
|
+
type: 'enum';
|
|
44
|
+
/**
|
|
45
|
+
* The valid values for the argument.
|
|
46
|
+
*/
|
|
47
|
+
validValues: string[];
|
|
48
|
+
/**
|
|
49
|
+
* The description of the argument.
|
|
50
|
+
*/
|
|
51
|
+
description: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* A CLI argument that can be accepted for a command.
|
|
55
|
+
*/
|
|
56
|
+
export type CliArgument = BooleanArgument | StandardArgument | EnumArgument;
|
|
57
|
+
export type Command = {
|
|
58
|
+
description: string;
|
|
59
|
+
options: Record<string, CliArgument>;
|
|
60
|
+
};
|
|
61
|
+
export type OptionConfig = {
|
|
62
|
+
type: 'string' | 'number' | 'boolean';
|
|
63
|
+
values: 'single' | 'multiple';
|
|
64
|
+
description: string;
|
|
65
|
+
character?: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* A map of CLI argument keys to their configuration.
|
|
69
|
+
*/
|
|
70
|
+
export type Config<T extends Record<string, CliArgument>> = T;
|
|
71
|
+
/**
|
|
72
|
+
* Create a type safe configuration for CLI arguments.
|
|
73
|
+
*
|
|
74
|
+
* @param config the configuration for the CLI arguments.
|
|
75
|
+
* @returns the configuration object.
|
|
76
|
+
*/
|
|
77
|
+
export declare function createConfig<T extends Record<string, CliArgument>>(config: T): T;
|
|
78
|
+
type ParsedArgs<T extends Record<string, CliArgument>> = {
|
|
79
|
+
[K in keyof T as K]: T[K] extends {
|
|
80
|
+
type: 'string';
|
|
81
|
+
} ? T[K]['values'] extends 'single' ? string | undefined : string[] : T[K] extends {
|
|
82
|
+
type: 'number';
|
|
83
|
+
} ? T[K]['values'] extends 'single' ? number | undefined : number[] : T[K] extends {
|
|
84
|
+
type: 'boolean';
|
|
85
|
+
} ? boolean : never;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Additional arguments that can be used to configure the CLI parser.
|
|
89
|
+
*/
|
|
90
|
+
export interface AdditionalCliArguments {
|
|
91
|
+
/**
|
|
92
|
+
* The version of the CLI command. If provided, the CLI provides a --version flag that prints the version and exits.
|
|
93
|
+
*/
|
|
94
|
+
version?: string;
|
|
95
|
+
/**
|
|
96
|
+
* The argument string from the CLI. If not provided, the process.argv.slice(2) is used.
|
|
97
|
+
*/
|
|
98
|
+
args?: string[];
|
|
99
|
+
/**
|
|
100
|
+
* The environment variables to use for parsing. If not provided, process.env is used.
|
|
101
|
+
*/
|
|
102
|
+
env?: Record<string, string>;
|
|
103
|
+
/**
|
|
104
|
+
* The prefix to use for environment variables. If provided, the CLI will look for environment variables with the prefix followed by an underscore.
|
|
105
|
+
*/
|
|
106
|
+
envPrefix?: string;
|
|
107
|
+
/**
|
|
108
|
+
* The name of the operands to display in the help message. Defaults to "operands".
|
|
109
|
+
*/
|
|
110
|
+
operandsName?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Whether a subcommand is required. If true, the CLI will exit with an error if no subcommand is provided.
|
|
113
|
+
*/
|
|
114
|
+
requireSubcommand?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* If there are zero arguments, show the help message. Defaults to false.
|
|
117
|
+
*/
|
|
118
|
+
showHelpIfNoArgs?: boolean;
|
|
119
|
+
}
|
|
120
|
+
export type SelectedCommandWithArgs<C extends Record<string, Command>, O extends Record<string, CliArgument>> = {
|
|
121
|
+
[K in keyof C]: {
|
|
122
|
+
command: K | undefined;
|
|
123
|
+
args: ParsedArgs<C[K]['options']> & ParsedArgs<O>;
|
|
124
|
+
operands: string[];
|
|
125
|
+
anyValues: boolean;
|
|
126
|
+
};
|
|
127
|
+
}[keyof C];
|
|
128
|
+
/**
|
|
129
|
+
* Parse CLI Arguments and return the parsed typesafe results.
|
|
130
|
+
*
|
|
131
|
+
* @param command the name of the command arguments are being parsed for.
|
|
132
|
+
* @param subcommands the list of subcommands that can be used, if any.
|
|
133
|
+
* @param cliOptions the configuration options for the CLI command.
|
|
134
|
+
* @param additionalArgs additional arguments to be used for parsing and displaying help.
|
|
135
|
+
* @returns the parsed arguments, operands, and subcommand if applicable.
|
|
136
|
+
*/
|
|
137
|
+
export declare function parseCliArguments<O extends Record<string, CliArgument>, C extends Record<string, Command>>(command: string, subcommands: C, cliOptions: Config<O>, additionalArgs?: AdditionalCliArguments): SelectedCommandWithArgs<C, O>;
|
|
138
|
+
export declare function printHelpContents<O extends Record<string, CliArgument>, C extends Record<string, Command>>(command: string, subcommands: C, cliOptions: O, additionalArgs?: AdditionalCliArguments, selectedSubcommand?: string | undefined): void;
|
|
139
|
+
export {};
|
|
140
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|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