handle remove venv
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
existsPath,
|
existsPath,
|
||||||
joinPath,
|
joinPath,
|
||||||
log,
|
log,
|
||||||
|
ProcessBar,
|
||||||
readFileToString,
|
readFileToString,
|
||||||
resolveFilename,
|
resolveFilename,
|
||||||
} from "https://global.hatter.ink/script/get/@16/deno-commons-mod.ts";
|
} from "https://global.hatter.ink/script/get/@16/deno-commons-mod.ts";
|
||||||
@@ -128,10 +129,11 @@ function handleHelp(_args: string[]) {
|
|||||||
help.push(
|
help.push(
|
||||||
`python.ts - Python version and virtual environment management tool
|
`python.ts - Python version and virtual environment management tool
|
||||||
|
|
||||||
python.ts python - management python version [alias: py]
|
python.ts python - management python version [alias: py]
|
||||||
python.ts add-python - add python version [alias: py]
|
python.ts add-python - add python version [alias: py]
|
||||||
python.ts venv - management python virtual environment
|
python.ts venv - management python virtual environment
|
||||||
python.ts add-venv - add python virtual environment`,
|
python.ts add-venv - add python virtual environment
|
||||||
|
python.ts remove-venv - remove python virtual environment`,
|
||||||
);
|
);
|
||||||
// source <(cat ~/.venv-python-3.13.5/bin/activate)
|
// source <(cat ~/.venv-python-3.13.5/bin/activate)
|
||||||
// source <(python.ts venv test1)
|
// source <(python.ts venv test1)
|
||||||
@@ -327,6 +329,54 @@ python.ts add-venv --version 3.10 --venv test-env`);
|
|||||||
await addVirtualEnv(flags.version, flags.venv);
|
await addVirtualEnv(flags.version, flags.venv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleRemoveVenv(args: string[]) {
|
||||||
|
const flags = parseArgs(args, {
|
||||||
|
boolean: ["help"],
|
||||||
|
string: ["venv"],
|
||||||
|
});
|
||||||
|
if (args.length === 0 || flags.help) {
|
||||||
|
console.log(`Help massage for remove-venv
|
||||||
|
|
||||||
|
python.ts remove-venv --venv test-env`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!flags.venv) {
|
||||||
|
log.error("Venv is missing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const pythonConfig = await loadPythonConfig();
|
||||||
|
const pythonVenvProfile = pythonConfig.profiles &&
|
||||||
|
pythonConfig.profiles[flags.venv];
|
||||||
|
if (!pythonVenvProfile) {
|
||||||
|
throw `Python venv not exists: ${flags.venv}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Pending remove virtual environment [PLEASE CONFIRM]: `,
|
||||||
|
pythonVenvProfile,
|
||||||
|
);
|
||||||
|
|
||||||
|
const yesOrNo = prompt("Please confirm (yes/no):");
|
||||||
|
if (yesOrNo === "yes" || yesOrNo === "y") {
|
||||||
|
// DO CONFIRM YES
|
||||||
|
// TODO
|
||||||
|
const path = pythonVenvProfile.path;
|
||||||
|
log.info(`Remove path: ${path}`);
|
||||||
|
|
||||||
|
await new ProcessBar(`Removing path ${path}`).call(async () => {
|
||||||
|
await Deno.remove(path, { recursive: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
delete pythonConfig.profiles[flags.venv];
|
||||||
|
await savePythonConfig(pythonConfig);
|
||||||
|
log.success(`Remove virtual environment: ${flags.venv}`);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`Your input '${yesOrNo}', skip remove the virtual environment`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const args = Deno.args;
|
const args = Deno.args;
|
||||||
|
|
||||||
@@ -356,6 +406,10 @@ async function main() {
|
|||||||
case "add-venv":
|
case "add-venv":
|
||||||
await handleAddVenv(remainingArgs);
|
await handleAddVenv(remainingArgs);
|
||||||
break;
|
break;
|
||||||
|
case "rm-venv":
|
||||||
|
case "remove-venv":
|
||||||
|
await handleRemoveVenv(remainingArgs);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
log.error(`Unknown subcommand: ${subcommand}`);
|
log.error(`Unknown subcommand: ${subcommand}`);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user