CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
uninstall.ts72 linesDownload Raw Back to extensions
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6 7import type { CommandModule } from 'yargs';8import { getErrorMessage } from '../../utils/errors.js';9import { writeStdoutLine, writeStderrLine } from '../../utils/stdioHelpers.js';10import { ExtensionManager } from '@qwen-code/qwen-code-core';11import {12  requestConsentNonInteractive,13  requestConsentOrFail,14} from './consent.js';15import { isWorkspaceTrusted } from '../../config/trustedFolders.js';16import { loadSettings } from '../../config/settings.js';17import { t, getCurrentLanguage } from '../../i18n/index.js';18 19interface UninstallArgs {20  name: string; // can be extension name or source URL.21}22 23export async function handleUninstall(args: UninstallArgs) {24  try {25    const workspaceDir = process.cwd();26    const extensionManager = new ExtensionManager({27      workspaceDir,28      locale: getCurrentLanguage(),29      requestConsent: requestConsentOrFail.bind(30        null,31        requestConsentNonInteractive,32      ),33      isWorkspaceTrusted:34        isWorkspaceTrusted(loadSettings(workspaceDir).merged).isTrusted ?? true,35    });36    await extensionManager.refreshCache();37    await extensionManager.uninstallExtension(args.name, false);38    writeStdoutLine(39      t('Extension "{{name}}" successfully uninstalled.', { name: args.name }),40    );41  } catch (error) {42    writeStderrLine(getErrorMessage(error));43    process.exit(1);44  }45}46 47export const uninstallCommand: CommandModule = {48  command: 'uninstall <name>',49  describe: t('Uninstalls an extension.'),50  builder: (yargs) =>51    yargs52      .positional('name', {53        describe: t('The name or source path of the extension to uninstall.'),54        type: 'string',55      })56      .check((argv) => {57        if (!argv.name) {58          throw new Error(59            t(60              'Please include the name of the extension to uninstall as a positional argument.',61            ),62          );63        }64        return true;65      }),66  handler: async (argv) => {67    await handleUninstall({68      name: argv['name'] as string,69    });70  },71};72 
basant307/AI_Governance_Project · CoolFace