@jinshuju/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 +202 -0
- package/README.md +311 -0
- package/dist/auth.d.ts +39 -0
- package/dist/auth.js +184 -0
- package/dist/cli-bin.d.ts +2 -0
- package/dist/cli-bin.js +8 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.js +699 -0
- package/dist/commands.d.ts +84 -0
- package/dist/commands.js +1672 -0
- package/dist/config.d.ts +64 -0
- package/dist/config.js +99 -0
- package/dist/help.d.ts +15 -0
- package/dist/help.js +98 -0
- package/dist/http.d.ts +29 -0
- package/dist/http.js +127 -0
- package/dist/options.d.ts +102 -0
- package/dist/options.js +232 -0
- package/dist/payload.d.ts +12 -0
- package/dist/payload.js +59 -0
- package/dist/progress.d.ts +16 -0
- package/dist/progress.js +17 -0
- package/package.json +43 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { JSON_OPTION, type OptionSpec } from './options.js';
|
|
2
|
+
import type { HttpClient } from './http.js';
|
|
3
|
+
/**
|
|
4
|
+
* Every command the CLI has, as data.
|
|
5
|
+
*
|
|
6
|
+
* The shape is `jinshuju <resource> <verb> [args] [flags]`: resources kept at
|
|
7
|
+
* one level, the parent given by a flag —
|
|
8
|
+
* `entry list --form <token>`, not `form entry list <token>`. Help, argument
|
|
9
|
+
* checking and dispatch all read this table, so a command cannot be reachable
|
|
10
|
+
* without its help, nor accept a flag it never described.
|
|
11
|
+
*/
|
|
12
|
+
export interface ArgSpec {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly required: boolean;
|
|
15
|
+
/** Takes the rest of the words; only the last argument may. */
|
|
16
|
+
readonly variadic?: boolean;
|
|
17
|
+
readonly description: string;
|
|
18
|
+
}
|
|
19
|
+
/** A repeated parameter arrives as a list; everything else is one value. */
|
|
20
|
+
export type QueryValues = Record<string, string | readonly string[] | undefined>;
|
|
21
|
+
export interface HttpRequest {
|
|
22
|
+
readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
23
|
+
readonly path: string;
|
|
24
|
+
readonly query?: QueryValues;
|
|
25
|
+
readonly body?: unknown;
|
|
26
|
+
/** A multipart body, for the endpoints that take a file. */
|
|
27
|
+
readonly form?: FormData;
|
|
28
|
+
}
|
|
29
|
+
/** How a listing returns its next page, which is what `--all` follows. */
|
|
30
|
+
export interface Pagination {
|
|
31
|
+
readonly items: string;
|
|
32
|
+
readonly cursor: string;
|
|
33
|
+
}
|
|
34
|
+
export interface CommandInput {
|
|
35
|
+
readonly args: Record<string, string>;
|
|
36
|
+
/** The values of a variadic argument, in the order given. */
|
|
37
|
+
readonly rest: readonly string[];
|
|
38
|
+
readonly options: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
export interface Command {
|
|
41
|
+
/** The words that select it: `['entry', 'list']`. */
|
|
42
|
+
readonly path: readonly string[];
|
|
43
|
+
/** One line, shown under its resource in the root help. */
|
|
44
|
+
readonly summary: string;
|
|
45
|
+
readonly description?: string;
|
|
46
|
+
readonly args?: readonly ArgSpec[];
|
|
47
|
+
readonly options?: readonly OptionSpec[];
|
|
48
|
+
/**
|
|
49
|
+
* What `--json` expects, shown in help. A flag named `<json>` says nothing
|
|
50
|
+
* about what goes in the file, and a caller with nothing to copy from cannot
|
|
51
|
+
* guess it — so the commands that take a payload show one.
|
|
52
|
+
*/
|
|
53
|
+
readonly payload?: readonly string[];
|
|
54
|
+
readonly examples?: readonly string[];
|
|
55
|
+
readonly request?: (input: CommandInput) => HttpRequest;
|
|
56
|
+
/**
|
|
57
|
+
* For the commands a single request cannot express: uploading a file and then
|
|
58
|
+
* acting on it. It gets the client and returns whatever should be printed.
|
|
59
|
+
*/
|
|
60
|
+
readonly run?: (input: CommandInput, client: HttpClient) => Promise<unknown>;
|
|
61
|
+
readonly paginate?: Pagination;
|
|
62
|
+
/**
|
|
63
|
+
* Narrows the response to what the command is about. `field list` asks for a
|
|
64
|
+
* form because that is where fields live, but a caller asked for the fields.
|
|
65
|
+
*/
|
|
66
|
+
readonly select?: (body: unknown) => unknown;
|
|
67
|
+
/**
|
|
68
|
+
* Reshapes the response for reading, and only for reading: `--output json`
|
|
69
|
+
* answers what the API answered. A command needs this when its payload is
|
|
70
|
+
* built for indexing rather than for looking at, and no generic renderer
|
|
71
|
+
* could know how to put it back together.
|
|
72
|
+
*/
|
|
73
|
+
readonly render?: (body: unknown) => unknown;
|
|
74
|
+
}
|
|
75
|
+
export interface Resource {
|
|
76
|
+
readonly name: string;
|
|
77
|
+
readonly summary: string;
|
|
78
|
+
}
|
|
79
|
+
/** Resource order in the root help, and the one-liner each gets. */
|
|
80
|
+
export declare const RESOURCES: readonly Resource[];
|
|
81
|
+
export declare const COMMANDS: readonly Command[];
|
|
82
|
+
/** The command whose path the words begin with, longest match first. */
|
|
83
|
+
export declare function findCommand(words: readonly string[], commands?: readonly Command[]): Command | undefined;
|
|
84
|
+
export { JSON_OPTION };
|