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) {
|
||||
|
||||
Reference in New Issue
Block a user