Skip to content

Commit a09bc4e

Browse files
committed
feat(cli): make CLI not interactive in agentic context (#2319)
Synced from monorepo@abf8f7b089b6c55e6ba278675a574a735bc680b1
1 parent 3cb7683 commit a09bc4e

36 files changed

Lines changed: 149 additions & 103 deletions

.sync-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
055633d07c494cc7355400f5ec7dfc86997870ff
1+
abf8f7b089b6c55e6ba278675a574a735bc680b1

pnpm-lock.yaml

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/auth/login.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ async function resolveCustomConfig(
2323
context: LocalContext,
2424
flags: Pick<Flags, 'custom-issuer' | 'custom-api-base-url' | 'custom-client-id' | 'custom-client-secret'>
2525
): Promise<CustomConfig | undefined> {
26-
const issuer = await context.enquirer.inputPrompt(context.isCI, 'Issuer URL', { flag: flags['custom-issuer'] });
27-
const apiBaseUrl = await context.enquirer.inputPrompt(context.isCI, 'API base URL', {
26+
const issuer = await context.enquirer.inputPrompt(context.isInteractive, 'Issuer URL', {
27+
flag: flags['custom-issuer']
28+
});
29+
const apiBaseUrl = await context.enquirer.inputPrompt(context.isInteractive, 'API base URL', {
2830
flag: flags['custom-api-base-url']
2931
});
30-
const clientSecret = await context.enquirer.inputPrompt(context.isCI, 'Client secret', {
32+
const clientSecret = await context.enquirer.inputPrompt(context.isInteractive, 'Client secret', {
3133
flag: flags['custom-client-secret']
3234
});
3335

src/commands/auth/logout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function implementation(this: LocalContext, { profile: profileFlag,
2020

2121
if (!yes) {
2222
const confirmFromPrompt = await this.enquirer.confirmPrompt(
23-
this.isCI,
23+
this.isInteractive,
2424
`Do you want to log out of the profile ${profile}`
2525
);
2626
if (!confirmFromPrompt) {

src/commands/auth/switch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function implementation(this: LocalContext, {}: Flags, profile?: st
2525
message: profile === activeProfile ? `${profile} (current)` : profile
2626
}));
2727

28-
selectedProfile = await this.enquirer.selectPrompt(this.isCI, 'Select profile to switch to:', choices);
28+
selectedProfile = await this.enquirer.selectPrompt(this.isInteractive, 'Select profile to switch to:', choices);
2929

3030
if (!selectedProfile) {
3131
console.log('No profile selected');

src/commands/branch/create.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ export async function getRegion(context: LocalContext, flags: { region?: string
146146

147147
if (!flags.region) {
148148
const regionChoices = groupAndSortRegions(regions.regions);
149-
const region = (await context.enquirer.selectPrompt(context.isCI, title, regionChoices)) as Flags['region'];
149+
const region = (await context.enquirer.selectPrompt(
150+
context.isInteractive,
151+
title,
152+
regionChoices
153+
)) as Flags['region'];
150154
invariant(region, `Region should exist`);
151155
return region;
152156
}
@@ -171,7 +175,11 @@ export async function getReplicas(context: LocalContext, flags: { replicas?: str
171175
}
172176

173177
if (!flags.replicas) {
174-
const replicas = (await context.enquirer.selectPrompt(context.isCI, title, replicaChoices)) as Flags['replicas'];
178+
const replicas = (await context.enquirer.selectPrompt(
179+
context.isInteractive,
180+
title,
181+
replicaChoices
182+
)) as Flags['replicas'];
175183
invariant(replicas, `Replicas should exist`);
176184
return replicas;
177185
}
@@ -203,7 +211,7 @@ export async function getInstanceType(
203211

204212
if (!flags['instance-type']) {
205213
const instanceType = (await context.enquirer.selectPrompt(
206-
context.isCI,
214+
context.isInteractive,
207215
title,
208216
instanceChoices
209217
)) as Flags['instance-type'];
@@ -254,7 +262,9 @@ export async function getImage(
254262
const defaultIndex = sortedImages.findIndex((image) => image.name.startsWith('postgres:'));
255263
const initial = defaultIndex >= 0 ? defaultIndex : 0;
256264

257-
const image = (await context.enquirer.selectPrompt(context.isCI, title, imageChoices, { initial })) as string;
265+
const image = (await context.enquirer.selectPrompt(context.isInteractive, title, imageChoices, {
266+
initial
267+
})) as string;
258268
invariant(image, `Postgres version should exist`);
259269
return image;
260270
} catch {
@@ -278,7 +288,9 @@ export async function implementation(this: LocalContext, flags: Flags) {
278288
const scaleToZeroChild = project.configuration.scaleToZero.childBranches.enabled;
279289
const inactivityPeriodChild = project.configuration.scaleToZero.childBranches.inactivityPeriodMinutes;
280290

281-
const branchName = await this.enquirer.inputPrompt(this.isCI, 'Please enter the branch name', { flag: flags.name });
291+
const branchName = await this.enquirer.inputPrompt(this.isInteractive, 'Please enter the branch name', {
292+
flag: flags.name
293+
});
282294
if (!branchName) {
283295
this.process.stderr.write(chalk.red(`Expected input for flag --name`));
284296
this.process.exit(1);

src/commands/branch/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function implementation(this: LocalContext, flags: Flags, branchNam
3232

3333
if (!flags.yes) {
3434
const confirmFromPrompt = await this.enquirer.confirmPrompt(
35-
this.isCI,
35+
this.isInteractive,
3636
`Are you sure you want to delete the branch ${branchToDelete.name} with id ${branchToDelete.id}?`
3737
);
3838
if (!confirmFromPrompt) {

src/commands/branch/rotate-password.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function implementation(this: LocalContext, flags: Flags, branchNam
3535

3636
if (!flags.yes) {
3737
const confirmed = await this.enquirer.confirmPrompt(
38-
this.isCI,
38+
this.isInteractive,
3939
`Rotate the password for PostgreSQL user ${username} on branch ${branch.name}? Existing connections will not be affected, but any new connections will need to use the new credentials.`
4040
);
4141
if (!confirmed) {

src/commands/branch/set.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,45 +113,45 @@ export async function implementation(this: LocalContext, flags: Flags, fieldArg:
113113
if (!value) {
114114
value = await match(field)
115115
.with('name', async () => {
116-
return await this.enquirer.inputPrompt(this.isCI, 'Please enter the new branch name');
116+
return await this.enquirer.inputPrompt(this.isInteractive, 'Please enter the new branch name');
117117
})
118118
.with('replicas', async () => {
119119
return await this.enquirer.selectPrompt(
120-
this.isCI,
120+
this.isInteractive,
121121
'Please select number of replicas for the branch',
122122
replicaChoices
123123
);
124124
})
125125
.with('instance-type', async () => {
126126
return await this.enquirer.selectPrompt(
127-
this.isCI,
127+
this.isInteractive,
128128
'Please select the type of instance for this branch',
129129
instanceChoices
130130
);
131131
})
132132
.with('hibernate', async () => {
133-
return await this.enquirer.selectPrompt(this.isCI, 'Please select hibernation status for the branch', [
133+
return await this.enquirer.selectPrompt(this.isInteractive, 'Please select hibernation status for the branch', [
134134
{ name: 'true', message: 'Hibernated' },
135135
{ name: 'false', message: 'Not hibernated' }
136136
]);
137137
})
138138
.with('scale-to-zero', async () => {
139139
return await this.enquirer.selectPrompt(
140-
this.isCI,
140+
this.isInteractive,
141141
`Please select scale to zero status for the branch (current: ${defaultScaleToZero ? 'Enabled' : 'Disabled'})`,
142142
[...scaleToZeroChoices]
143143
);
144144
})
145145
.with('inactivity-period', async () => {
146146
return await this.enquirer.selectPrompt(
147-
this.isCI,
147+
this.isInteractive,
148148
`Please select inactivity period for the branch (current: ${defaultInactivityPeriod} minutes)`,
149149
[...timeChoices]
150150
);
151151
})
152152
.with('postgres-version', async () => {
153153
return await this.enquirer.selectPrompt(
154-
this.isCI,
154+
this.isInteractive,
155155
`Please select the PostgreSQL version for this branch (current: ${branch.configuration.image})`,
156156
upgradeableImageChoices
157157
);

src/commands/clone/config.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type Flags = {
6363
};
6464

6565
export async function implementation(this: LocalContext, flags: Flags) {
66-
if (this.isCI && flags.mode !== 'auto') {
66+
if (!this.isInteractive && flags.mode !== 'auto') {
6767
invariant(false, 'Only --mode `auto` is available in CI');
6868
}
6969
await checkBranchIsReachable(this, flags);
@@ -76,10 +76,14 @@ export async function implementation(this: LocalContext, flags: Flags) {
7676

7777
let validationMode: ValidationMode = 'strict';
7878
if (flags['validation-mode'] === 'prompt') {
79-
const validationModeResult = (await this.enquirer.selectPrompt(this.isCI, 'Do you want to anonymize data?', [
80-
{ name: 'strict', message: 'Yes' },
81-
{ name: 'relaxed', message: 'No' }
82-
])) as ValidationMode;
79+
const validationModeResult = (await this.enquirer.selectPrompt(
80+
this.isInteractive,
81+
'Do you want to anonymize data?',
82+
[
83+
{ name: 'strict', message: 'Yes' },
84+
{ name: 'relaxed', message: 'No' }
85+
]
86+
)) as ValidationMode;
8387
if (validationModeResult) {
8488
validationMode = validationModeResult;
8589
}

0 commit comments

Comments
 (0)