Skip to content

feat: support hidden args - #263

Open
danielroe wants to merge 2 commits into
mainfrom
feat/hidden-args
Open

feat: support hidden args#263
danielroe wants to merge 2 commits into
mainfrom
feat/hidden-args

Conversation

@danielroe

@danielroe danielroe commented Jul 26, 2026

Copy link
Copy Markdown
Member

similar to hidden subcommands, this allows us to hide args (which we might, for example, want to keep for backwards compatibility)

Summary by CodeRabbit

  • New Features
    • Added a hidden argument option to omit specific arguments from rendered usage/help output while keeping them parsed and usable.
  • Documentation
    • Updated the README “Common Options” table to document the new hidden behavior.
  • Bug Fixes
    • Ensured hidden boolean arguments (including negated forms) continue to parse correctly.
  • Tests
    • Added coverage for renderUsage skipping hidden arguments and confirmed parseArgs still reads values for hidden options.

@danielroe
danielroe requested a review from pi0 July 26, 2026 13:39
@danielroe danielroe changed the title feat(usage): support hidden args feat: support hidden args Jul 26, 2026
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an optional hidden argument flag, excludes hidden arguments from rendered usage output, documents the option, and verifies that hidden arguments continue to parse normally.

Changes

Hidden arguments

Layer / File(s) Summary
Hidden argument contract
src/types.ts, README.md
Adds the optional hidden property to argument definitions, excludes it from positional definitions, and documents that hidden arguments remain parseable but are omitted from usage output.
Hidden argument rendering and parsing
src/usage.ts, test/usage.test.ts
Skips hidden arguments during usage generation and tests rendering exclusion, normal parsing, and boolean negation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • unjs/citty#198: Changes the same renderUsage argument-processing logic.

Suggested reviewers: pi0

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding support for hidden arguments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/hidden-args

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/usage.ts`:
- Around line 38-40: Update the usage-generation logic around the arg.hidden
check so hidden positional arguments cannot make the displayed invocation
unparsable: reject hidden required positionals or hidden positionals preceding
visible positionals, or retain required placeholders in usage. Extend the
relevant test to parse the exact invocation rendered by usage when secretPos
precedes rootDir.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0da35241-5ff3-4afa-bbbc-be740b52253e

📥 Commits

Reviewing files that changed from the base of the PR and between 9cb0edc and 79cefa5.

📒 Files selected for processing (4)
  • README.md
  • src/types.ts
  • src/usage.ts
  • test/usage.test.ts

Comment thread src/usage.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/usage.ts`:
- Around line 44-46: Update the hidden-argument handling in parseArgs so
required hidden non-positional ArgDefs are not silently omitted: either reject
them during validation or preserve their required invocation placeholder in both
the OPTIONS entry and usageLine output. Keep hidden positional arguments’
existing behavior unchanged, and ensure showUsage() remains consistent with
parser requirements.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c039a6d7-a5dd-4c34-b7d0-8ff53bfaeeed

📥 Commits

Reviewing files that changed from the base of the PR and between 79cefa5 and 1f704e4.

📒 Files selected for processing (4)
  • README.md
  • src/types.ts
  • src/usage.ts
  • test/usage.test.ts
💤 Files with no reviewable changes (1)
  • test/usage.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • README.md
  • src/types.ts

Comment thread src/usage.ts
Comment on lines +44 to +46
if (arg.hidden) {
continue;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n 'hidden|required' src/types.ts src/_parser.ts test/usage.test.ts

Repository: unjs/citty

Length of output: 1079


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '--- files ---\n'
git ls-files 'src/*.ts' 'src/**/*.ts' 'test/*.test.ts' | sort

printf '\n--- src/types.ts outline ---\n'
ast-grep outline src/types.ts --view compact || true

printf '\n--- src/types.ts ---\n'
cat -n src/types.ts | sed -n '1,140p'

printf '\n--- src/_parser.ts outline ---\n'
ast-grep outline src/_parser.ts --view compact || true

printf '\n--- src/_parser.ts relevant sections ---\n'
wc -l src/_parser.ts
cat -n src/_parser.ts | sed -n '1,260p'

printf '\n--- src/usage.ts ---\n'
cat -n src/usage.ts | sed -n '1,180p'

printf '\n--- test usage hidden/relevant sections ---\n'
cat -n test/usage.test.ts | sed -n '1,360p'

Repository: unjs/citty

Length of output: 239


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- files ---'
git ls-files 'src/*.ts' 'src/**/*.ts' 'test/*.test.ts' | sort

printf '%s\n' ''
printf '%s\n' '--- src/types.ts outline ---'
ast-grep outline src/types.ts --view compact || true

printf '%s\n' ''
printf '%s\n' '--- src/types.ts ---'
cat -n src/types.ts | sed -n '1,140p'

printf '%s\n' ''
printf '%s\n' '--- src/_parser.ts outline ---'
ast-grep outline src/_parser.ts --view compact || true

printf '%s\n' ''
printf '%s\n' '--- src/_parser.ts relevant sections ---'
wc -l src/_parser.ts
cat -n src/_parser.ts | sed -n '1,320p'

printf '%s\n' ''
printf '%s\n' '--- src/usage.ts ---'
cat -n src/usage.ts | sed -n '1,200p'

printf '%s\n' ''
printf '%s\n' '--- test usage hidden/relevant sections ---'
cat -n test/usage.test.ts | sed -n '1,380p'

Repository: unjs/citty

Length of output: 28891


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- src/args.ts ---'
cat -n src/args.ts | sed -n '1,240p'

printf '%s\n' ''
printf '%s\n' '--- src/index.ts ---'
cat -n src/index.ts | sed -n '1,220p'

printf '%s\n' ''
printf '%s\n' '--- targeted hidden required/parsing searches ---'
rg -n 'hidden|required|check|validate|missing|option|parseRawArgs|renderUsage|defineCommand' src test -g '*.ts' | sed -n '1,240p'

printf '%s\n' ''
printf '%s\n' '--- static check for no explicit hidden required validation ---'
python3 - <<'PY'
from pathlib import Path
for path in [Path('src/args.ts'), Path('src/_parser.ts'), Path('src/main.ts'), Path('src/command.ts')]:
    text = path.read_text()
    print(f'{path}: hidden_required_validator={ "hidden" in text and "required" in text }')
PY

Repository: unjs/citty

Length of output: 16652


Reject required hidden non-positional options or preserve their invocation placeholder.

hidden is allowed on non-positional ArgDefs, and parseArgs only rejects missing required options after parsing. This continue skips both the OPTIONS entry and the required usageLine slot (--${arg.name}), so showUsage() can render an invocation without the required parser input.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/usage.ts` around lines 44 - 46, Update the hidden-argument handling in
parseArgs so required hidden non-positional ArgDefs are not silently omitted:
either reject them during validation or preserve their required invocation
placeholder in both the OPTIONS entry and usageLine output. Keep hidden
positional arguments’ existing behavior unchanged, and ensure showUsage()
remains consistent with parser requirements.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant