@adkit.so/cli 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.
- package/dist/cli-utils.d.ts +11 -0
- package/dist/cli-utils.js +58 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +841 -0
- package/dist/client.d.ts +13 -0
- package/dist/client.js +84 -0
- package/dist/commands/auth.d.ts +7 -0
- package/dist/commands/auth.js +184 -0
- package/dist/commands/drafts.d.ts +6 -0
- package/dist/commands/drafts.js +36 -0
- package/dist/commands/meta.d.ts +28 -0
- package/dist/commands/meta.js +534 -0
- package/dist/commands/projects.d.ts +25 -0
- package/dist/commands/projects.js +30 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +36 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.js +70 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +9 -0
- package/dist/output.d.ts +6 -0
- package/dist/output.js +48 -0
- package/package.json +20 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Flags = Record<string, string | string[] | true>;
|
|
2
|
+
interface ParseOptions {
|
|
3
|
+
multi?: string[];
|
|
4
|
+
}
|
|
5
|
+
export declare function parseArgs(argv: string[], options?: ParseOptions): {
|
|
6
|
+
args: string[];
|
|
7
|
+
flags: Record<string, string | true | string[]>;
|
|
8
|
+
};
|
|
9
|
+
export declare function validateFlags(flags: Flags, allowed: string[], command: string): void;
|
|
10
|
+
export declare function unwrapList(data: unknown): Record<string, unknown>[];
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CliError } from './errors.js';
|
|
2
|
+
export function parseArgs(argv, options) {
|
|
3
|
+
const args = [];
|
|
4
|
+
const flags = {};
|
|
5
|
+
const multiSet = new Set(options?.multi);
|
|
6
|
+
for (let i = 0; i < argv.length; i++) {
|
|
7
|
+
const arg = argv[i];
|
|
8
|
+
if (!arg.startsWith('--')) {
|
|
9
|
+
args.push(arg);
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const eqIdx = arg.indexOf('=');
|
|
13
|
+
let key;
|
|
14
|
+
let value;
|
|
15
|
+
if (eqIdx !== -1) {
|
|
16
|
+
key = arg.slice(2, eqIdx);
|
|
17
|
+
value = arg.slice(eqIdx + 1);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
key = arg.slice(2);
|
|
21
|
+
const next = argv[i + 1];
|
|
22
|
+
if (next && !next.startsWith('--')) {
|
|
23
|
+
value = next;
|
|
24
|
+
i++;
|
|
25
|
+
}
|
|
26
|
+
else
|
|
27
|
+
value = true;
|
|
28
|
+
}
|
|
29
|
+
if (multiSet.has(key) && typeof value === 'string') {
|
|
30
|
+
const existing = flags[key];
|
|
31
|
+
if (Array.isArray(existing))
|
|
32
|
+
existing.push(value);
|
|
33
|
+
else
|
|
34
|
+
flags[key] = [value];
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
flags[key] = value;
|
|
38
|
+
}
|
|
39
|
+
return { args, flags };
|
|
40
|
+
}
|
|
41
|
+
const GLOBAL_FLAGS = ['account', 'json', 'fields', 'publish', 'data', 'platform-overrides', 'force', 'project'];
|
|
42
|
+
export function validateFlags(flags, allowed, command) {
|
|
43
|
+
const allAllowed = new Set([...GLOBAL_FLAGS, ...allowed]);
|
|
44
|
+
const unknown = Object.keys(flags).filter((k) => !allAllowed.has(k));
|
|
45
|
+
if (unknown.length)
|
|
46
|
+
throw new CliError('UNKNOWN_FLAG', `Unknown flag${unknown.length > 1 ? 's' : ''}: ${unknown.map((f) => `--${f}`).join(', ')}`, `Run: adkit ${command} --help`);
|
|
47
|
+
}
|
|
48
|
+
export function unwrapList(data) {
|
|
49
|
+
if (Array.isArray(data))
|
|
50
|
+
return data;
|
|
51
|
+
if (data && typeof data === 'object') {
|
|
52
|
+
const values = Object.values(data);
|
|
53
|
+
const arr = values.find((v) => Array.isArray(v));
|
|
54
|
+
if (arr)
|
|
55
|
+
return arr;
|
|
56
|
+
}
|
|
57
|
+
return [];
|
|
58
|
+
}
|
package/dist/cli.d.ts
ADDED