icore Node.js
On this page

Command-line arguments

icore receives process.argv.slice(2) and separates command names and positional arguments from options. The selected command's schema determines how values are read and checked. Four forms are supported.

  • Long options --name value and --name=value.
  • Boolean flags --flag and --no-flag.
  • Short names declared in the schema, such as -f and -n value.
  • The -- terminator before positional arguments.

Long options

Pass the name and value as separate arguments.

Shell
node dist/cli.js users get --name Alice

Parsing yields this value.

JSON
{
  "name": "Alice"
}

An equals sign gives the same result.

Shell
node dist/cli.js users get --name=Alice

String and number options can take a value that begins with -. In this example the schema declares label as type: 'string' and limit as type: 'number'.

Shell
node dist/cli.js search --label -draft --limit -1

Boolean flags

The flag name sets the option to true.

Shell
node dist/cli.js reports list --archived

--no-<name> sets a known boolean option to false when its schema allows negation.

Shell
node dist/cli.js reports list --no-archived

An explicit value after an equals sign is rejected.

Shell
node dist/cli.js reports list --archived=true
node dist/cli.js reports list --archived=false

As a separate argument, the value leaves archived set to true and false remains positional.

Shell
node dist/cli.js reports list --archived false

Short names

Assign -v to --verbose in the option schema.

TypeScript
const options = {
  verbose: {
    type: 'boolean',
    alias: 'v'
  }
} as const;

The user calls the short form.

Shell
node dist/cli.js users get -v

The handler receives the value under the long name.

JSON
{
  "verbose": true
}

For string and number options, put the short name and its value in separate arguments.

TypeScript
const options = {
  name: {
    type: 'string',
    alias: 'n'
  },
  limit: {
    type: 'number',
    alias: 'l'
  }
} as const;
Shell
node dist/cli.js users get -n Alice -l 10
JSON
{
  "name": "Alice",
  "limit": 10
}

A value attached directly to the name is rejected.

Shell
node dist/cli.js users get -nAlice

Pass each flag separately. A group of short names in one argument is rejected.

Shell
node dist/cli.js users get -abc

Option terminator

-- stops option parsing and is removed from the result. All following arguments are positional, even when they start with -.

Shell
node dist/cli.js search -- --name Alice -v

The command name is followed by the positional arguments --name, Alice, and -v.

Duplicate options

Pass each option once. A repeated long name is rejected.

Shell
node dist/cli.js users get --format json --format table

Passing both the long and short name of one option is also a duplicate.

Shell
node dist/cli.js users get --verbose -v

Unknown options

An unknown long option raises a validation error.

Shell
node dist/cli.js users get --unknown value

An undeclared short argument remains positional. Validation rejects it when the command forbids extra positional arguments.

See the CLI patterns for global flags, shared options, and renaming.