Skip to content

Conversation

@yassinedorbozgithub
Copy link
Collaborator

@yassinedorbozgithub yassinedorbozgithub commented May 31, 2025

Motivation

The main motivation of this PR is to remove a third party nest-commander package used from the CLI.

Fixes #1069

Checklist:

  • I have performed a self-review of my own code
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Refactor
    • Updated the command-line interface to use a simplified manual command dispatch approach with explicit command validation and error handling.
    • Streamlined the migration command implementation for improved maintainability and dependency injection.
  • Chores
    • Removed an unused dependency to reduce package size.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 31, 2025

Walkthrough

The changes remove the nest-commander dependency from the CLI implementation. The CLI now uses explicit command parsing and manual dependency injection via NestJS, replacing the previous decorator-based and inheritance approach. The migration command is handled directly, and related class structure and dependency injection are updated accordingly.

Changes

Files/Paths Change Summary
api/package.json Removed nest-commander from dependencies.
api/src/cli.ts Replaced nest-commander CLI bootstrap with manual command parsing and NestJS context management.
api/src/migration/migration.command.ts Refactored MigrationCommand to remove inheritance/decorator from nest-commander; used property injection.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI (cli.ts)
    participant NestAppContext
    participant LoggerService
    participant MigrationCommand

    User->>CLI (cli.ts): Run CLI with command and args
    CLI (cli.ts)->>NestAppContext: Create context (logging disabled)
    CLI (cli.ts)->>LoggerService: Resolve LoggerService
    CLI (cli.ts)->>CLI (cli.ts): Check allowed commands
    alt Command is 'migration'
        CLI (cli.ts)->>MigrationCommand: Resolve and run(args)
    else Invalid command
        CLI (cli.ts)->>LoggerService: Log error
        CLI (cli.ts)->>CLI (cli.ts): Exit(1)
    end
    CLI (cli.ts)->>NestAppContext: Close context
Loading

Assessment against linked issues

Objective Addressed Explanation
Remove/reduce CLI dependency on nest-commander (#1069)
Refactor CLI and migration command to work without nest-commander (#1069)

Suggested labels

bug

Suggested reviewers

  • medchedli
  • MohamedAliBouhaouala

Poem

The commander is gone, the CLI stands tall,
With manual dispatch, it answers the call.
Migration runs swiftly, dependencies are few,
The codebase is lighter, the logic is new.
🐇 With a hop and a skip, we celebrate this feat—
Fewer packages now, and the CLI is neat!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce1e98a and 7dbd18c.

📒 Files selected for processing (1)
  • api/src/cli.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/src/cli.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: API-Tests
  • GitHub Check: Frontend Tests
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
api/src/cli.ts (1)

20-20: Consider a more extensible command architecture for future growth.

The current hard-coded approach works for the single migration command but may need refactoring as more commands are added. Consider implementing a command registry pattern for better maintainability.

For future enhancements, consider:

  • A command registry with auto-discovery
  • Help/usage generation
  • Command-specific argument parsing
  • Modular command structure

This can be addressed in future iterations as the CLI grows.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef4c61b and 8fda5b9.

⛔ Files ignored due to path filters (1)
  • api/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • api/package.json (0 hunks)
  • api/src/cli.ts (1 hunks)
  • api/src/migration/migration.command.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • api/package.json
🧰 Additional context used
🧬 Code Graph Analysis (1)
api/src/cli.ts (1)
api/src/migration/migration.command.ts (1)
  • MigrationCommand (16-66)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: API-Tests
  • GitHub Check: Frontend Tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
api/src/migration/migration.command.ts (1)

16-16:

✅ Verification successful

Ensure MigrationCommand is registered as a provider.

Since this class is no longer using nest-commander's automatic registration, verify that MigrationCommand is properly registered as a provider in the relevant module to enable appContext.get(MigrationCommand) in cli.ts.

Run the following script to verify the provider registration:


🏁 Script executed:

#!/bin/bash
# Description: Check if MigrationCommand is registered as a provider in any module

# Search for MigrationCommand in provider arrays
rg -A 10 -B 5 "providers.*\[" | rg -A 15 -B 5 "MigrationCommand"

Length of output: 1250


MigrationCommand registration verified

MigrationCommand is already registered in api/src/migration/migration.module.ts under the providers array alongside MigrationService. No further changes are needed.

api/src/cli.ts (2)

24-27: Good practice: Clean application context creation for CLI.

The application context creation with disabled logging is appropriate for CLI usage, and the manual logger resolution ensures proper logging functionality.


36-36: Proper cleanup: Application context is correctly closed.

Good practice to ensure the application context is properly closed after command execution to prevent resource leaks.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
api/src/cli.ts (1)

34-39: Improve error type safety in catch block.

The error handling is present (addressing the previous review concern), but could be more type-safe.

    } catch (error) {
-      logger.error(`Migration command failed: ${error.message}`);
+      logger.error(`Migration command failed: ${error instanceof Error ? error.message : String(error)}`);
      process.exit(1);
    }

This ensures proper error message extraction regardless of the error type.

🧹 Nitpick comments (1)
api/src/cli.ts (1)

20-20: Consider making ALLOWED_COMMANDS more maintainable.

While the current approach works for a single command, consider making this more scalable for future command additions.

-const ALLOWED_COMMANDS = ['migration'];
+const ALLOWED_COMMANDS = ['migration'] as const;
+type AllowedCommand = typeof ALLOWED_COMMANDS[number];

This provides better type safety and makes it clear this is an immutable list.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8fda5b9 and ce1e98a.

📒 Files selected for processing (1)
  • api/src/cli.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
api/src/cli.ts (2)
api/src/migration/migration.command.ts (1)
  • MigrationCommand (16-66)
api/src/logger/logger.service.ts (1)
  • error (32-34)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: API-Tests
  • GitHub Check: Frontend Tests
🔇 Additional comments (3)
api/src/cli.ts (3)

9-9: LGTM: Clean import structure after removing nest-commander.

The imports are well-organized and reflect the migration from nest-commander to manual NestJS dependency injection.

Also applies to: 17-18


23-26: Good implementation of manual command parsing and app context creation.

The approach correctly extracts command and arguments from process.argv and creates the NestJS context with logging disabled for CLI usage.


41-41: LGTM: Proper resource cleanup.

The application context is properly closed, ensuring clean resource management.

@marrouchi marrouchi marked this pull request as draft June 9, 2025 08:36
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.

🤔 [ISSUE] - investigate reducing cli dependencies

3 participants