rabbit_rabbit
rabbit_rabbit8mo ago

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
deno task db:migrate:latest
IS_TEST=true deno task db:migrate:latest
I want to write
deno task db:migrate:local latest
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"
}
}
{
"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"
$ 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!
2 Replies
marvinh.
marvinh.8mo ago
yeah parameters to tasks are merely appended at the end of the command. You could write a simple cli tool that shells out to the different commands or runs them directly in the same process
rabbit_rabbit
rabbit_rabbit8mo ago
Makes sense — I'll have it call out to a shell script. Thanks!