rabbit_rabbitR
Deno3y ago
2 replies
rabbit_rabbit

positional arguments deno task

Can I use positional arguments in deno task?

I have a number of scripts that I frequently want to run commands against both a dev and test database. I currently control which I'm connecting to via an environment variable. So where I'd normally do

deno task db:migrate:latest
IS_TEST=true deno task db:migrate:latest


I want to write

deno task db:migrate:local latest


My attempt looks like so

{
  "tasks": {
    "db:migrate:up": "deno task run:trusted db/migrate.ts --up",
    "db:migrate:latest": "deno task run:trusted db/migrate.ts --latest",
    "db:migrate:down": "deno task run:trusted db/migrate.ts --down",
    "db:migrate:to": "deno task run:trusted db/migrate.ts --to",
    "db:migrate:wipe": "deno task run:trusted db/migrate.ts --wipe",
    "db:migrate:redo": "deno task run:trusted db/migrate.ts --down && deno task run:trusted db/migrate.ts --up",
    "db:migrate:redo:all": "deno task run:trusted db/migrate.ts --wipe && deno task run:trusted db/migrate.ts --latest",
    "db:migrate:local": "diff .env .env.local >/dev/null && deno task db:migrate:$1 && IS_TEST=true deno task db:migrate:$1"
  }
}


But the positional argument seems to just get appended on the end without interpolation

$ deno task db:migrate:local latest
Task db:migrate:local diff .env .env.local >/dev/null && deno task db:migrate:$1 && IS_TEST=true deno task db:migrate:$1 "latest"


Is this possible? Should I rethink this?

Thanks in advance!
Was this page helpful?