Skip to content

Commit

Permalink
Allow symlinks to tea to execute those commands (pkgxdev#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusviri authored Nov 26, 2022
1 parent d0de85c commit a8c499d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/hooks/useFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/node/fs.ts";

// doing here as this is the only file all our scripts import
set_tmp(usePrefix().join('tea.xyz/tmp'))
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit a8c499d

Please sign in to comment.