diff --git a/src/hooks/useFlags.ts b/src/hooks/useFlags.ts index d18ebdea..02e1b78b 100644 --- a/src/hooks/useFlags.ts +++ b/src/hooks/useFlags.ts @@ -4,6 +4,7 @@ import { isNumber } from "is_what" import { set_tmp } from "path" import { usePrefix } from "hooks" import Path from "path" +import { lstatSync } from "https://deno.land/std@0.165.0/node/fs.ts"; // doing here as this is the only file all our scripts import set_tmp(usePrefix().join('tea.xyz/tmp')) @@ -63,10 +64,18 @@ export type Args = { export function useArgs(args: string[], arg0: string): [Args, Flags & ConvenienceFlags] { if (flags) throw new Error("contract-violated") - if (/(.+\/|^)tea_(.+)$/.test(arg0)) { - args = [...args] // args is usually the immutable `Deno.args` - const match = arg0.match(/tea_(.+)$/)! - args.unshift("-X", match[1]) + if (lstatSync(arg0).isSymbolicLink()) { + const arg0_basename = new Path(arg0).basename() + if (arg0_basename != "tea") { + args = [...args] // args is usually the immutable `Deno.args` + if (/^tea_([^\/]+)$/.test(arg0_basename)) { + //TODO apply non-magic mode + const match = arg0_basename.match(/^tea_([^\/]+)$/)! + args.unshift("-X", match[1]) + } else { + args.unshift("-X", arg0_basename) + } + } } const rv: Args = {