The Double-Dash Delimiter

|2 min read

The double-dash delimiter (aka option terminator) allows you to pass arbitrary commands to a CLI program. The arguments passed after the -- are treated as arguments and not flag of a program even if it begins with a hyphen.

For example, if you would like to delete a folder called -r, the rm -r command would be invalid because -r is an option for the rm command. Therefore, to successfully delete the folder you can separate the command and option with the double-dash like so:

rm -- -r

In this case, it separates/ terminates/ delimits rm’s options from its values.

Options passed after the -- can be provided multiple times and in any order.

User defined arguments

Disclaimer: The following example is specific to JavaScript/ Node.js but could also apply to other languages/ runtimes.

Prisma 4.15.0 added support for custom arguments for the prisma db seed command, which led me to the interesting discovery of what a double-dash/ option terminator is, and it’s possibilities.

If you’re building a CLI program you could use the double-dash delimiter to allow users to “extend” your program and pass their own arguments, separated by --.

For example, with the prisma db seed command, you could define your own arguments to to partially seed data in specific tables by passing a --tables option as follows:

npx prisma db seed -- --tables=user,post

… and within the seed file, you could parse the --tables option’s values as follows:

import { parseArgs } from 'node:util'

const options = {
  tables: { type: "string" },
}

async function main() {
  const { values: { tables }, } = parseArgs({ options })

  tables.split(",").forEach(table => {
    /**  logic to seed tables defined here */
  });
}

main()

Other libraries such as vitest and eslint, among many others, also provide the double-dash.

This is only one of many examples you could use custom arguments. Feel free to explore the different use-cases you think of and share them with us. I would be particularly interested in what you build. 🙂

Going further

If you’re interested in reading further, I would recommend the following: