DenoDDeno
Powered by
rabbit_rabbitR
Deno•3y 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
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!
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

[VSCodium] - Deno task list
©TriMoon™©©TriMoon™ / help
13mo ago
RUN deno task in Dockerfile
vanpetVvanpet / help
3y ago
Arguments ignored in Deno Deploy EA
PolarisPPolaris / help
7mo ago