@seamapi/cli 0.16.0 → 0.17.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/bin/cli.js +7 -4
- package/bin/cli.js.map +1 -1
- package/lib/interact-for-action-attempt-poll.js +3 -5
- package/lib/interact-for-action-attempt-poll.js.map +1 -1
- package/lib/interact-for-array.js +11 -18
- package/lib/interact-for-array.js.map +1 -1
- package/lib/interact-for-blueprint-object.js +19 -31
- package/lib/interact-for-blueprint-object.js.map +1 -1
- package/lib/interact-for-command-selection.js +6 -11
- package/lib/interact-for-command-selection.js.map +1 -1
- package/lib/interact-for-custom-metadata.js +10 -21
- package/lib/interact-for-custom-metadata.js.map +1 -1
- package/lib/interact-for-login.js +3 -5
- package/lib/interact-for-login.js.map +1 -1
- package/lib/interact-for-resource.js +6 -6
- package/lib/interact-for-resource.js.map +1 -1
- package/lib/interact-for-server-selection.js +9 -17
- package/lib/interact-for-server-selection.js.map +1 -1
- package/lib/interact-for-timestamp.d.ts +1 -1
- package/lib/interact-for-timestamp.js +14 -5
- package/lib/interact-for-timestamp.js.map +1 -1
- package/lib/interact-for-use-remote-api-defs.js +14 -18
- package/lib/interact-for-use-remote-api-defs.js.map +1 -1
- package/lib/interact-for-workspace-id.d.ts +1 -1
- package/lib/interact-for-workspace-id.js +8 -13
- package/lib/interact-for-workspace-id.js.map +1 -1
- package/lib/util/prompt.d.ts +42 -13
- package/lib/util/prompt.js +79 -28
- package/lib/util/prompt.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +2 -3
- package/src/bin/cli.ts +12 -4
- package/src/lib/interact-for-action-attempt-poll.ts +3 -5
- package/src/lib/interact-for-array.ts +11 -19
- package/src/lib/interact-for-blueprint-object.ts +35 -46
- package/src/lib/interact-for-command-selection.ts +6 -12
- package/src/lib/interact-for-custom-metadata.ts +10 -22
- package/src/lib/interact-for-login.ts +3 -5
- package/src/lib/interact-for-resource.ts +6 -7
- package/src/lib/interact-for-server-selection.ts +10 -18
- package/src/lib/interact-for-timestamp.ts +14 -5
- package/src/lib/interact-for-use-remote-api-defs.ts +14 -18
- package/src/lib/interact-for-workspace-id.ts +8 -14
- package/src/lib/util/prompt.ts +138 -38
- package/src/lib/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interact-for-server-selection.js","sourceRoot":"","sources":["../src/lib/interact-for-server-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,WAAW,GACZ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"interact-for-server-selection.js","sourceRoot":"","sources":["../src/lib/interact-for-server-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,WAAW,GACZ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAEjE,MAAM,CAAC,KAAK,UAAU,0BAA0B;IAC9C,iBAAiB,CAAC,cAAc,EAAE,kBAAkB,EAAE,EAAE,iBAAiB,CAAC,CAAA;IAE1E,MAAM,OAAO,GAAG;QACd,uBAAuB;QACvB,6BA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promise<
|
|
1
|
+
export declare const interactForTimestamp: () => Promise<string>;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { promptText } from './util/prompt.js';
|
|
2
2
|
export const interactForTimestamp = async () => {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
type: 'date',
|
|
3
|
+
const now = new Date().toISOString();
|
|
4
|
+
const timestamp = await promptText({
|
|
6
5
|
message: 'Enter a timestamp:',
|
|
6
|
+
placeholder: now,
|
|
7
|
+
defaultValue: now,
|
|
8
|
+
validate: (value) => {
|
|
9
|
+
if (value == null || value === '')
|
|
10
|
+
return undefined;
|
|
11
|
+
if (Number.isNaN(new Date(value).getTime())) {
|
|
12
|
+
return `Enter a valid timestamp, e.g. ${now}`;
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
},
|
|
7
16
|
});
|
|
8
|
-
return timestamp.toISOString();
|
|
17
|
+
return new Date(timestamp).toISOString();
|
|
9
18
|
};
|
|
10
19
|
//# sourceMappingURL=interact-for-timestamp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interact-for-timestamp.js","sourceRoot":"","sources":["../src/lib/interact-for-timestamp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"interact-for-timestamp.js","sourceRoot":"","sources":["../src/lib/interact-for-timestamp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,IAAI,EAAE;IAC7C,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACpC,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC;QACjC,OAAO,EAAE,oBAAoB;QAC7B,WAAW,EAAE,GAAG;QAChB,YAAY,EAAE,GAAG;QACjB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YAClB,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,EAAE;gBAAE,OAAO,SAAS,CAAA;YACnD,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;gBAC5C,OAAO,iCAAiC,GAAG,EAAE,CAAA;YAC/C,CAAC;YACD,OAAO,SAAS,CAAA;QAClB,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAA;AAC1C,CAAC,CAAA"}
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import { getConfigStore } from './config/index.js';
|
|
2
2
|
import { getOutput } from './output/get-output.js';
|
|
3
|
-
import {
|
|
3
|
+
import { promptSelect } from './util/prompt.js';
|
|
4
4
|
export async function interactForUseRemoteApiDefs() {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
]);
|
|
5
|
+
const useRemoteApiDefs = await promptSelect({
|
|
6
|
+
message: 'Always use remote API Definitions?',
|
|
7
|
+
choices: [
|
|
8
|
+
{
|
|
9
|
+
label: 'Yes',
|
|
10
|
+
value: true,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
label: 'No',
|
|
14
|
+
value: false,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
});
|
|
22
18
|
const config = getConfigStore();
|
|
23
19
|
config.set('use_remote_api_defs', useRemoteApiDefs);
|
|
24
20
|
getOutput().info(`Use remote API Definitions: ${useRemoteApiDefs}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interact-for-use-remote-api-defs.js","sourceRoot":"","sources":["../src/lib/interact-for-use-remote-api-defs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"interact-for-use-remote-api-defs.js","sourceRoot":"","sources":["../src/lib/interact-for-use-remote-api-defs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,MAAM,CAAC,KAAK,UAAU,2BAA2B;IAC/C,MAAM,gBAAgB,GAAG,MAAM,YAAY,CAAC;QAC1C,OAAO,EAAE,oCAAoC;QAC7C,OAAO,EAAE;YACP;gBACE,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,IAAI;aACZ;YACD;gBACE,KAAK,EAAE,IAAI;gBACX,KAAK,EAAE,KAAK;aACb;SACF;KACF,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,cAAc,EAAE,CAAA;IAC/B,MAAM,CAAC,GAAG,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAA;IACnD,SAAS,EAAE,CAAC,IAAI,CAAC,+BAA+B,gBAAgB,EAAE,CAAC,CAAA;AACrE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const interactForWorkspaceId: (personalAccessToken?: string) => Promise<
|
|
1
|
+
export declare const interactForWorkspaceId: (personalAccessToken?: string) => Promise<string>;
|
|
@@ -3,7 +3,7 @@ import { getConfigStore } from './config/index.js';
|
|
|
3
3
|
import { assertEnvVarUnset, getWorkspaceIdFromEnv, workspaceIdEnvVar, } from './env.js';
|
|
4
4
|
import { getSeamMultiWorkspace } from './get-seam.js';
|
|
5
5
|
import { getServer } from './get-server.js';
|
|
6
|
-
import {
|
|
6
|
+
import { promptAutocomplete } from './util/prompt.js';
|
|
7
7
|
import { withLoading } from './util/with-loading.js';
|
|
8
8
|
export const interactForWorkspaceId = async (personalAccessToken) => {
|
|
9
9
|
const config = getConfigStore();
|
|
@@ -14,22 +14,17 @@ export const interactForWorkspaceId = async (personalAccessToken) => {
|
|
|
14
14
|
})
|
|
15
15
|
: await getSeamMultiWorkspace();
|
|
16
16
|
const workspaces = await withLoading('Fetching workspaces...', () => seam.workspaces.list());
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// more workspaces than fit on a screen.
|
|
21
|
-
type: 'autocomplete',
|
|
17
|
+
// Searchable, as selecting a device or a command is: an account may have
|
|
18
|
+
// more workspaces than fit on a screen.
|
|
19
|
+
const workspaceId = await promptAutocomplete({
|
|
22
20
|
message: 'Select a workspace:',
|
|
23
21
|
choices: workspaces.map((workspace) => ({
|
|
24
|
-
|
|
22
|
+
label: workspace.name,
|
|
25
23
|
value: workspace.workspace_id,
|
|
26
|
-
|
|
24
|
+
hint: workspace.workspace_id,
|
|
27
25
|
})),
|
|
28
26
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return workspaceId;
|
|
32
|
-
}
|
|
33
|
-
throw new Error('Bailed');
|
|
27
|
+
config.set('current_workspace_id', workspaceId);
|
|
28
|
+
return workspaceId;
|
|
34
29
|
};
|
|
35
30
|
//# sourceMappingURL=interact-for-workspace-id.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interact-for-workspace-id.js","sourceRoot":"","sources":["../src/lib/interact-for-workspace-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,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AI;YACrB,KAAK,EAAE,SAAS,CAAC,YAAY;YAC7B,IAAI,EAAE,SAAS,CAAC,YAAY;SAC7B,CAAC,CAAC;KACJ,CAAC,CAAA;IAEF,MAAM,CAAC,GAAG,CAAC,sBAAsB,EAAE,WAAW,CAAC,CAAA;IAC/C,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA"}
|
package/lib/util/prompt.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type Answers, type Options, type PromptObject } from 'prompts';
|
|
2
1
|
/**
|
|
3
2
|
* Whether the CLI can ask the user a question.
|
|
4
3
|
*
|
|
@@ -8,19 +7,49 @@ import { type Answers, type Options, type PromptObject } from 'prompts';
|
|
|
8
7
|
* question.
|
|
9
8
|
*/
|
|
10
9
|
export declare const canPrompt: () => boolean;
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
/** The user dismissed a prompt with ctrl-c or escape instead of answering. */
|
|
11
|
+
export declare class PromptCancelledError extends Error {
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
14
|
+
export interface PromptChoice<Value> {
|
|
15
|
+
label: string;
|
|
16
|
+
value: Value;
|
|
17
|
+
hint?: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
export declare const promptText: (options: {
|
|
20
|
+
message: string;
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
defaultValue?: string;
|
|
23
|
+
validate?: (value: string | undefined) => string | undefined;
|
|
24
|
+
}) => Promise<string>;
|
|
25
|
+
export declare const promptNumber: (options: {
|
|
26
|
+
message: string;
|
|
27
|
+
validate?: (value: number) => string | undefined;
|
|
28
|
+
}) => Promise<number>;
|
|
29
|
+
export declare const promptConfirm: (options: {
|
|
30
|
+
message: string;
|
|
31
|
+
initialValue?: boolean;
|
|
32
|
+
active?: string;
|
|
33
|
+
inactive?: string;
|
|
34
|
+
}) => Promise<boolean>;
|
|
35
|
+
export declare const promptSelect: <Value>(options: {
|
|
36
|
+
message: string;
|
|
37
|
+
choices: Array<PromptChoice<Value>>;
|
|
38
|
+
}) => Promise<Value>;
|
|
39
|
+
export declare const promptAutocomplete: <Value>(options: {
|
|
40
|
+
message: string;
|
|
41
|
+
choices: Array<PromptChoice<Value>>;
|
|
42
|
+
}) => Promise<Value>;
|
|
43
|
+
export declare const promptAutocompleteMultiselect: <Value>(options: {
|
|
44
|
+
message: string;
|
|
45
|
+
choices: Array<PromptChoice<Value>>;
|
|
46
|
+
}) => Promise<Value[]>;
|
|
18
47
|
export interface SearchableChoice {
|
|
19
|
-
|
|
20
|
-
|
|
48
|
+
label?: string | undefined;
|
|
49
|
+
hint?: string | undefined;
|
|
21
50
|
}
|
|
22
51
|
/**
|
|
23
|
-
*
|
|
24
|
-
* case insensitively against the
|
|
52
|
+
* Match a choice by every whitespace separated term of the input, matched
|
|
53
|
+
* case insensitively against the label and the hint.
|
|
25
54
|
*/
|
|
26
|
-
export declare const searchChoices:
|
|
55
|
+
export declare const searchChoices: (input: string, choice: SearchableChoice) => boolean;
|
package/lib/util/prompt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { autocomplete, autocompleteMultiselect, confirm, isCancel, select, text, } from '@clack/prompts';
|
|
2
2
|
import { NonInteractiveError } from './cli-args.js';
|
|
3
3
|
/**
|
|
4
4
|
* Whether the CLI can ask the user a question.
|
|
@@ -9,43 +9,94 @@ import { NonInteractiveError } from './cli-args.js';
|
|
|
9
9
|
* question.
|
|
10
10
|
*/
|
|
11
11
|
export const canPrompt = () => process.stdin.isTTY === true && process.stderr.isTTY === true;
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
/** The user dismissed a prompt with ctrl-c or escape instead of answering. */
|
|
13
|
+
export class PromptCancelledError extends Error {
|
|
14
|
+
constructor() {
|
|
15
|
+
super('Cancelled');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const ensureInteractive = () => {
|
|
19
19
|
if (!canPrompt()) {
|
|
20
20
|
throw new NonInteractiveError('Cannot prompt without a terminal: pass the missing arguments, or pipe them in as JSON');
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
};
|
|
23
|
+
const unwrap = (value) => {
|
|
24
|
+
if (isCancel(value))
|
|
25
|
+
throw new PromptCancelledError();
|
|
26
|
+
return value;
|
|
27
|
+
};
|
|
28
|
+
// Prompts are rendered to stderr: a selection is not a command result,
|
|
29
|
+
// so it must not end up in stdout when the CLI is piped.
|
|
30
|
+
const output = process.stderr;
|
|
31
|
+
const toOptions = (choices) => choices.map(({ label, value, hint }) => (hint === undefined
|
|
32
|
+
? { label, value }
|
|
33
|
+
: { label, value, hint }));
|
|
34
|
+
export const promptText = async (options) => {
|
|
35
|
+
ensureInteractive();
|
|
36
|
+
return unwrap(await text({ ...options, output }));
|
|
37
|
+
};
|
|
38
|
+
export const promptNumber = async (options) => {
|
|
39
|
+
ensureInteractive();
|
|
40
|
+
const value = unwrap(await text({
|
|
41
|
+
message: options.message,
|
|
42
|
+
validate: (value) => {
|
|
43
|
+
if (value == null || value.trim() === '')
|
|
44
|
+
return 'Enter a number';
|
|
45
|
+
const parsed = Number(value);
|
|
46
|
+
if (Number.isNaN(parsed))
|
|
47
|
+
return 'Enter a number';
|
|
48
|
+
return options.validate?.(parsed);
|
|
49
|
+
},
|
|
50
|
+
output,
|
|
51
|
+
}));
|
|
52
|
+
return Number(value);
|
|
53
|
+
};
|
|
54
|
+
export const promptConfirm = async (options) => {
|
|
55
|
+
ensureInteractive();
|
|
56
|
+
return unwrap(await confirm({ ...options, output }));
|
|
57
|
+
};
|
|
58
|
+
export const promptSelect = async (options) => {
|
|
59
|
+
ensureInteractive();
|
|
60
|
+
return unwrap(await select({
|
|
61
|
+
message: options.message,
|
|
62
|
+
options: toOptions(options.choices),
|
|
63
|
+
output,
|
|
64
|
+
}));
|
|
65
|
+
};
|
|
66
|
+
export const promptAutocomplete = async (options) => {
|
|
67
|
+
ensureInteractive();
|
|
68
|
+
return unwrap(await autocomplete({
|
|
69
|
+
message: options.message,
|
|
70
|
+
options: toOptions(options.choices),
|
|
71
|
+
// Search a list by any part of a name or hint, rather than only by
|
|
72
|
+
// the label, which is all clack matches for itself.
|
|
73
|
+
filter: searchChoices,
|
|
74
|
+
output,
|
|
75
|
+
}));
|
|
76
|
+
};
|
|
77
|
+
export const promptAutocompleteMultiselect = async (options) => {
|
|
78
|
+
ensureInteractive();
|
|
79
|
+
return unwrap(await autocompleteMultiselect({
|
|
80
|
+
message: options.message,
|
|
81
|
+
options: toOptions(options.choices),
|
|
82
|
+
filter: searchChoices,
|
|
83
|
+
output,
|
|
84
|
+
}));
|
|
32
85
|
};
|
|
33
86
|
/**
|
|
34
|
-
*
|
|
35
|
-
* case insensitively against the
|
|
87
|
+
* Match a choice by every whitespace separated term of the input, matched
|
|
88
|
+
* case insensitively against the label and the hint.
|
|
36
89
|
*/
|
|
37
|
-
export const searchChoices =
|
|
90
|
+
export const searchChoices = (input, choice) => {
|
|
38
91
|
const terms = input
|
|
39
92
|
.toLowerCase()
|
|
40
93
|
.split(/\s+/)
|
|
41
94
|
.filter((term) => term.length > 0);
|
|
42
95
|
if (terms.length === 0)
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return terms.every((term) => searchable.includes(term));
|
|
49
|
-
});
|
|
96
|
+
return true;
|
|
97
|
+
const searchable = `${choice.label ?? ''} ${choice.hint ?? ''}`
|
|
98
|
+
.toLowerCase()
|
|
99
|
+
.trim();
|
|
100
|
+
return terms.every((term) => searchable.includes(term));
|
|
50
101
|
};
|
|
51
102
|
//# sourceMappingURL=prompt.js.map
|
package/lib/util/prompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/lib/util/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/lib/util/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,OAAO,EACP,QAAQ,EAER,MAAM,EACN,IAAI,GACL,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAEnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAY,EAAE,CACrC,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAA;AAE/D,8EAA8E;AAC9E,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C;QACE,KAAK,CAAC,WAAW,CAAC,CAAA;IACpB,CAAC;CACF;AAQD,MAAM,iBAAiB,GAAG,GAAS,EAAE;IACnC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,mBAAmB,CAC3B,uFAAuF,CACxF,CAAA;IACH,CAAC;AACH,CAAC,CAAA;AAED,MAAM,MAAM,GAAG,CAAQ,KAAqB,EAAS,EAAE;IACrD,IAAI,QAAQ,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,oBAAoB,EAAE,CAAA;IACrD,OAAO,KAAc,CAAA;AACvB,CAAC,CAAA;AAED,uEAAuE;AACvE,yDAAyD;AACzD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;AAE7B,MAAM,SAAS,GAAG,CAChB,OAAmC,EACb,EAAE,CACxB,OAAO,CAAC,GAAG,CACT,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CACzB,CAAC,IAAI,KA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I,EAAE,IAAI,MAAM,CAAC,IAAI,IAAI,EAAE,EAAE;SAC5D,WAAW,EAAE;SACb,IAAI,EAAE,CAAA;IACT,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;AACzD,CAAC,CAAA"}
|
package/lib/version.d.ts
CHANGED
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seamapi/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "A command-line interface (CLI) for interacting with the Seam API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
}
|
|
93
93
|
},
|
|
94
94
|
"dependencies": {
|
|
95
|
+
"@clack/prompts": "^1.7.0",
|
|
95
96
|
"@seamapi/blueprint": "1.2.0",
|
|
96
97
|
"@seamapi/http": "2.2.0",
|
|
97
98
|
"@seamapi/wizard": "0.5.2",
|
|
@@ -102,7 +103,6 @@
|
|
|
102
103
|
"minimist": "^1.2.8",
|
|
103
104
|
"nanospinner": "^1.2.2",
|
|
104
105
|
"open": "^11.0.0",
|
|
105
|
-
"prompts": "^2.4.2",
|
|
106
106
|
"tar": "^7.5.22"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
@@ -110,7 +110,6 @@
|
|
|
110
110
|
"@types/command-line-usage": "^5.0.4",
|
|
111
111
|
"@types/minimist": "^1.2.5",
|
|
112
112
|
"@types/node": "^24.10.9",
|
|
113
|
-
"@types/prompts": "^2.4.9",
|
|
114
113
|
"@vitest/coverage-v8": "^4.1.10",
|
|
115
114
|
"concurrently": "^10.0.4",
|
|
116
115
|
"del-cli": "^7.0.0",
|
package/src/bin/cli.ts
CHANGED
|
@@ -49,7 +49,11 @@ import {
|
|
|
49
49
|
toParameterName,
|
|
50
50
|
UsageError,
|
|
51
51
|
} from 'lib/util/cli-args.js'
|
|
52
|
-
import {
|
|
52
|
+
import {
|
|
53
|
+
canPrompt,
|
|
54
|
+
PromptCancelledError,
|
|
55
|
+
promptConfirm,
|
|
56
|
+
} from 'lib/util/prompt.js'
|
|
53
57
|
import { readStdinJson } from 'lib/util/read-stdin-json.js'
|
|
54
58
|
import { RequestSeamApi } from 'lib/util/request-seam-api.js'
|
|
55
59
|
import { validateToken } from 'lib/validate-token.js'
|
|
@@ -406,10 +410,9 @@ const handleConnectWebviewResponse = async (
|
|
|
406
410
|
interactivity !== 'non-interactive' &&
|
|
407
411
|
process.env['INSIDE_WEB_BROWSER'] !== '1'
|
|
408
412
|
) {
|
|
409
|
-
const
|
|
410
|
-
type: 'confirm',
|
|
411
|
-
name: 'action',
|
|
413
|
+
const action = await promptConfirm({
|
|
412
414
|
message: 'Would you like to open the webview in your browser?',
|
|
415
|
+
initialValue: false,
|
|
413
416
|
})
|
|
414
417
|
|
|
415
418
|
if (action) {
|
|
@@ -458,6 +461,11 @@ run(process.argv.slice(2)).catch((e: unknown) => {
|
|
|
458
461
|
return
|
|
459
462
|
}
|
|
460
463
|
|
|
464
|
+
if (e instanceof PromptCancelledError) {
|
|
465
|
+
output.error(chalk.gray(e.message))
|
|
466
|
+
return
|
|
467
|
+
}
|
|
468
|
+
|
|
461
469
|
const error = e instanceof Error ? e : new Error(String(e))
|
|
462
470
|
output.error(chalk.red(`CLI Error: ${error.message}`))
|
|
463
471
|
if (error.stack != null) output.error(chalk.gray(error.stack))
|
|
@@ -2,18 +2,16 @@ import type { ActionAttemptsGetResponse } from '@seamapi/http/connect'
|
|
|
2
2
|
|
|
3
3
|
import { getSeam } from './get-seam.js'
|
|
4
4
|
import { getOutput } from './output/get-output.js'
|
|
5
|
-
import {
|
|
5
|
+
import { promptConfirm } from './util/prompt.js'
|
|
6
6
|
import { withLoading } from './util/with-loading.js'
|
|
7
7
|
|
|
8
8
|
export const interactForActionAttemptPoll = async (
|
|
9
9
|
actionAttempt: ActionAttemptsGetResponse['action_attempt'],
|
|
10
10
|
) => {
|
|
11
11
|
if (actionAttempt.status === 'pending') {
|
|
12
|
-
const
|
|
13
|
-
name: 'pollForActionAttempt',
|
|
12
|
+
const pollForActionAttempt = await promptConfirm({
|
|
14
13
|
message: "Would you like to poll the action attempt until it's ready?",
|
|
15
|
-
|
|
16
|
-
initial: true,
|
|
14
|
+
initialValue: true,
|
|
17
15
|
active: 'yes',
|
|
18
16
|
inactive: 'no',
|
|
19
17
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getOutput } from './output/get-output.js'
|
|
2
|
-
import {
|
|
2
|
+
import { promptNumber, promptSelect, promptText } from './util/prompt.js'
|
|
3
3
|
|
|
4
4
|
export const interactForArray = async (
|
|
5
5
|
array: string[],
|
|
@@ -23,39 +23,31 @@ export const interactForArray = async (
|
|
|
23
23
|
do {
|
|
24
24
|
displayList()
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
type: 'select',
|
|
28
|
-
name: 'action',
|
|
26
|
+
action = await promptSelect({
|
|
29
27
|
message: 'Choose an action:',
|
|
30
28
|
choices: [
|
|
31
|
-
{
|
|
32
|
-
{
|
|
33
|
-
{
|
|
29
|
+
{ label: 'Add an item', value: 'add' },
|
|
30
|
+
{ label: 'Remove an item', value: 'remove' },
|
|
31
|
+
{ label: 'Finish editing', value: 'done' },
|
|
34
32
|
],
|
|
35
33
|
})
|
|
36
34
|
|
|
37
|
-
action = response.action
|
|
38
|
-
|
|
39
35
|
if (action === 'add') {
|
|
40
|
-
const
|
|
41
|
-
type: 'text',
|
|
42
|
-
name: 'newItem',
|
|
36
|
+
const newItem = await promptText({
|
|
43
37
|
message: 'Enter the new item:',
|
|
44
38
|
})
|
|
45
39
|
if (newItem) {
|
|
46
40
|
updatedArray.push(newItem)
|
|
47
41
|
}
|
|
48
42
|
} else if (action === 'remove') {
|
|
49
|
-
const
|
|
50
|
-
type: 'number',
|
|
51
|
-
name: 'index',
|
|
43
|
+
const index = await promptNumber({
|
|
52
44
|
message: 'Enter the index of the item to remove:',
|
|
53
45
|
validate: (value) =>
|
|
54
|
-
value > 0 && value <= updatedArray.length
|
|
46
|
+
value > 0 && value <= updatedArray.length
|
|
47
|
+
? undefined
|
|
48
|
+
: 'Invalid index',
|
|
55
49
|
})
|
|
56
|
-
|
|
57
|
-
updatedArray.splice(index - 1, 1)
|
|
58
|
-
}
|
|
50
|
+
updatedArray.splice(index - 1, 1)
|
|
59
51
|
}
|
|
60
52
|
} while (action !== 'done')
|
|
61
53
|
|