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

View File

@@ -189,11 +189,11 @@
},
"python.ts": {
"script_name": "python.ts",
"script_length": 16778,
"script_sha256": "1c3f140ed8071f45ae313a88b03bd281c0c314609f4b0e7f38d2b14e72f15f3e",
"script_length": 17681,
"script_sha256": "6335bdf69656d14d9bc4ffa6cd69f23c43763ebba912d3952940c8b8a6d0bda7",
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/python-ts/main.ts",
"publish_time": 1768236234264,
"update_time": 1770390206795
"update_time": 1770902071230
},
"random.ts": {
"script_name": "random.ts",

View File

@@ -6,8 +6,8 @@
},
"python-ts": {
"script_name": "python-ts",
"script_length": 16778,
"script_sha256": "1c3f140ed8071f45ae313a88b03bd281c0c314609f4b0e7f38d2b14e72f15f3e"
"script_length": 17681,
"script_sha256": "6335bdf69656d14d9bc4ffa6cd69f23c43763ebba912d3952940c8b8a6d0bda7"
},
"sigstore-verify-ts": {
"script_name": "sigstore-verify-ts",