@whooshbang/sdk 1.0.0-rc.22 → 1.0.0-rc.24
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/arguments.js +45 -4
- package/dist/cli/arguments.js.map +1 -1
- package/dist/cli/commands.d.ts +58 -0
- package/dist/cli/commands.js +640 -34
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/config.d.ts +28 -0
- package/dist/cli/config.js +38 -0
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.js +60 -5
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/selectors.d.ts +25 -3
- package/dist/cli/selectors.js +76 -22
- package/dist/cli/selectors.js.map +1 -1
- package/dist/cli/session.d.ts +19 -0
- package/dist/cli/session.js +22 -0
- package/dist/cli/session.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/arguments.js
CHANGED
|
@@ -4,7 +4,41 @@ const SWITCHES = new Set([
|
|
|
4
4
|
"version",
|
|
5
5
|
"credential-stdin",
|
|
6
6
|
"yes",
|
|
7
|
+
"free-text",
|
|
8
|
+
"no-connection",
|
|
9
|
+
"no-route",
|
|
10
|
+
"invite",
|
|
11
|
+
"no-invite",
|
|
12
|
+
"send",
|
|
13
|
+
"no-send",
|
|
14
|
+
"ask",
|
|
7
15
|
]);
|
|
16
|
+
/**
|
|
17
|
+
* Short and shortened spellings, resolved here so no command ever sees one.
|
|
18
|
+
*
|
|
19
|
+
* A short form that some commands understand and others do not is worse than
|
|
20
|
+
* none: the failure is silent, because an unrecognised flag is read as a
|
|
21
|
+
* switch and the value it carried disappears. Normalising at the door means
|
|
22
|
+
* `-p` is the same argument as `--project` everywhere, including in the error
|
|
23
|
+
* messages, which always name the long form so nothing has to be memorised to
|
|
24
|
+
* recover from a mistake.
|
|
25
|
+
*/
|
|
26
|
+
const ALIASES = new Map([
|
|
27
|
+
["c", "connection"],
|
|
28
|
+
["e", "environment"],
|
|
29
|
+
["env", "environment"],
|
|
30
|
+
["k", "key"],
|
|
31
|
+
["m", "mode"],
|
|
32
|
+
["n", "name"],
|
|
33
|
+
["p", "project"],
|
|
34
|
+
["s", "subscriber"],
|
|
35
|
+
["t", "text"],
|
|
36
|
+
["w", "wait"],
|
|
37
|
+
["y", "yes"],
|
|
38
|
+
]);
|
|
39
|
+
function canonical(name) {
|
|
40
|
+
return ALIASES.get(name) ?? name;
|
|
41
|
+
}
|
|
8
42
|
export function parseArguments(argv) {
|
|
9
43
|
const words = [];
|
|
10
44
|
const options = new Map();
|
|
@@ -12,13 +46,20 @@ export function parseArguments(argv) {
|
|
|
12
46
|
const repeated = new Map();
|
|
13
47
|
for (let index = 0; index < argv.length; index += 1) {
|
|
14
48
|
const token = argv[index];
|
|
15
|
-
|
|
49
|
+
// A single dash introduces a short form; `-` alone and a negative number
|
|
50
|
+
// are ordinary words, because both are things somebody might legitimately
|
|
51
|
+
// pass as a value.
|
|
52
|
+
const short = token.length > 1 &&
|
|
53
|
+
token.startsWith("-") &&
|
|
54
|
+
!token.startsWith("--") &&
|
|
55
|
+
!/^-\d/u.test(token);
|
|
56
|
+
if (!token.startsWith("--") && !short) {
|
|
16
57
|
words.push(token);
|
|
17
58
|
continue;
|
|
18
59
|
}
|
|
19
|
-
const body = token.slice(2);
|
|
60
|
+
const body = short ? token.slice(1) : token.slice(2);
|
|
20
61
|
const equals = body.indexOf("=");
|
|
21
|
-
const name = equals === -1 ? body : body.slice(0, equals);
|
|
62
|
+
const name = canonical(equals === -1 ? body : body.slice(0, equals));
|
|
22
63
|
if (equals !== -1) {
|
|
23
64
|
const value = body.slice(equals + 1);
|
|
24
65
|
options.set(name, value);
|
|
@@ -30,7 +71,7 @@ export function parseArguments(argv) {
|
|
|
30
71
|
continue;
|
|
31
72
|
}
|
|
32
73
|
const next = argv[index + 1];
|
|
33
|
-
if (next === undefined || next.startsWith("
|
|
74
|
+
if (next === undefined || next.startsWith("-")) {
|
|
34
75
|
// A bare unknown flag is a switch rather than an error: the command
|
|
35
76
|
// decides what it does and does not understand, and it can say so in its
|
|
36
77
|
// own words.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arguments.js","sourceRoot":"","sources":["../../src/cli/arguments.ts"],"names":[],"mappings":"AAkBA,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IACvB,MAAM;IACN,MAAM;IACN,SAAS;IACT,kBAAkB;IAClB,KAAK;CACN,CAAC,CAAC;AAEH,MAAM,UAAU,cAAc,CAAC,IAAuB;IACpD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAoB,CAAC;IAE7C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAW,CAAC;QACpC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"arguments.js","sourceRoot":"","sources":["../../src/cli/arguments.ts"],"names":[],"mappings":"AAkBA,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IACvB,MAAM;IACN,MAAM;IACN,SAAS;IACT,kBAAkB;IAClB,KAAK;IACL,WAAW;IACX,eAAe;IACf,UAAU;IACV,QAAQ;IACR,WAAW;IACX,MAAM;IACN,SAAS;IACT,KAAK;CACN,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,MAAM,OAAO,GAAgC,IAAI,GAAG,CAAC;IACnD,CAAC,GAAG,EAAE,YAAY,CAAC;IACnB,CAAC,GAAG,EAAE,aAAa,CAAC;IACpB,CAAC,KAAK,EAAE,aAAa,CAAC;IACtB,CAAC,GAAG,EAAE,KAAK,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,EAAE,IAAI,CAAC,CAAC,CAAC;QAC1D,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAChD,CAAC;AAED,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,UAAU,QAAQ,CACtB,MAAuB,EACvB,IAAY,EACZ,IAAY;IAEZ,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,UAAU,CAAC,KAAK,IAAI,iBAAiB,IAAI,GAAG,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/cli/commands.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ConfirmInteractionRequest, InputInteractionRequest, InteractionSummary, SelectInteractionRequest } from "@whooshbang/contracts";
|
|
2
|
+
import type { WhooshBangClient } from "../client.js";
|
|
1
3
|
import { type ParsedArguments } from "./arguments.js";
|
|
2
4
|
import { type Writer } from "./output.js";
|
|
3
5
|
import { resolveOrigin } from "./session.js";
|
|
@@ -8,7 +10,63 @@ export interface CommandContext {
|
|
|
8
10
|
readonly openUrl: (url: string) => Promise<void>;
|
|
9
11
|
readonly readStdin: () => Promise<string>;
|
|
10
12
|
readonly credentialsFile?: string;
|
|
13
|
+
readonly contextFile?: string;
|
|
14
|
+
/** Asks a question when there is a person to ask. Absent means non-interactive. */
|
|
15
|
+
readonly prompt?: (question: string, fallback?: string) => Promise<string>;
|
|
11
16
|
}
|
|
17
|
+
declare const CONNECTION_MODES: readonly ["whooshbang_shared", "customer_managed", "customer_byok"];
|
|
18
|
+
/**
|
|
19
|
+
* Builds the question from what was asked for.
|
|
20
|
+
*
|
|
21
|
+
* Choices mean a single-select, `--free-text` means a typed reply, and a
|
|
22
|
+
* question with neither is a yes/no confirm — which is what most first
|
|
23
|
+
* questions are, and what someone following a quickstart gets for free.
|
|
24
|
+
*/
|
|
25
|
+
export declare function askedInteraction(parsed: ParsedArguments): ConfirmInteractionRequest | SelectInteractionRequest | InputInteractionRequest;
|
|
26
|
+
/**
|
|
27
|
+
* Waits for the question to reach a state that can no longer change.
|
|
28
|
+
*
|
|
29
|
+
* One request cannot wait longer than the service's own poll ceiling, so a
|
|
30
|
+
* longer wait is consecutive polls against a deadline. Each one returns the
|
|
31
|
+
* moment the answer lands, so this costs the wait it was given and no more.
|
|
32
|
+
*/
|
|
33
|
+
export interface EnvironmentScope {
|
|
34
|
+
readonly environmentId: string;
|
|
35
|
+
readonly projectId: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function untilAnswered(api: WhooshBangClient, scope: EnvironmentScope | null, interactionId: string, waitFor: number): Promise<InteractionSummary>;
|
|
38
|
+
export declare function describeInteraction(summary: InteractionSummary, where: string): string[];
|
|
39
|
+
/**
|
|
40
|
+
* Asks for something that was not given, when there is somebody to ask.
|
|
41
|
+
*
|
|
42
|
+
* Every question is also an argument. Supply them all and nothing is asked, so
|
|
43
|
+
* the same command works unchanged in a script — which is the rule that keeps
|
|
44
|
+
* a guided path from quietly becoming a second, divergent product.
|
|
45
|
+
*
|
|
46
|
+
* With no terminal attached there is nobody to answer, so this refuses in the
|
|
47
|
+
* same words the argument would have: a cron job should be told which flag it
|
|
48
|
+
* forgot, not left waiting on a prompt nothing will ever read.
|
|
49
|
+
*/
|
|
50
|
+
export declare function ask(context: CommandContext, question: string, option: string, fallback?: string): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* A yes-or-no step that can be answered in advance.
|
|
53
|
+
*
|
|
54
|
+
* `--invite` and `--no-invite` decide it without asking, which is what lets
|
|
55
|
+
* `wb init` run in a script. With no terminal and no flag the answer is no:
|
|
56
|
+
* an unattended run should do less rather than guess.
|
|
57
|
+
*/
|
|
58
|
+
export declare function confirmed(context: CommandContext, option: string, question: string): Promise<boolean>;
|
|
59
|
+
/** What to call a connection nobody bothered to name. */
|
|
60
|
+
export declare function defaultConnectionName(mode: (typeof CONNECTION_MODES)[number]): string;
|
|
61
|
+
/**
|
|
62
|
+
* The shared identity to connect through, chosen rather than demanded.
|
|
63
|
+
*
|
|
64
|
+
* A provider offering exactly one is not a choice, and making somebody run a
|
|
65
|
+
* lookup command to copy an opaque id out of it was the single largest piece of
|
|
66
|
+
* the getting-started path. When there is more than one the choice is real, so
|
|
67
|
+
* it is named along with what the alternatives are.
|
|
68
|
+
*/
|
|
69
|
+
export declare function sharedIdentityFor(api: WhooshBangClient, projectId: string, environmentId: string, parsed: ParsedArguments): Promise<string>;
|
|
12
70
|
/**
|
|
13
71
|
* Words left over once the command itself is accounted for.
|
|
14
72
|
*
|