Skip to content

Commit

Permalink
fix: affected commands no longer clear flags first time through (#1242)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackDeRose authored Feb 7, 2022
1 parent 3e6183c commit 0a0faca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
49 changes: 34 additions & 15 deletions libs/vscode/tasks/src/lib/nx-task-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,7 @@ async function promptForAffectedFlags(target: string) {
const telemetry = getTelemetry();
telemetry.featureUsed('affected-cli');

let positional: string | undefined;
let command: string;

switch (target) {
case 'apps':
case 'libs':
case 'dep-graph':
command = `affected:${target}`;
break;
default:
command = 'affected';
positional = `--target=${target}`;
await selectFlags(`affected ${positional}`, AFFECTED_OPTIONS, 'nx');
}
const flags = await selectFlags(command, AFFECTED_OPTIONS, 'nx');
const { positional, command, flags } = await selectAffectedFlags(target);

if (flags !== undefined) {
const task = NxTask.create(
Expand All @@ -281,6 +267,39 @@ async function promptForAffectedFlags(target: string) {
}
}

/**
*
*/
async function selectAffectedFlags(target: string): Promise<{
command: string;
flags: string[] | undefined;
positional?: string;
}> {
switch (target) {
case 'apps':
case 'libs':
case 'dep-graph': {
const command = `affected:${target}`;
return {
command,
flags: await selectFlags(command, AFFECTED_OPTIONS, 'nx'),
};
}
default: {
const positional = `--target=${target}`;
return {
command: 'affected',
positional,
flags: await selectFlags(
`affected ${positional}`,
AFFECTED_OPTIONS,
'nx'
),
};
}
}
}

async function promptForRunMany() {
const telemetry = getTelemetry();
telemetry.featureUsed('affected-cli');
Expand Down
7 changes: 6 additions & 1 deletion libs/vscode/tasks/src/lib/select-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { Option } from '@nx-console/schema';
import { QuickPickItem, window } from 'vscode';
import { CliTaskFlagQuickPickItem } from './cli-task-flag-quick-pick-item';

/**
* Returns undefined if the user wants to cancel the command.
* Returns an empty array to run the command without flags.
* Returns an array populated with flags if the user provides them.
*/
export async function selectFlags(
command: string,
options: Option[],
Expand Down Expand Up @@ -83,7 +88,7 @@ function promptForFlagValue(flagToSet: CliTaskFlagQuickPickItem) {
} else if (flagToSet.option.enum && flagToSet.option.enum.length) {
return window.showQuickPick([...flagToSet.option.enum.map(String)], {
placeHolder,
canPickMany: flagToSet.option.type === 'array'
canPickMany: flagToSet.option.type === 'array',
});
} else {
return window.showInputBox({
Expand Down

0 comments on commit 0a0faca

Please sign in to comment.