Fix CLI arg routing and desktop install links
This commit is contained in:
@@ -18,6 +18,31 @@ export function isPathLikeArg(arg: string): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
export function isExistingDirectoryArg(arg: string): boolean {
|
||||
const absolutePath = path.resolve(expandUserPath(arg));
|
||||
|
||||
if (!existsSync(absolutePath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return statSync(absolutePath).isDirectory();
|
||||
}
|
||||
|
||||
export function shouldOpenProjectArg(input: {
|
||||
arg: string;
|
||||
knownCommands: ReadonlySet<string>;
|
||||
}): boolean {
|
||||
if (input.arg.startsWith("-")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input.knownCommands.has(input.arg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isPathLikeArg(input.arg) || isExistingDirectoryArg(input.arg);
|
||||
}
|
||||
|
||||
function expandUserPath(inputPath: string): string {
|
||||
if (inputPath === "~") {
|
||||
return homedir();
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { createCli } from "./cli.js";
|
||||
import { isPathLikeArg, openDesktopWithProject } from "./commands/open.js";
|
||||
import { openDesktopWithProject, shouldOpenProjectArg } from "./commands/open.js";
|
||||
|
||||
const program = createCli();
|
||||
const knownCommands = new Set(program.commands.map((command) => command.name()));
|
||||
|
||||
const firstArg = process.argv[2];
|
||||
if (firstArg && isPathLikeArg(firstArg)) {
|
||||
if (firstArg && shouldOpenProjectArg({ arg: firstArg, knownCommands })) {
|
||||
await openDesktopWithProject(firstArg);
|
||||
} else {
|
||||
if (process.argv.length <= 2) {
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
#!/usr/bin/env npx zx
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir, mkdtemp } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { isPathLikeArg, openDesktopWithProject } from "../src/commands/open.ts";
|
||||
import {
|
||||
isExistingDirectoryArg,
|
||||
isPathLikeArg,
|
||||
openDesktopWithProject,
|
||||
shouldOpenProjectArg,
|
||||
} from "../src/commands/open.ts";
|
||||
|
||||
console.log("📋 Phase 32: Open Project CLI Tests\n");
|
||||
|
||||
@@ -16,6 +22,25 @@ assert.equal(isPathLikeArg("run"), false);
|
||||
assert.equal(isPathLikeArg("foo"), false);
|
||||
console.log(" ✅ path-like detection matches the expected prefixes");
|
||||
|
||||
console.log(" Testing existing directory detection and command precedence...");
|
||||
const existingProject = join(await mkdtemp(join(tmpdir(), "paseo-open-project-")), "project");
|
||||
await mkdir(existingProject);
|
||||
const originalCwd = process.cwd();
|
||||
process.chdir(join(existingProject, ".."));
|
||||
|
||||
assert.equal(isExistingDirectoryArg("project"), true);
|
||||
assert.equal(
|
||||
shouldOpenProjectArg({ arg: "project", knownCommands: new Set(["run", "status"]) }),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
shouldOpenProjectArg({ arg: "run", knownCommands: new Set(["run", "status"]) }),
|
||||
false,
|
||||
);
|
||||
|
||||
process.chdir(originalCwd);
|
||||
console.log(" ✅ existing directories open as projects, but known commands still win");
|
||||
|
||||
console.log(" Testing nonexistent project path errors...");
|
||||
const missingProject = join(tmpdir(), "paseo-open-project-missing");
|
||||
const originalWrite = process.stderr.write.bind(process.stderr);
|
||||
|
||||
Reference in New Issue
Block a user