Skip to content

A required object option shows as optional in --help #230

Open

Description

@FluteBlade

A required string field in the input schema gets an option like --name <string>, which trpc-cli makes mandatory. A required object field gets --contract [json] instead, written as an optional value, and its option is not made mandatory. Leaving it out is then caught only by the schema, not by Commander as a missing option:

import { createCli, os } from "trpc-cli";
import { z } from "zod";

const router = os.router({
  add: os
    .input(z.object({ name: z.string(), contract: z.object({ schema: z.record(z.string(), z.unknown()) }) }))
    .handler(({ input }) => input),
});
await createCli({ router }).run();
$ node cli.mjs add --help
  --name <string>
  --contract [json]  Object (json formatted); Required: ["schema"]
$ node cli.mjs add --name a
error: option '--contract [json]' is invalid. Invalid input: expected object, received undefined

In trpc-cli 0.17.1, an option's value name gets its brackets from bracketise (src/index.ts#L433): angle brackets for a required option, square ones otherwise. Strings, numbers, enums and untyped values go through it, but an object keeps [json], the value name every option starts with (#L467). Since only a flag with angle brackets is made mandatory (#L479), a required object option is neither shown nor enforced as required. Starting the value name from bracketise('json') instead of '[json]' would fix both.

Activity

  1. pullfrog commented on Oct 23, 2026

    @pullfrog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions