Skip to content

Conversation

@kitlangton
Copy link
Contributor

Summary

  • Simplify withSubcommands: remove type widening and as casts
  • Fix --version to have global precedence (git/npm style)
  • Simplify type extractors using T[number] pattern
  • Rename HelpFormatter to CliOutput
  • Improve docstrings for CommandContext, withSubcommands, prompt, provide
  • Add TODO for process.argv browser compatibility

Test plan

  • All existing CLI tests pass
  • Added tests for --version global precedence

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This is a comprehensive refactoring of the CLI module focused on simplifying the API and improving type safety. The PR removes unnecessary type widening, fixes --version to have global precedence (git/npm style), and renames HelpFormatter to CliOutput for better clarity. It also introduces internal separation of concerns by splitting Command implementation into separate modules (command.ts, config.ts).

Key changes:

  • Simplified withSubcommands to accept an array instead of variadic arguments, removing type casting
  • Fixed --version/--help to work anywhere in command invocation (global precedence)
  • Renamed HelpFormatter to CliOutput and defaultHelpRenderer to defaultFormatter
  • Refactored internal command structure with new config.ts and command.ts modules

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Command.ts Major refactoring: simplified API, extracted internal logic to command.ts, updated to use array-based withSubcommands
CliOutput.ts Renamed from HelpFormatter.ts, added formatErrors method for batch error display
parser.ts Added extensive documentation, restructured for clarity, implements --version global precedence
command.ts (new) Internal implementation module containing command construction and validation logic
config.ts (new) Internal module for parsing and reconstructing nested config structures
Param.ts Renamed Argument/Flag constants to argumentKind/flagKind, improved type variance
Flag.ts Updated to use new Param constants, renamed withPseudoName → withMetavar, removed repeated combinator
Argument.ts Updated to use new Param constants, added missing combinators (filter, filterMap, orElse, etc.)
Primitive.ts Renamed fileString → fileText, keyValueMap → keyValuePair, added isBoolean helper
Test files Updated all test files to use array syntax for withSubcommands and new CliOutput API

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Rename FlagSpec → FlagRegistry, FlagBag → FlagAccumulator
- Add explicit ParseMode and FirstValueResult discriminated unions
- Break scanCommandLevel into processFlag, processValue, resolveFirstValue
- Remove vestigial leadingArguments field
- Rename ParsedConfig/InputSpec → Command.Config.Internal
- Move CommandConfig → Command.Config namespace
- Move InferConfig → Command.Config.Infer
- Add isFlagParam helper to Param.ts
- Extract config parsing to internal/config.ts
- Remove static completion generators (bash.ts, fish.ts, zsh/)
- --completions now generates dynamic shims that call binary at runtime
- Extract CommandInternal, toImpl, makeCommand to internal/command.ts
- makeCommand only accepts parsed ConfigInternal
- Remove getHelpDoc from public API
- Change from variadic to array parameter: withSubcommands([a, b])
- Add showHelp helper to deduplicate error handling
- Remove unnecessary CliError cast
- Update all test files to use new array syntax
- Rewrite withSubcommands with clearer structure and minimal casts
- Add TODO comment on prompt constructor semantic mismatch
- Use explicit type aliases for NewInput, NewService
- Document remaining casts with explanatory comments
Remove UserError wrap/unwrap dance. Use Effect.catch with instanceof
check to handle ShowHelp errors directly.
- Extract commandPath computation once
- Group built-in flag handlers together
- Use return yield* for early exits
- Consolidate parsing error handling
Replace recursive conditional types with simpler T[number] pattern.
18 lines → 6 lines for the same functionality.
- Fix withHandler JSDoc to use array syntax for withSubcommands
- Remove redundant args variable in runWith
- Yield HelpRenderer once at start of built-in handling
- Extract mapHandler helper to consolidate provide* functions
- HelpFormatter -> CliOutput (formats help, errors, version)
- HelpRenderer -> Formatter (service interface)
- defaultHelpRenderer -> defaultFormatter
- RawInput -> ParsedTokens (clearer purpose)
- ParentCommand -> CommandContext (describes service role)
- Remove NewInput type widening from withSubcommands return type
- Track subcommand info internally via _subcommand, not in public type
- Eliminate 4 type casts (as NewInput, as Input, as NewService)
- Fix tests to use yield* parent instead of yield* parent.service
- Add TODO for process.argv browser compatibility
- Simplify withHandler docstring example
- CommandContext: explain how to access parent config via yield*
- withSubcommands: show parent context access pattern
- prompt: add docstring with example
- provide: add example showing input-dependent layer
…mbinators

- Make Param module internal (not exported from index.ts)
- Fix Flag.none passing string instead of Param.Flag constant
- Rename fileString to fileText for consistency
- Fix @SInCE tags in Flag.ts (1.0.0 → 4.0.0)
- Fix mapTryCatch using hardcoded "unknown" for option name
- Add missing combinators to Argument: choiceWithValue, withPseudoName,
  filter, filterMap, orElse, orElseResult
- Fix optional @category: constructors → combinators
- Add architecture documentation to Param.ts
- Add Command.Any type alias for type-safe command navigation
- Extract findMatchingFlag helper to eliminate 3x duplication in handler.ts
- Remove all `as any` casts from handler.ts and internal/command.ts
- parseArgs now accepts Command.Any instead of being generic
- Removed generics from CommandContext and internal functions
- Eliminated `as unknown as` cast for subcommand recursion
- Add formatErrors to CliOutput.Formatter for multiple error display
- Update showHelp() to accept error array instead of single error
- Pass all accumulated errors in runWith (was only showing first)
- Improve createFlagRegistry error messages
- Add comprehensive error tests
- findMatchingFlag -> lookupFlag
- SingleFlagMeta -> FlagDescriptor
- parseOption -> parseFlag
- Add Primitive.isBoolean() helper
- Remove deprecated: keyValueMap, repeated, withPseudoName, Argument/Flag constants
- Fix AnyArgument/AnyFlag to use argumentKind/flagKind
- Make CliError.TypeId internal
- Normalize @category tags to lowercase
@github-actions
Copy link

📊 JSDoc Documentation Analysis

📈 Current Analysis Results
Analyzing 66 TypeScript files in packages/effect/src/ (including schema and config subdirectories)...

============================================================
         EFFECT JSDOC ANALYSIS REPORT
============================================================

📊 SUMMARY STATISTICS
------------------------------
Total files analyzed: 66
Total exported members: 2189
Missing @example: 1064 (48.6%)
Missing @category: 385 (17.6%)

🎯 TOP FILES NEEDING ATTENTION
----------------------------------------
1. schema/Schema.ts
   📝 419 missing examples, 🏷️  243 missing categories
   📦 419 total exports
2. schema/AST.ts
   📝 71 missing examples, 🏷️  13 missing categories
   📦 71 total exports
3. schema/Annotations.ts
   📝 37 missing examples, 🏷️  25 missing categories
   📦 37 total exports
4. schema/StandardSchema.ts
   📝 27 missing examples, 🏷️  27 missing categories
   📦 27 total exports
5. schema/Getter.ts
   📝 52 missing examples, 🏷️  1 missing categories
   📦 52 total exports
6. schema/Transformation.ts
   📝 28 missing examples, 🏷️  17 missing categories
   📦 28 total exports
7. PubSub.ts
   📝 25 missing examples, 🏷️  16 missing categories
   📦 37 total exports
8. Config.ts
   📝 33 missing examples, 🏷️  5 missing categories
   📦 33 total exports
9. Effect.ts
   📝 28 missing examples, 🏷️  1 missing categories
   📦 231 total exports
10. Cause.ts
   📝 26 missing examples, 🏷️  2 missing categories
   📦 66 total exports
11. SynchronizedRef.ts
   📝 24 missing examples, 🏷️  0 missing categories
   📦 24 total exports
12. schema/FromJsonSchema.ts
   📝 12 missing examples, 🏷️  12 missing categories
   📦 12 total exports
13. schema/Issue.ts
   📝 22 missing examples, 🏷️  2 missing categories
   📦 22 total exports
14. schema/Parser.ts
   📝 24 missing examples, 🏷️  0 missing categories
   📦 24 total exports
15. ConfigProvider.ts
   📝 20 missing examples, 🏷️  1 missing categories
   📦 20 total exports

✅ PERFECTLY DOCUMENTED FILES
-----------------------------------
   Clock.ts (5 exports)
   Console.ts (21 exports)
   FiberHandle.ts (15 exports)
   FiberMap.ts (19 exports)
   FiberSet.ts (14 exports)
   Match.ts (57 exports)
   MutableRef.ts (17 exports)
   Random.ts (7 exports)
   RegExp.ts (3 exports)
   Runtime.ts (3 exports)
   Symbol.ts (1 exports)
   index.ts (0 exports)
   schema/index.ts (0 exports)

🔍 SAMPLE MISSING ITEMS FROM schema/Schema.ts
-----------------------------------
   Optionality (type, line 54): missing example, category
   Mutability (type, line 61): missing example, category
   ConstructorDefault (type, line 68): missing example, category
   MakeOptions (interface, line 76): missing example, category
   Bottom (interface, line 100): missing example, category
   declareConstructor (interface, line 180): missing example, category
   declareConstructor (function, line 204): missing example
   declare (interface, line 228): missing example
   declare (function, line 237): missing example, category
   revealBottom (function, line 257): missing example, category

📋 BREAKDOWN BY EXPORT TYPE
-----------------------------------
type: 128 missing examples, 73 missing categories
const: 400 missing examples, 102 missing categories
interface: 208 missing examples, 138 missing categories
class: 52 missing examples, 3 missing categories
function: 245 missing examples, 51 missing categories
namespace: 31 missing examples, 18 missing categories

📈 DOCUMENTATION PROGRESS
------------------------------
Examples: 1125/2189 (51.4% complete)
Categories: 1804/2189 (82.4% complete)

============================================================
Analysis complete! 1449 items need attention.
============================================================

📄 Detailed results saved to: jsdoc-analysis-results.json

This comment is automatically updated on each push. View the analysis script for details.

@github-actions
Copy link

Bundle Size Analysis

File Name Current Size Previous Size Difference
bundle/basic.ts 6.23 KB 6.23 KB 0.00 KB (0.00%)
bundle/batching.ts 8.49 KB 8.49 KB 0.00 KB (0.00%)
bundle/brand.ts 6.35 KB 6.35 KB 0.00 KB (0.00%)
bundle/cache.ts 9.54 KB 9.54 KB 0.00 KB (0.00%)
bundle/config.ts 16.04 KB 16.04 KB 0.00 KB (0.00%)
bundle/differ.ts 14.29 KB 14.29 KB 0.00 KB (0.00%)
bundle/http-client.ts 18.45 KB 18.45 KB 0.00 KB (0.00%)
bundle/logger.ts 8.59 KB 8.59 KB 0.00 KB (0.00%)
bundle/metric.ts 8.72 KB 8.72 KB 0.00 KB (0.00%)
bundle/optic.ts 7.60 KB 7.60 KB 0.00 KB (0.00%)
bundle/pubsub.ts 13.05 KB 13.05 KB 0.00 KB (0.00%)
bundle/queue.ts 10.92 KB 10.92 KB 0.00 KB (0.00%)
bundle/schedule.ts 9.67 KB 9.67 KB 0.00 KB (0.00%)
bundle/schema-arbitrary.ts 16.26 KB 16.26 KB 0.00 KB (0.00%)
bundle/schema-equivalence.ts 15.39 KB 15.39 KB 0.00 KB (0.00%)
bundle/schema-formatter.ts 15.25 KB 15.25 KB 0.00 KB (0.00%)
bundle/schema-json-schema.ts 16.56 KB 16.56 KB 0.00 KB (0.00%)
bundle/schema-record-literals-key.ts 13.78 KB 13.78 KB 0.00 KB (0.00%)
bundle/schema-string-async.ts 11.29 KB 11.29 KB 0.00 KB (0.00%)
bundle/schema-string-check.ts 10.05 KB 10.05 KB 0.00 KB (0.00%)
bundle/schema-string.ts 9.64 KB 9.64 KB 0.00 KB (0.00%)
bundle/schema-template-literal.ts 12.20 KB 12.20 KB 0.00 KB (0.00%)
bundle/schema-toSerializerStringTree.ts 15.46 KB 15.46 KB 0.00 KB (0.00%)
bundle/schema.ts 14.88 KB 14.88 KB 0.00 KB (0.00%)
bundle/stm.ts 11.71 KB 11.71 KB 0.00 KB (0.00%)
bundle/stream.ts 8.42 KB 8.42 KB 0.00 KB (0.00%)

Remove handler from root command in test fixture - commands without
handlers should show help by default, which the framework already
supported but wasn't being tested.
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.

2 participants