update python.ts

This commit is contained in:
2026-02-12 21:14:39 +08:00
parent e46b17315b
commit 3ffe4a8ae3
3 changed files with 39 additions and 7 deletions

View File

@@ -94,6 +94,7 @@ function handleHelp(_args: string[]) {
[green]python.ts[/green] [bold]python[/bold] - management python version [yellow]\\[alias: py, ver, version][/yellow]
[green]python.ts[/green] [bold]add-python[/bold] - add python version [yellow]\\[alias: add-py][/yellow]
[green]python.ts[/green] [bold]env[/bold] - management python virtual environment [yellow]\\[alias: env][/yellow]
[green]python.ts[/green] [bold]run[/bold] - run python [yellow]\\[alias: exec][/yellow]
[green]python.ts[/green] [bold]add-venv[/bold] - add python virtual environment [yellow]\\[alias: add-env][/yellow]
[green]python.ts[/green] [bold]remove-venv[/bold] - remove python virtual environment [yellow]\\[alias: rm-venv, rm-env][/yellow]
[green]python.ts[/green] [bold]active-venv[/bold] - active python virtual environment [yellow]\\[alias: active, active-env][/yellow]`;
@@ -465,6 +466,33 @@ source <(python.rs active[-venv] test-env)`);
console.log(pythonVenvActiveFileContent);
}
async function handleRun(args: string[]) {
const flags = parseArgs(args, {
boolean: ["help"],
string: ["version"],
});
if (flags.help) {
console.log(`Help massage for run
python.ts run --ver 3.10`);
return;
}
if (!flags.version) {
log.error("Version missing");
return;
}
const pythonConfig = await loadPythonConfig();
const pythonVersion = findPythonVersion(pythonConfig, flags.version);
if (!pythonVersion) {
throw `Python version: ${pythonVersion} not found`;
}
const pythonPath = pythonVersion.path;
log.debug(`Python path: ${pythonPath}`);
await execCommandShell(pythonPath, flags._);
}
async function main() {
const args = Deno.args;
@@ -509,6 +537,10 @@ async function main() {
case "active-venv":
await handleActiveVenv(remainingArgs);
break;
case "run":
case "exec":
await handleRun(remainingArgs);
break;
default:
log.error(`Unknown subcommand: ${subcommand}`);
break;
@@ -526,5 +558,5 @@ Deno.test("versionSort", () => {
assertEquals(["3.7", "3.10", "3.10.1", "3.11"], versions2);
});
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260205T232313+08:00.MEQCIHC9xGfzR6iiMjJjpPAc
// lJ3lyEUT5a+7qLUml7HcEV6WAiA7ZZ5yUdtfk0J0zQBnam92VOHjYvH2sLrVBI/88vB1sQ==
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260212T211313+08:00.MEYCIQDlYhjo1HOebT1rkqHy
// K96Iyw3/yinAYiNtjW3NdmgsvAIhAO301xuVm04GArN2Q8WRboOCkhunlyRbMXGBkR3mM2EJ