rework-file-structure#1001
Conversation
1b31011 to
82b0310
Compare
|
🔎 The preview has been automatically deleted. |
2b452ee to
1b0264a
Compare
34b3a79 to
cc47164
Compare
9739631 to
957c4a5
Compare
Extract `getFavouriteDomain` and `getDomainObject` functions from `commands/domain.js` to `models/domain.js` to help future automated transforms and refactors.
2604933 to
2bc1ace
Compare
davlgd
left a comment
There was a problem hiding this comment.
Thanks for this amazing work, especially on automatic documentation. After using this version, and implemented new commands/options in it, LGTM. Using zod is way better than previous parsers. Just some nitpicks/reflexions:
--version as global option prevents us to add --version option to commands. I suppose this is related to cliparse and we can't do much about it for now.
As discussed, in --help I would be more for :
- USAGE
- COMMANDS (without AVAILABLE)
- OPTIONS
In options such as :
-F, --format <format> Output format (human, json) (default: human)
Default value is in grey. But sometimes we add default value in the option description (if it's managed from API for example). So it's incoherent. We must choose if we go all white or grey for such information.
About command metadata:
defineCommand({
description: 'Restart a Kubernetes cluster',
since: '4.5.0',
sinceDate: '2025-10-22',
IMHO, since is a good addition, as discussed for documentation, and it will be easy to add/maintain in release process. But sinceDate seems too much here. We can't plan when a release will be effective and it will need us to update this just before release. Additionally, this information already lives somewhere else.
If we don't plan to use it, we can just remove. If we plan to use it, maybe we can infer the date from the release semver.
27605de to
ee12c98
Compare
Yes, we cannot do much better for now because of cliparse but we're very close to be able to remove it.
Fixed, I wonder what others think.
I agree, this is fixed. |
ee12c98 to
521c106
Compare
Copy src/commands/curl.js to src/commands2/curl/curl.command.js with adjusted import paths and defineCommand wrapper.
Define add-on ID as a required argument using the argument definition system instead of relying on positional parameters, improving consistency with the new CLI structure. The automated script missed it because the original code was using an option inside args.
Rename kebab-case option keys to camelCase for consistency with JavaScript conventions. Update option definitions and destructuring assignments in activity, addon-create, applications, deploy, drain-create, env, logs, notify-email, restart, scale, service, ssh, and webhooks commands.
These options were not used by the commands, it was probably a options/privateOptions declaration problem.
Use the `deprecated` field in option definitions instead of runtime logging. This removes duplicate deprecation warnings and centralizes deprecation messaging.
Remove redundant text about current directory fallback behavior, making the description more concise while preserving the essential information.
Add help and version global options to the command-line interface with standard aliases (? for help, V for version). This will improve --help and documentation generation.
Implement new help command structure by creating dedicated help command file and registering it in global commands registry. This follows the established command architecture pattern used throughout the codebase.
Add new CLI entry point (bin/clever2.js) that builds commands dynamically from global commands structure. Includes utility functions (zod-utils.js) for Zod schema introspection to handle option parsing, validation, and type coercion. New system enables modular command organization and feature flag filtering.
Delete the command-options.js file containing cliparse-based option helpers that are no longer used in the new CLI structure.
Remove cliparse dependency from application_configuration.js and migrate the config update command to use the new defineOption system. Rename 'app' option to 'appIdOrName' for consistency and add explicit option definitions for all configuration settings including name, description, and feature flags.
Simplify expiration date handling by using schema default instead of conditional logic. Remove redundant date calculations and always require an expiration value.
Add getCommandInfo function to extract normalized command information for help text generation. Implement custom help function in cliparse patch to format usage, arguments, options, examples, and available commands with styled output.
Add scripts to automatically generate markdown documentation for CLI commands, including per-command docs and LLM-optimized reference material. Integrate documentation generation into the build and validation pipeline.
- Add detailed "Creating a New Command" section with file organization, command structure, options, arguments, and best practices - Add "Documentation Generation" section explaining auto-generated docs, workflow, and validation - Expand Project Structure with detailed command directory hierarchy and file organization - Replace TODO placeholder in Code Quality section with actual tooling list - Clarify that npm run docs must be run before committing to avoid CI failures - Fix typo in auto-fix command suggestion - Remove unused defineOption import from demo command example
Document the motivations, problems, and solutions for the file structure reorganization and documentation generation system. This ADR explains the transition from a monolithic structure to a hierarchical command-based organization, the introduction of a type-safe definition system using Zod, and automatic documentation generation capabilities.
Add mise.toml configuration file specifying Node.js 22.17.0 and npm 11.6.2 as project tool versions for development environment consistency.
78b9912 to
4c5a453
Compare
👋 Welcome reviewers
Summary
This PR completely restructures the clever-tools CLI architecture.
The main goal is to move from a monolithic structure (a single
clever.jsfile with all commands) to a modular architecture where each command lives in its own file with a typed declarative API.It also contains improvements about documentation:
--helpOverall stats: ~296 files changed, +14,834 / -6,754 lines
Phase 1: Documentation Preparation
Normalize argument and option documentation before the refactoring:
id-or-nameparameters (c99a3385)metavarto lowercase kebab-case (270b7368)wgPublicKey(54763a7e)outputoption (0fb533a0)Why first? These changes reduce noise in later diffs and ensure consistent documentation before transformation.
Phase 2: Preparatory Refactoring
Simplify existing code to ease the migration:
models/domain.js(715a298d)optionsas a function argumentImpact: These changes decouple our code from cliparse's internal API.
Phase 3: Analysis and Automated Transformation Scripts
Create temporary scripts to analyze and transform the code:
Note: These scripts are removed at the end of Phase 4.
Phase 4: Apply Transformations
Apply scripts and create the new architecture:
optionsandargs(5258e1c6)defineArgument,defineOption,defineCommand(af21b84d)*.command.jsfiles (3949a5b4)New structure:
Phase 5: Cleanup and Improvements
Post-migration cleanup and structure improvements:
curlcommand to new file structure (0d31d307).default('1y')for token expiration (3165698f)Phase 6: Final Integration
Activate the new structure as default:
--helpand--versionto global options (76e92ab5)helpcommand to global commands (a4bd6b3a)clever.jsandcommands/) (ce5514e9)Phase 7: Documentation
Improve help display and generate documentation:
--helpdisplay (52bf70d5)Chore
How to Review
I recommend following the phase order for review:
src/lib/define-*.jsand a command example (e.g.,addon/)clever.jsentry pointPhase 3 and parts of phase 6 are migration "noise" - temporary scripts and cleanup.