Fix extensions enablement bugs (#8797)

This commit is contained in:
christine betts
2025-09-19 11:43:39 -04:00
committed by GitHub
parent 6e4236bf76
commit fa8cea170a
5 changed files with 353 additions and 83 deletions

View File

@@ -11,12 +11,16 @@ import { getErrorMessage } from '../../utils/errors.js';
interface DisableArgs {
name: string;
scope: SettingScope;
scope?: string;
}
export function handleDisable(args: DisableArgs) {
try {
disableExtension(args.name, args.scope);
if (args.scope?.toLowerCase() === 'workspace') {
disableExtension(args.name, SettingScope.Workspace);
} else {
disableExtension(args.name, SettingScope.User);
}
console.log(
`Extension "${args.name}" successfully disabled for scope "${args.scope}".`,
);
@@ -39,13 +43,28 @@ export const disableCommand: CommandModule = {
describe: 'The scope to disable the extenison in.',
type: 'string',
default: SettingScope.User,
choices: [SettingScope.User, SettingScope.Workspace],
})
.check((_argv) => true),
.check((argv) => {
if (
argv.scope &&
!Object.values(SettingScope)
.map((s) => s.toLowerCase())
.includes((argv.scope as string).toLowerCase())
) {
throw new Error(
`Invalid scope: ${argv.scope}. Please use one of ${Object.values(
SettingScope,
)
.map((s) => s.toLowerCase())
.join(', ')}.`,
);
}
return true;
}),
handler: (argv) => {
handleDisable({
name: argv['name'] as string,
scope: argv['scope'] as SettingScope,
scope: argv['scope'] as string,
});
},
};

View File

@@ -11,13 +11,16 @@ import { SettingScope } from '../../config/settings.js';
interface EnableArgs {
name: string;
scope?: SettingScope;
scope?: string;
}
export function handleEnable(args: EnableArgs) {
try {
const scope = args.scope ? args.scope : SettingScope.User;
enableExtension(args.name, scope);
if (args.scope?.toLowerCase() === 'workspace') {
enableExtension(args.name, SettingScope.Workspace);
} else {
enableExtension(args.name, SettingScope.User);
}
if (args.scope) {
console.log(
`Extension "${args.name}" successfully enabled for scope "${args.scope}".`,
@@ -45,13 +48,28 @@ export const enableCommand: CommandModule = {
describe:
'The scope to enable the extenison in. If not set, will be enabled in all scopes.',
type: 'string',
choices: [SettingScope.User, SettingScope.Workspace],
})
.check((_argv) => true),
.check((argv) => {
if (
argv.scope &&
!Object.values(SettingScope)
.map((s) => s.toLowerCase())
.includes((argv.scope as string).toLowerCase())
) {
throw new Error(
`Invalid scope: ${argv.scope}. Please use one of ${Object.values(
SettingScope,
)
.map((s) => s.toLowerCase())
.join(', ')}.`,
);
}
return true;
}),
handler: (argv) => {
handleEnable({
name: argv['name'] as string,
scope: argv['scope'] as SettingScope,
scope: argv['scope'] as string,
});
},
};