Skip to content

rework-file-structure#1001

Merged
hsablonniere merged 45 commits intomasterfrom
rework-file-structure-cleanup
Jan 14, 2026
Merged

rework-file-structure#1001
hsablonniere merged 45 commits intomasterfrom
rework-file-structure-cleanup

Conversation

@hsablonniere
Copy link
Copy Markdown
Member

@hsablonniere hsablonniere commented Nov 19, 2025

👋 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.js file 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:

  • We patched cliparse to improve the display of --help
  • We added a new npm script to generate a reference documentation for each commands and a single document with everything for LLMs

Overall stats: ~296 files changed, +14,834 / -6,754 lines

Phase 1: Documentation Preparation

Normalize argument and option documentation before the refactoring:

  • Clarify argument names for id-or-name parameters (c99a3385)
  • Normalize metavar to lowercase kebab-case (270b7368)
  • Remove redundant metavar on wgPublicKey (54763a7e)
  • Add missing metavar on output option (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:

  • Move domain utility functions to models/domain.js (715a298d)
  • Make getEmailNotificationTargets function private (be1ab98d)
  • Rename some constants to avoid naming conflicts (dc3165f7)
    • We're going to need options as a function argument
  • Extract cliparse patches into a dedicated module (cd046782)
  • Simplify parsers: they now throw errors instead of returning cliparse result objects (5810a03c)
  • Simplify autocomplete: functions now return plain arrays (4bd1d817)

Impact: 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:

  • Add CSV file with versions and dates for each command (737cbe47)
  • Script to analyze commands, arguments, and options (df843913)
  • Script to transform command function signatures (c48d3226)
  • Script to analyze command dependencies and usage (7166e2e6)
  • Script to generate new CLI command structure (23e60b9e)

Note: These scripts are removed at the end of Phase 4.

Phase 4: Apply Transformations

Apply scripts and create the new architecture:

  • Apply automated script to convert command function signatures (d2b56f65)
  • Update cliparse command function signature to pass options and args (5258e1c6)
  • Introduce type-safe helpers defineArgument, defineOption, defineCommand (af21b84d)
  • Apply generation script: create all *.command.js files (3949a5b4)
  • Remove temporary refactoring scripts (6a992607)

New structure:

src/commands/
├── addon/
│   ├── addon.command.js
│   ├── addon.args.js
│   ├── addon.create.command.js
│   ├── addon.delete.command.js
│   └── ...
├── domain/
│   ├── domain.command.js
│   └── ...
├── global.commands.js
├── global.options.js
└── ...

Phase 5: Cleanup and Improvements

Post-migration cleanup and structure improvements:

  • Add curl command to new file structure (0d31d307)
  • Add argument definition to addon env command (7d3427f1)
  • Fix options schemas, descriptions, and parsers (97ece541)
  • Normalize option keys to camelCase (95973b96)
  • Remove unused options (b2946200)
  • Improve option placeholders for clarity (40554379)
  • Move single-usage options to their respective commands (c438b079)
  • Deduplicate: when root and list commands are the same (9877b49f)
  • Move deprecation messages to option definitions (57257270)
  • Remove redundant "(optional)" from argument descriptions (149de624)
  • Migrate config update command to new option definition system (1f80cfe6)
  • Use .default('1y') for token expiration (3165698f)

Phase 6: Final Integration

Activate the new structure as default:

  • Add --help and --version to global options (76e92ab5)
  • Add help command to global commands (a4bd6b3a)
  • New entry point using the new file structure (958fa568)
  • Remove old CLI structure (old clever.js and commands/) (ce5514e9)
  • Make new CLI structure the default (b776128e)
  • Remove unused parsers (2c6cafa7)
  • Remove unused command-options module (e398115c)

Phase 7: Documentation

Improve help display and generate documentation:

  • Improve --help display (52bf70d5)
  • Add documentation generation scripts (reference & LLM) (b4436995)
  • Generate comprehensive command reference and LLM documentation (d4eaba58)
  • Update CONTRIBUTING.md with new command structure and docs (a28b13de)
  • Add architecture decision record for file structure rework (da07c1b9)

Chore

  • Add mise.toml with node and npm versions (4c5a4531)

How to Review

I recommend following the phase order for review:

  1. Phase 1-2: Simple preparatory changes
  2. Phase 4: Look at src/lib/define-*.js and a command example (e.g., addon/)
  3. Phase 6: Check the new clever.js entry point
  4. Phase 7: Review the generated documentation and the ADR

Phase 3 and parts of phase 6 are migration "noise" - temporary scripts and cleanup.

@hsablonniere hsablonniere changed the title refactor: remove unused CLI arguments and options rework-file-structure Nov 19, 2025
@hsablonniere hsablonniere force-pushed the rework-file-structure-cleanup branch from 1b31011 to 82b0310 Compare November 25, 2025 17:22
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 25, 2025

🔎 The preview has been automatically deleted.

@hsablonniere hsablonniere force-pushed the rework-file-structure-cleanup branch from 2b452ee to 1b0264a Compare November 25, 2025 18:27
@hsablonniere hsablonniere force-pushed the rework-file-structure-cleanup branch 2 times, most recently from 34b3a79 to cc47164 Compare December 2, 2025 23:14
@hsablonniere hsablonniere added this to the 4.5.0 milestone Dec 8, 2025
@hsablonniere hsablonniere force-pushed the rework-file-structure-cleanup branch 9 times, most recently from 9739631 to 957c4a5 Compare December 11, 2025 17:55
@hsablonniere hsablonniere force-pushed the rework-file-structure-cleanup branch 5 times, most recently from 2604933 to 2bc1ace Compare December 18, 2025 19:44
Copy link
Copy Markdown
Contributor

@davlgd davlgd left a comment

Choose a reason for hiding this comment

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

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.

@hsablonniere hsablonniere force-pushed the rework-file-structure-cleanup branch from 27605de to ee12c98 Compare January 7, 2026 15:39
@hsablonniere
Copy link
Copy Markdown
Member Author

--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.

Yes, we cannot do much better for now because of cliparse but we're very close to be able to remove it.

As discussed, in --help I would be more for : USAGE, COMMANDS (without AVAILABLE), OPTIONS

Fixed, I wonder what others think.

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.

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.

I agree, this is fixed.

@hsablonniere hsablonniere force-pushed the rework-file-structure-cleanup branch from ee12c98 to 521c106 Compare January 7, 2026 15:45
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.
@hsablonniere hsablonniere force-pushed the rework-file-structure-cleanup branch from 78b9912 to 4c5a453 Compare January 13, 2026 16:39
@hsablonniere hsablonniere marked this pull request as ready for review January 14, 2026 10:40
@hsablonniere hsablonniere requested a review from a team as a code owner January 14, 2026 10:40
@hsablonniere hsablonniere merged commit 884aaa0 into master Jan 14, 2026
6 checks passed
@hsablonniere hsablonniere deleted the rework-file-structure-cleanup branch January 14, 2026 10:40
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.

4 participants