feat: support hidden args - #263
Conversation
📝 WalkthroughWalkthroughAdds an optional ChangesHidden arguments
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
README.mdsrc/types.tssrc/usage.tstest/usage.test.ts
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
README.mdsrc/types.tssrc/usage.tstest/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
| if (arg.hidden) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n 'hidden|required' src/types.ts src/_parser.ts test/usage.test.tsRepository: 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 }')
PYRepository: 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.
similar to hidden subcommands, this allows us to hide args (which we might, for example, want to keep for backwards compatibility)
Summary by CodeRabbit
hiddenargument option to omit specific arguments from rendered usage/help output while keeping them parsed and usable.hiddenbehavior.renderUsageskipping hidden arguments and confirmedparseArgsstill reads values for hidden options.