@seamapi/cli 0.21.0 → 0.22.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/README.md +39 -4
- package/bin/cli.js +26 -6
- package/bin/cli.js.map +1 -1
- package/lib/args/parse.d.ts +9 -0
- package/lib/args/parse.js +42 -2
- package/lib/args/parse.js.map +1 -1
- package/lib/args/validate.d.ts +10 -0
- package/lib/args/validate.js +23 -0
- package/lib/args/validate.js.map +1 -1
- package/lib/auth/operations.d.ts +7 -9
- package/lib/auth/operations.js +13 -23
- package/lib/auth/operations.js.map +1 -1
- package/lib/commands/local/login.js +4 -12
- package/lib/commands/local/login.js.map +1 -1
- package/lib/commands/local/select-endpoint.js +10 -7
- package/lib/commands/local/select-endpoint.js.map +1 -1
- package/lib/commands/local/select-workspace.js +12 -4
- package/lib/commands/local/select-workspace.js.map +1 -1
- package/lib/commands/registry.d.ts +11 -0
- package/lib/commands/registry.js +11 -0
- package/lib/commands/registry.js.map +1 -1
- package/lib/commands/spec.d.ts +12 -0
- package/lib/commands/spec.js +16 -0
- package/lib/commands/spec.js.map +1 -1
- package/lib/context.d.ts +5 -4
- package/lib/context.js +23 -8
- package/lib/context.js.map +1 -1
- package/lib/overrides.d.ts +20 -0
- package/lib/overrides.js +23 -0
- package/lib/overrides.js.map +1 -0
- package/lib/render/help.js +20 -1
- package/lib/render/help.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/bin/cli.ts +31 -6
- package/src/lib/args/parse.ts +47 -2
- package/src/lib/args/validate.ts +37 -0
- package/src/lib/auth/operations.ts +13 -29
- package/src/lib/commands/local/login.ts +4 -15
- package/src/lib/commands/local/select-endpoint.ts +11 -7
- package/src/lib/commands/local/select-workspace.ts +13 -4
- package/src/lib/commands/registry.ts +20 -0
- package/src/lib/commands/spec.ts +31 -0
- package/src/lib/context.ts +30 -12
- package/src/lib/overrides.ts +32 -0
- package/src/lib/render/help.ts +21 -1
- package/src/lib/version.ts +1 -1
package/README.md
CHANGED
|
@@ -181,6 +181,40 @@ Missing required parameter for /locks/unlock_door: --device-id
|
|
|
181
181
|
An error exits non-zero. A request that fails reports its `error` on stdout,
|
|
182
182
|
so it can be inspected from a pipe; anything else is written to stderr only.
|
|
183
183
|
|
|
184
|
+
### Selecting an endpoint and a workspace
|
|
185
|
+
|
|
186
|
+
Two settings say where commands go, and one command each stores them:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# Every later command runs against this endpoint
|
|
190
|
+
seam select endpoint https://connect.getseam.com
|
|
191
|
+
|
|
192
|
+
# ...and this workspace
|
|
193
|
+
seam select workspace $MY_WORKSPACE
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Run either without a value to pick one interactively.
|
|
197
|
+
|
|
198
|
+
To send a single command somewhere else, pass `--endpoint` or
|
|
199
|
+
`--workspace-id` to that command. They override what is selected for that one
|
|
200
|
+
invocation and store nothing:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
# List devices in another workspace, without switching to it
|
|
204
|
+
seam devices list --workspace-id $OTHER_WORKSPACE
|
|
205
|
+
|
|
206
|
+
# Run one command against a local Seam Connect instance
|
|
207
|
+
seam devices list --endpoint http://localhost:3020
|
|
208
|
+
|
|
209
|
+
# Log in to another endpoint: the token is stored for that endpoint,
|
|
210
|
+
# and the selected one is left alone
|
|
211
|
+
seam login --endpoint http://localhost:3020 --token $LOCAL_KEY
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Because the two flags never store anything, they are refused on the commands
|
|
215
|
+
that do: `seam select endpoint --endpoint <url>` is an error, and the value
|
|
216
|
+
belongs after the command instead.
|
|
217
|
+
|
|
184
218
|
### Environment variables
|
|
185
219
|
|
|
186
220
|
Everything `seam login`, `seam select workspace`, and `seam select endpoint`
|
|
@@ -191,8 +225,9 @@ store may be given in the environment instead:
|
|
|
191
225
|
- `SEAM_CLI_ENDPOINT`: the Seam API endpoint requests are made to.
|
|
192
226
|
|
|
193
227
|
Any of them, all of them, or none of them may be set. Each one wins over the
|
|
194
|
-
corresponding stored value
|
|
195
|
-
|
|
228
|
+
corresponding stored value and is in turn overridden by `--endpoint` or
|
|
229
|
+
`--workspace-id`, which makes them useful for CI or for working against
|
|
230
|
+
another workspace for a whole shell.
|
|
196
231
|
|
|
197
232
|
```bash
|
|
198
233
|
# One command against another workspace
|
|
@@ -207,8 +242,8 @@ SEAM_CLI_ENDPOINT=http://localhost:3020 seam devices list
|
|
|
207
242
|
```
|
|
208
243
|
|
|
209
244
|
An API Key is scoped to a single workspace, so it needs no workspace id. A
|
|
210
|
-
Personal Access Token works across workspaces, so it needs one from
|
|
211
|
-
`SEAM_CLI_WORKSPACE_ID
|
|
245
|
+
Personal Access Token works across workspaces, so it needs one from
|
|
246
|
+
`--workspace-id`, `SEAM_CLI_WORKSPACE_ID`, or `seam select workspace`.
|
|
212
247
|
|
|
213
248
|
The command that would store an overridden value fails rather than storing
|
|
214
249
|
something the environment ignores: `seam login` and `seam logout` while
|
package/bin/cli.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { isDeepStrictEqual as isEqual } from 'node:util';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
-
import { cliFlags, getInteractivity, parseCliArgs, toParameterName, } from '../lib/args/parse.js';
|
|
5
|
-
import { assertKnownArgs } from '../lib/args/validate.js';
|
|
4
|
+
import { cliFlags, getInteractivity, parseCliArgs, toAuthOverrides, toParameterName, } from '../lib/args/parse.js';
|
|
5
|
+
import { assertKnownArgs, assertNoAuthOverrides } from '../lib/args/validate.js';
|
|
6
6
|
import { getApiBlueprint } from '../lib/blueprint/index.js';
|
|
7
7
|
import { printCompletion } from '../lib/commands/local/completion.js';
|
|
8
8
|
import { runWizard } from '../lib/commands/local/wizard.js';
|
|
9
|
-
import { acceptedParamsOf, buildRegistry, findLocalCommand, } from '../lib/commands/registry.js';
|
|
9
|
+
import { acceptedParamsOf, buildRegistry, findLocalCommand, findLocalCommandTakingPositional, } from '../lib/commands/registry.js';
|
|
10
10
|
import { getConfigStore } from '../lib/config/index.js';
|
|
11
11
|
import { resolveAuth } from '../lib/context.js';
|
|
12
12
|
import { tokenEnvVar } from '../lib/env.js';
|
|
@@ -17,6 +17,7 @@ import { getOutput, setOutput } from '../lib/output/get-output.js';
|
|
|
17
17
|
import { createOutput } from '../lib/output/output.js';
|
|
18
18
|
import { readStdinJson } from '../lib/output/read-stdin-json.js';
|
|
19
19
|
import { resolveOutputFormat } from '../lib/output/resolve-output-format.js';
|
|
20
|
+
import { setAuthOverrides } from '../lib/overrides.js';
|
|
20
21
|
import { canPrompt } from '../lib/prompt.js';
|
|
21
22
|
import { completionShells, isCompletionShell, } from '../lib/render/completion/index.js';
|
|
22
23
|
import { renderHelp } from '../lib/render/help.js';
|
|
@@ -24,6 +25,18 @@ import seamapiCliVersion from '../lib/version.js';
|
|
|
24
25
|
async function cli(args, argv) {
|
|
25
26
|
const config = getConfigStore();
|
|
26
27
|
const output = getOutput();
|
|
28
|
+
// Scoped to this one command, and read wherever auth resolves, so they are
|
|
29
|
+
// in place before anything asks what the endpoint or the workspace is.
|
|
30
|
+
const authOverrides = toAuthOverrides(args);
|
|
31
|
+
setAuthOverrides(authOverrides);
|
|
32
|
+
// A command may take one value after its path, e.g., the URL in 'seam
|
|
33
|
+
// select endpoint <url>'. Split it off before the path is normalized, or
|
|
34
|
+
// lowercasing the path would rewrite the value along with it.
|
|
35
|
+
const commandWords = args._.map(toCommandWord);
|
|
36
|
+
const commandTakingPositional = findLocalCommandTakingPositional(commandWords);
|
|
37
|
+
const positional = commandTakingPositional == null ? undefined : String(args._.at(-1));
|
|
38
|
+
args._ =
|
|
39
|
+
commandTakingPositional == null ? commandWords : commandWords.slice(0, -1);
|
|
27
40
|
const update = args['update'] === true;
|
|
28
41
|
const helpFlag = args['help'] ?? args['h'];
|
|
29
42
|
if (helpFlag != null) {
|
|
@@ -51,7 +64,6 @@ async function cli(args, argv) {
|
|
|
51
64
|
output.text(seamapiCliVersion);
|
|
52
65
|
return;
|
|
53
66
|
}
|
|
54
|
-
args._ = args._.map(toCommandWord);
|
|
55
67
|
// Argument keys name parameters however they are written, so normalize each
|
|
56
68
|
// one to the name the API gives it. Replace the key rather than adding the
|
|
57
69
|
// normalized form alongside it, or an argument would be sent twice: once as
|
|
@@ -92,6 +104,11 @@ async function cli(args, argv) {
|
|
|
92
104
|
return;
|
|
93
105
|
}
|
|
94
106
|
const localCommand = findLocalCommand(args._);
|
|
107
|
+
// Before the login gate, so a command that selects reports the flag it
|
|
108
|
+
// cannot take rather than whatever the flag pointed it at.
|
|
109
|
+
if (localCommand != null) {
|
|
110
|
+
assertNoAuthOverrides(localCommand.definition, authOverrides);
|
|
111
|
+
}
|
|
95
112
|
// Commands declared not to need a token bypass the login gate. A partial
|
|
96
113
|
// path keeps the historical rule: only login and select endpoint may be
|
|
97
114
|
// reached logged out.
|
|
@@ -140,11 +157,12 @@ async function cli(args, argv) {
|
|
|
140
157
|
}
|
|
141
158
|
// Check the arguments before the command acts on any of them, so a
|
|
142
159
|
// mistake is reported rather than half applied.
|
|
160
|
+
assertNoAuthOverrides(command.definition, authOverrides);
|
|
143
161
|
assertKnownArgs(argParams, selectedCommand, {
|
|
144
162
|
accepted: acceptedParamsOf(command.definition),
|
|
145
163
|
isLocal: findLocalCommand(selectedCommand) != null,
|
|
146
164
|
});
|
|
147
|
-
const result = await command.execute({ path: selectedCommand, argParams, stdinParams, args, argv }, ctx);
|
|
165
|
+
const result = await command.execute({ path: selectedCommand, positional, argParams, stdinParams, args, argv }, ctx);
|
|
148
166
|
if (result.kind === 'back') {
|
|
149
167
|
commandPath = result.toPath;
|
|
150
168
|
continue;
|
|
@@ -152,7 +170,9 @@ async function cli(args, argv) {
|
|
|
152
170
|
return;
|
|
153
171
|
}
|
|
154
172
|
}
|
|
155
|
-
|
|
173
|
+
// minimist reads a numeric word as a number, so a command path is only a
|
|
174
|
+
// path once every word is one.
|
|
175
|
+
const toCommandWord = (arg) => String(arg).toLowerCase().replace(/_/g, '-');
|
|
156
176
|
const run = async (argv) => {
|
|
157
177
|
if (argv[0] === 'wizard') {
|
|
158
178
|
await runWizard(argv.slice(1));
|
package/bin/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/bin/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,MAAM,WAAW,CAAA;AAExD,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/bin/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,MAAM,WAAW,CAAA;AAExD,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACxD,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,gCAAgC,GACjC,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAmB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,EAAE,WAAW,EAA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,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAA;IAE3C,SAAS,CACP,YAAY,CAAC;QACX,MAAM,EAAE,mBAAmB,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC;QAC5C,MAAM,EAAE,KAAK;KACd,CAAC,CACH,CAAA;IAED,MAAM,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AACvB,CAAC,CAAA;AAED,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;IAC9C,kBAAkB,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAA;AACpC,CAAC,CAAC,CAAA"}
|
package/lib/args/parse.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ParsedArgs } from 'minimist';
|
|
2
|
+
import type { AuthOverrides } from '../overrides.js';
|
|
2
3
|
/**
|
|
3
4
|
* How the CLI should behave when properties are not given as arguments.
|
|
4
5
|
*
|
|
@@ -35,6 +36,14 @@ export declare const parseCliArgs: (argv: string[], { stringKeys }?: ParseCliArg
|
|
|
35
36
|
* the parameter it names, minus the flags that configure the CLI itself.
|
|
36
37
|
*/
|
|
37
38
|
export declare const toArgParams: (args: ParsedArgs) => Record<string, unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* The auth overrides among the parsed arguments.
|
|
41
|
+
*
|
|
42
|
+
* Both scope a single command: they change what it resolves to and are never
|
|
43
|
+
* stored, so they read like the environment variables they take precedence
|
|
44
|
+
* over, down to treating a blank value as though it were not given.
|
|
45
|
+
*/
|
|
46
|
+
export declare const toAuthOverrides: (args: ParsedArgs) => AuthOverrides;
|
|
38
47
|
export interface GetInteractivityOptions {
|
|
39
48
|
/**
|
|
40
49
|
* Whether there is a terminal to prompt on.
|
package/lib/args/parse.js
CHANGED
|
@@ -15,17 +15,29 @@ export const interactivityFlags = [
|
|
|
15
15
|
*/
|
|
16
16
|
export const cliFlags = [
|
|
17
17
|
...interactivityFlags,
|
|
18
|
+
'endpoint',
|
|
18
19
|
'h',
|
|
19
20
|
'help',
|
|
20
21
|
'json',
|
|
21
22
|
'remote_api_defs',
|
|
22
23
|
'update',
|
|
23
24
|
'version',
|
|
25
|
+
'workspace_id',
|
|
24
26
|
];
|
|
25
27
|
export const parseCliArgs = (argv, { stringKeys = [] } = {}) => parseArgs(argv, {
|
|
26
28
|
// A page cursor and a code are opaque even before the endpoint's own
|
|
27
|
-
// parameter types are known, so always keep them exactly as given.
|
|
28
|
-
|
|
29
|
+
// parameter types are known, so always keep them exactly as given. The
|
|
30
|
+
// overrides are read as given for the same reason: a URL or an id is
|
|
31
|
+
// never a number, however it happens to be spelled.
|
|
32
|
+
string: [
|
|
33
|
+
'code',
|
|
34
|
+
'endpoint',
|
|
35
|
+
'page-cursor',
|
|
36
|
+
'page_cursor',
|
|
37
|
+
'workspace-id',
|
|
38
|
+
'workspace_id',
|
|
39
|
+
...stringKeys,
|
|
40
|
+
],
|
|
29
41
|
boolean: ['non-interactive', 'interactive', 'json'],
|
|
30
42
|
// Deliberately not aliased to -n, which is reserved for a future
|
|
31
43
|
// --dry-run flag.
|
|
@@ -47,6 +59,34 @@ export const toArgParams = (args) => {
|
|
|
47
59
|
}
|
|
48
60
|
return argParams;
|
|
49
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* The auth overrides among the parsed arguments.
|
|
64
|
+
*
|
|
65
|
+
* Both scope a single command: they change what it resolves to and are never
|
|
66
|
+
* stored, so they read like the environment variables they take precedence
|
|
67
|
+
* over, down to treating a blank value as though it were not given.
|
|
68
|
+
*/
|
|
69
|
+
export const toAuthOverrides = (args) => {
|
|
70
|
+
// Read by the name each key names, as every other argument is, so the
|
|
71
|
+
// overrides may be written `--workspace-id`, `--workspace_id`, or in caps,
|
|
72
|
+
// and so they resolve whenever they are read.
|
|
73
|
+
const byName = {};
|
|
74
|
+
for (const [key, value] of Object.entries(args)) {
|
|
75
|
+
if (key === '_')
|
|
76
|
+
continue;
|
|
77
|
+
byName[toParameterName(key)] = value;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
endpoint: readOverride(byName['endpoint']),
|
|
81
|
+
workspaceId: readOverride(byName['workspace_id']),
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
const readOverride = (value) => {
|
|
85
|
+
if (typeof value !== 'string')
|
|
86
|
+
return null;
|
|
87
|
+
const trimmedValue = value.trim();
|
|
88
|
+
return trimmedValue === '' ? null : trimmedValue;
|
|
89
|
+
};
|
|
50
90
|
export const getInteractivity = (args, { canPrompt = true } = {}) => {
|
|
51
91
|
const isNonInteractive = args['non_interactive'] === true || args['y'] === true;
|
|
52
92
|
const isInteractive = args['interactive'] === true || args['i'] === true;
|
package/lib/args/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/lib/args/parse.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAmB,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/lib/args/parse.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAmB,MAAM,UAAU,CAAA;AAgBrD;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAa;IAC1C,iBAAiB;IACjB,GAAG;IACH,aAAa;IACb,GAAG;CACJ,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAa;IAChC,GAAG,kBAAkB;IACrB,UAAU;IACV,GAAG;IACH,MAAM;IACN,MAAM;IACN,iBAAiB;IACjB,QAAQ;IACR,SAAS;IACT,cAAc;CACf,CAAA;AAYD,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,IAAc,EACd,EAAE,UAAU,GAAG,EAAE,KAA0B,EAAE,EACjC,EAAE,CACd,SAAS,CAAC,IAAI,EAAE;IACd,qEAAqE;IACrE,uEA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E,CACxD,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAc,EAAU,EAAE,CACvD,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA"}
|
package/lib/args/validate.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Parameter } from '@seamapi/blueprint';
|
|
2
|
+
import type { CommandDefinition } from '../commands/spec.js';
|
|
3
|
+
import type { AuthOverrides } from '../overrides.js';
|
|
2
4
|
/**
|
|
3
5
|
* Report every required parameter still missing from the params, rather
|
|
4
6
|
* than prompting for it.
|
|
@@ -15,6 +17,14 @@ export declare const assertRequiredParams: (parameters: Parameter[], params: Rec
|
|
|
15
17
|
* Only arguments are checked. Params read from stdin are passed through as
|
|
16
18
|
* given, so a caller may send whatever the API itself accepts.
|
|
17
19
|
*/
|
|
20
|
+
/**
|
|
21
|
+
* Refuse the auth overrides on a command that selects what they override.
|
|
22
|
+
*
|
|
23
|
+
* `--endpoint` and `--workspace-id` scope one command and are never stored,
|
|
24
|
+
* so on `seam select ...` they would read as the value to store and quietly
|
|
25
|
+
* do nothing of the kind. The positional is what stores.
|
|
26
|
+
*/
|
|
27
|
+
export declare const assertNoAuthOverrides: ({ path, positional }: CommandDefinition, overrides: AuthOverrides) => void;
|
|
18
28
|
export declare const assertKnownArgs: (argParams: Record<string, unknown>, command: string[], { accepted, isLocal, }: {
|
|
19
29
|
/** Parameter names the command accepts. */
|
|
20
30
|
accepted: Set<string>;
|
package/lib/args/validate.js
CHANGED
|
@@ -26,6 +26,29 @@ export const assertRequiredParams = (parameters, params, target) => {
|
|
|
26
26
|
* Only arguments are checked. Params read from stdin are passed through as
|
|
27
27
|
* given, so a caller may send whatever the API itself accepts.
|
|
28
28
|
*/
|
|
29
|
+
/**
|
|
30
|
+
* Refuse the auth overrides on a command that selects what they override.
|
|
31
|
+
*
|
|
32
|
+
* `--endpoint` and `--workspace-id` scope one command and are never stored,
|
|
33
|
+
* so on `seam select ...` they would read as the value to store and quietly
|
|
34
|
+
* do nothing of the kind. The positional is what stores.
|
|
35
|
+
*/
|
|
36
|
+
export const assertNoAuthOverrides = ({ path, positional }, overrides) => {
|
|
37
|
+
if (path[0] !== 'select')
|
|
38
|
+
return;
|
|
39
|
+
const given = [
|
|
40
|
+
overrides.endpoint == null ? null : '--endpoint',
|
|
41
|
+
overrides.workspaceId == null ? null : '--workspace-id',
|
|
42
|
+
].filter((flag) => flag != null);
|
|
43
|
+
if (given.length === 0)
|
|
44
|
+
return;
|
|
45
|
+
const command = `seam ${path.join(' ')}`;
|
|
46
|
+
throw new UsageError(`${given.join(' and ')} cannot be used with ${command}: ${given.length === 1 ? 'it overrides' : 'they override'} a single command rather than changing what is selected.`, {
|
|
47
|
+
hint: positional == null
|
|
48
|
+
? `Run '${command}' to change what is selected.`
|
|
49
|
+
: `Run '${command} <${positional.name}>' to change what is selected.`,
|
|
50
|
+
});
|
|
51
|
+
};
|
|
29
52
|
export const assertKnownArgs = (argParams, command, { accepted, isLocal, }) => {
|
|
30
53
|
const unknown = Object.keys(argParams).filter((key) => !accepted.has(key));
|
|
31
54
|
if (unknown.length === 0)
|
package/lib/args/validate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/lib/args/validate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/lib/args/validate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAG/D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEtD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBA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;KACvE,CACF,CAAA;AACH,CAAC,CAAA"}
|
package/lib/auth/operations.d.ts
CHANGED
|
@@ -13,20 +13,18 @@ export type AuthSetting = 'endpoint' | 'token' | 'workspaceId';
|
|
|
13
13
|
* @param action What the command does, e.g., `log in`.
|
|
14
14
|
*/
|
|
15
15
|
export declare const assertMutable: (auth: AuthContext, setting: AuthSetting, action: string) => void;
|
|
16
|
-
export interface LoginOptions {
|
|
17
|
-
endpoint?: string | undefined;
|
|
18
|
-
token?: string | undefined;
|
|
19
|
-
workspaceId?: string | undefined;
|
|
20
|
-
}
|
|
21
16
|
/**
|
|
22
|
-
* Store
|
|
17
|
+
* Store a token, validating it first.
|
|
23
18
|
*
|
|
24
|
-
* The token is stored under the endpoint it will be used with,
|
|
25
|
-
* endpoint
|
|
19
|
+
* The token is stored under the endpoint it will be used with, which
|
|
20
|
+
* `--endpoint` or the environment may have pointed elsewhere for this one
|
|
21
|
+
* command: logging in to another endpoint stores a token for it without
|
|
22
|
+
* selecting it. The workspace is only what the token is validated against,
|
|
23
|
+
* as a Personal Access Token is meaningless without one.
|
|
26
24
|
*
|
|
27
25
|
* Validation reaches the network, so a test may inject its own `validate`.
|
|
28
26
|
*/
|
|
29
|
-
export declare const login: (
|
|
27
|
+
export declare const login: (token: string, config?: ConfigStore, validate?: typeof validateToken) => Promise<void>;
|
|
30
28
|
/** Store the token for the current endpoint, e.g., one just prompted for. */
|
|
31
29
|
export declare const storeToken: (token: string, config?: ConfigStore) => void;
|
|
32
30
|
/** Remove the stored token and workspace selection. */
|
package/lib/auth/operations.js
CHANGED
|
@@ -30,35 +30,25 @@ export const assertMutable = (auth, setting, action) => {
|
|
|
30
30
|
assertEnvVarUnset(envVar, value, action);
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
|
-
* Store
|
|
33
|
+
* Store a token, validating it first.
|
|
34
34
|
*
|
|
35
|
-
* The token is stored under the endpoint it will be used with,
|
|
36
|
-
* endpoint
|
|
35
|
+
* The token is stored under the endpoint it will be used with, which
|
|
36
|
+
* `--endpoint` or the environment may have pointed elsewhere for this one
|
|
37
|
+
* command: logging in to another endpoint stores a token for it without
|
|
38
|
+
* selecting it. The workspace is only what the token is validated against,
|
|
39
|
+
* as a Personal Access Token is meaningless without one.
|
|
37
40
|
*
|
|
38
41
|
* Validation reaches the network, so a test may inject its own `validate`.
|
|
39
42
|
*/
|
|
40
|
-
export const login = async (
|
|
41
|
-
|
|
43
|
+
export const login = async (token, config = getConfigStore(), validate = validateToken) => {
|
|
44
|
+
const auth = resolveAuth(config);
|
|
42
45
|
// Nothing is stored while the environment overrides it, so refuse before
|
|
43
|
-
//
|
|
46
|
+
// validating rather than after reaching the network.
|
|
44
47
|
assertMutable(auth, 'token', 'log in');
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
if (endpoint != null) {
|
|
51
|
-
storeEndpoint(endpoint, config);
|
|
52
|
-
auth = resolveAuth(config);
|
|
53
|
-
}
|
|
54
|
-
if (token != null) {
|
|
55
|
-
await validate(token, workspaceId);
|
|
56
|
-
config.set(`${auth.endpoint}.pat`, token);
|
|
57
|
-
config.delete('current_workspace_id');
|
|
58
|
-
}
|
|
59
|
-
if (workspaceId != null) {
|
|
60
|
-
config.set('current_workspace_id', workspaceId);
|
|
61
|
-
}
|
|
48
|
+
await validate(token, auth.workspaceId ?? undefined);
|
|
49
|
+
config.set(`${auth.endpoint}.pat`, token);
|
|
50
|
+
// The selection belongs to whoever was logged in before.
|
|
51
|
+
config.delete('current_workspace_id');
|
|
62
52
|
};
|
|
63
53
|
/** Store the token for the current endpoint, e.g., one just prompted for. */
|
|
64
54
|
export const storeToken = (token, config = getConfigStore()) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/lib/auth/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACtE,OAAO,EAAoB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AG,CACjC,gBAAyB,EACzB,SAAsB,cAAc,EAAE,EAChC,EAAE;IACR,MAAM,CAAC,GAAG,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAA;AACrD,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAE,MAAmB,EAAQ,EAAE;IACpE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAChC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACvB,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAA;AACvC,CAAC,CAAA"}
|
|
@@ -7,21 +7,13 @@ export const loginCommand = {
|
|
|
7
7
|
path: ['login'],
|
|
8
8
|
kind: 'cli',
|
|
9
9
|
title: 'Log in to Seam.',
|
|
10
|
-
description: 'Prompts for a personal access token unless one is passed with --token.',
|
|
11
|
-
flags: [
|
|
12
|
-
stringFlag('endpoint', 'Seam API endpoint to log in to.'),
|
|
13
|
-
stringFlag('token', 'Personal access token to log in with.'),
|
|
14
|
-
stringFlag('workspace-id', 'Workspace to select after logging in.'),
|
|
15
|
-
],
|
|
10
|
+
description: 'Prompts for a personal access token unless one is passed with --token. The token is stored for the selected endpoint, or for the one --endpoint names.',
|
|
11
|
+
flags: [stringFlag('token', 'Personal access token to log in with.')],
|
|
16
12
|
},
|
|
17
13
|
requiresAuth: false,
|
|
18
14
|
execute: async ({ args }, ctx) => {
|
|
19
|
-
if (args['token']
|
|
20
|
-
await login(
|
|
21
|
-
endpoint: args['endpoint'] ? args['endpoint'] : undefined,
|
|
22
|
-
token: args['token'] ? String(args['token']).trim() : undefined,
|
|
23
|
-
workspaceId: args['workspace_id'] ? args['workspace_id'] : undefined,
|
|
24
|
-
}, ctx.config);
|
|
15
|
+
if (args['token']) {
|
|
16
|
+
await login(String(args['token']).trim(), ctx.config);
|
|
25
17
|
return { kind: 'done' };
|
|
26
18
|
}
|
|
27
19
|
assertMutable(ctx.auth, 'token', 'log in');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../../src/lib/commands/local/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAE5D,MAAM,CAAC,MAAM,YAAY,GAAY;IACnC,UAAU,EAAE;QACV,IAAI,EAAE,CAAC,OAAO,CAAC;QACf,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,iBAAiB;QACxB,WAAW,EACT,
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../../src/lib/commands/local/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAE5D,MAAM,CAAC,MAAM,YAAY,GAAY;IACnC,UAAU,EAAE;QACV,IAAI,EAAE,CAAC,OAAO,CAAC;QACf,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,iBAAiB;QACxB,WAAW,EACT,wJAAwJ;QAC1J,KAAK,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,uCAAuC,CAAC,CAAC;KACtE;IACD,YAAY,EAAE,KAAK;IACnB,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE;QAC/B,IAAI,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAClB,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;YACrD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;QACzB,CAAC;QACD,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;QAC1C,IAAI,GAAG,CAAC,aAAa,KAAK,iBAAiB,EAAE,CAAC;YAC5C,MAAM,IAAI,mBAAmB,CAC3B,+CAA+C,CAChD,CAAA;QACH,CAAC;QACD,MAAM,gBAAgB,EAAE,CAAA;QACxB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IACzB,CAAC;CACF,CAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { assertMutable, selectEndpoint } from '../../auth/operations.js';
|
|
2
|
-
import { stringFlag } from '../../commands/spec.js';
|
|
3
2
|
import { NonInteractiveError } from '../../errors.js';
|
|
4
3
|
import { interactForEndpointSelection } from '../../interactions/index.js';
|
|
5
4
|
export const selectEndpointCommand = {
|
|
@@ -7,18 +6,22 @@ export const selectEndpointCommand = {
|
|
|
7
6
|
path: ['select', 'endpoint'],
|
|
8
7
|
kind: 'cli',
|
|
9
8
|
title: 'Select the Seam API endpoint.',
|
|
10
|
-
description: '',
|
|
11
|
-
flags: [
|
|
9
|
+
description: 'Stores the endpoint every later command runs against. To use one for a single command instead, pass --endpoint to that command.',
|
|
10
|
+
flags: [],
|
|
11
|
+
positional: {
|
|
12
|
+
name: 'url',
|
|
13
|
+
description: 'Seam API endpoint to select.',
|
|
14
|
+
},
|
|
12
15
|
},
|
|
13
16
|
requiresAuth: false,
|
|
14
|
-
execute: async ({
|
|
17
|
+
execute: async ({ positional }, ctx) => {
|
|
15
18
|
assertMutable(ctx.auth, 'endpoint', 'select an endpoint');
|
|
16
|
-
if (
|
|
17
|
-
selectEndpoint(
|
|
19
|
+
if (positional != null) {
|
|
20
|
+
selectEndpoint(positional, ctx.config);
|
|
18
21
|
return { kind: 'done' };
|
|
19
22
|
}
|
|
20
23
|
if (ctx.interactivity === 'non-interactive') {
|
|
21
|
-
throw new NonInteractiveError('Missing required
|
|
24
|
+
throw new NonInteractiveError('Missing required argument for select endpoint: <url>');
|
|
22
25
|
}
|
|
23
26
|
await interactForEndpointSelection();
|
|
24
27
|
return { kind: 'done' };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-endpoint.js","sourceRoot":"","sources":["../../../src/lib/commands/local/select-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAEtE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"select-endpoint.js","sourceRoot":"","sources":["../../../src/lib/commands/local/select-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAEtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAA;AAExE,MAAM,CAAC,MAAM,qBAAqB,GAAY;IAC5C,UAAU,EAAE;QACV,IAAI,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC5B,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,+BAA+B;QACtC,WAAW,EACT,iIAAiI;QACnI,KAAK,EAAE,EAAE;QACT,UAAU,EAAE;YACV,IAAI,EAAE,KAAK;YACX,WAAW,EAAE,8BAA8B;SAC5C;KACF;IACD,YAAY,EAAE,KAAK;IACnB,OAAO,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,EAAE;QACrC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,oBAAoB,CAAC,CAAA;QACzD,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;YACvB,cAAc,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;YACtC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;QACzB,CAAC;QACD,IAAI,GAAG,CAAC,aAAa,KAAK,iBAAiB,EAAE,CAAC;YAC5C,MAAM,IAAI,mBAAmB,CAC3B,sDAAsD,CACvD,CAAA;QACH,CAAC;QACD,MAAM,4BAA4B,EAAE,CAAA;QACpC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IACzB,CAAC;CACF,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertMutable } from '../../auth/operations.js';
|
|
1
|
+
import { assertMutable, selectWorkspace } from '../../auth/operations.js';
|
|
2
2
|
import { NonInteractiveError } from '../../errors.js';
|
|
3
3
|
import { interactForWorkspaceId } from '../../interactions/index.js';
|
|
4
4
|
export const selectWorkspaceCommand = {
|
|
@@ -6,14 +6,22 @@ export const selectWorkspaceCommand = {
|
|
|
6
6
|
path: ['select', 'workspace'],
|
|
7
7
|
kind: 'cli',
|
|
8
8
|
title: 'Select the current workspace.',
|
|
9
|
-
description: '',
|
|
9
|
+
description: 'Stores the workspace every later command runs against. To use one for a single command instead, pass --workspace-id to that command.',
|
|
10
10
|
flags: [],
|
|
11
|
+
positional: {
|
|
12
|
+
name: 'workspace-id',
|
|
13
|
+
description: 'Workspace to select.',
|
|
14
|
+
},
|
|
11
15
|
},
|
|
12
16
|
requiresAuth: true,
|
|
13
|
-
execute: async (
|
|
17
|
+
execute: async ({ positional }, ctx) => {
|
|
14
18
|
assertMutable(ctx.auth, 'workspaceId', 'select a workspace');
|
|
19
|
+
if (positional != null) {
|
|
20
|
+
selectWorkspace(positional, ctx.config);
|
|
21
|
+
return { kind: 'done' };
|
|
22
|
+
}
|
|
15
23
|
if (ctx.interactivity === 'non-interactive') {
|
|
16
|
-
throw new NonInteractiveError('
|
|
24
|
+
throw new NonInteractiveError('Missing required argument for select workspace: <workspace-id>');
|
|
17
25
|
}
|
|
18
26
|
await interactForWorkspaceId();
|
|
19
27
|
return { kind: 'done' };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-workspace.js","sourceRoot":"","sources":["../../../src/lib/commands/local/select-workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"select-workspace.js","sourceRoot":"","sources":["../../../src/lib/commands/local/select-workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAEvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAElE,MAAM,CAAC,MAAM,sBAAsB,GAAY;IAC7C,UAAU,EAAE;QACV,IAAI,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;QAC7B,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,+BAA+B;QACtC,WAAW,EACT,sIAAsI;QACxI,KAAK,EAAE,EAAE;QACT,UAAU,EAAE;YACV,IAAI,EAAE,cAAc;YACpB,WAAW,EAAE,sBAAsB;SACpC;KACF;IACD,YAAY,EAAE,IAAI;IAClB,OAAO,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,EAAE;QACrC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,aAAa,EAAE,oBAAoB,CAAC,CAAA;QAC5D,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;YACvB,eAAe,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;YACvC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;QACzB,CAAC;QACD,IAAI,GAAG,CAAC,aAAa,KAAK,iBAAiB,EAAE,CAAC;YAC5C,MAAM,IAAI,mBAAmB,CAC3B,gEAAgE,CACjE,CAAA;QACH,CAAC;QACD,MAAM,sBAAsB,EAAE,CAAA;QAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IACzB,CAAC;CACF,CAAA"}
|
|
@@ -18,6 +18,8 @@ export interface Command {
|
|
|
18
18
|
/** Everything a single run of a command was given. */
|
|
19
19
|
export interface Invocation {
|
|
20
20
|
path: string[];
|
|
21
|
+
/** The value written after the command path, when the command takes one. */
|
|
22
|
+
positional?: string | undefined;
|
|
21
23
|
/** Params given as arguments, held to what the command accepts. */
|
|
22
24
|
argParams: Record<string, unknown>;
|
|
23
25
|
/** Params piped in as JSON, passed through as given. */
|
|
@@ -49,6 +51,15 @@ export declare const localCommandDefinitions: CommandDefinition[];
|
|
|
49
51
|
* commands before any definitions are loaded.
|
|
50
52
|
*/
|
|
51
53
|
export declare const findLocalCommand: (path: string[]) => Command | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The local command the given words invoke with a value after its path, e.g.,
|
|
56
|
+
* `select endpoint` for `select endpoint https://connect.getseam.com`, or
|
|
57
|
+
* `undefined` when the words are not a command taking one.
|
|
58
|
+
*
|
|
59
|
+
* Only commands declaring a positional match, so a stray word after any other
|
|
60
|
+
* command stays what it has always been: no command at all.
|
|
61
|
+
*/
|
|
62
|
+
export declare const findLocalCommandTakingPositional: (words: string[]) => Command | undefined;
|
|
52
63
|
/** Parameter names a command accepts as arguments. */
|
|
53
64
|
export declare const acceptedParamsOf: (definition: CommandDefinition) => Set<string>;
|
|
54
65
|
export declare const buildRegistry: (blueprint: ApiBlueprint) => CommandRegistry;
|
package/lib/commands/registry.js
CHANGED
|
@@ -37,6 +37,17 @@ export const localCommandDefinitions = localCommands
|
|
|
37
37
|
* commands before any definitions are loaded.
|
|
38
38
|
*/
|
|
39
39
|
export const findLocalCommand = (path) => localCommands.find((command) => isSamePath(command.definition.path, path));
|
|
40
|
+
/**
|
|
41
|
+
* The local command the given words invoke with a value after its path, e.g.,
|
|
42
|
+
* `select endpoint` for `select endpoint https://connect.getseam.com`, or
|
|
43
|
+
* `undefined` when the words are not a command taking one.
|
|
44
|
+
*
|
|
45
|
+
* Only commands declaring a positional match, so a stray word after any other
|
|
46
|
+
* command stays what it has always been: no command at all.
|
|
47
|
+
*/
|
|
48
|
+
export const findLocalCommandTakingPositional = (words) => localCommands.find(({ definition }) => definition.positional != null &&
|
|
49
|
+
words.length === definition.path.length + 1 &&
|
|
50
|
+
isSamePath(definition.path, words.slice(0, -1)));
|
|
40
51
|
/** Parameter names a command accepts as arguments. */
|
|
41
52
|
export const acceptedParamsOf = (definition) => new Set(definition.flags.flatMap(({ long }) => long == null ? [] : [toParameterName(long)]));
|
|
42
53
|
export const buildRegistry = (blueprint) => {
|