Skip to content

refactor: simplify CLI command dispatch#2

Merged
ychampion merged 1 commit intoychampion:mainfrom
YchampionOP:refactor-cli-dispatch-6219048290121400892
Feb 25, 2026
Merged

refactor: simplify CLI command dispatch#2
ychampion merged 1 commit intoychampion:mainfrom
YchampionOP:refactor-cli-dispatch-6219048290121400892

Conversation

@YchampionOP
Copy link
Contributor

Summary

simplify CLI command dispatch

Changes

Validation

  • python -m pytest -q
  • Added/updated tests for behavior changes
  • Updated docs for command or UX changes

Risk and Rollback

Risk level:

  • Low
  • Medium
  • High

Rollback plan:

Co-authored-by: YchampionOP <86096030+YchampionOP@users.noreply.github.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @YchampionOP, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the command dispatch mechanism within the CLI, moving from a sequential conditional structure to a more organized, dictionary-driven approach. This change enhances the readability and maintainability of the command-line interface by centralizing command-to-function mapping and encapsulating command-specific logic into dedicated handler functions.

Highlights

  • Refactored CLI Command Dispatch: The main function's command handling logic was refactored from a long if/elif chain into a more modular and maintainable dictionary-based dispatch system.
  • Introduced Dedicated Handler Functions: Individual private functions (e.g., _handle_prep, _handle_status) were created for each CLI command, encapsulating their specific logic.
  • Centralized Command Mapping: A COMMAND_HANDLERS dictionary was added to map command names to their corresponding handler functions, simplifying command resolution.
Changelog
  • codeclaw/cli/init.py
    • Extracted existing command-specific logic into new private handler functions (e.g., _handle_prep, _handle_status, _handle_confirm, _handle_update_skill, _handle_list, _handle_serve, _handle_install_mcp).
    • Introduced a COMMAND_HANDLERS dictionary to map command names to their respective handler functions.
    • Replaced the extensive if/elif block for command dispatch with a concise lookup in the COMMAND_HANDLERS dictionary, falling back to _run_export if the command is not found.
Activity
  • No specific review comments or activity have been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ychampion ychampion merged commit 881a3dc into ychampion:main Feb 25, 2026
6 checks passed
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the CLI command dispatch logic, replacing an if/elif chain with a dictionary-based dispatch table. The logic for each command is extracted into a handler function. My review includes a suggestion to use lambda functions for simple handlers that don't use arguments, which can reduce boilerplate code and make the implementation more concise.

Comment on lines +140 to +157
COMMAND_HANDLERS = {
"prep": _handle_prep,
"status": _handle_status,
"confirm": _handle_confirm,
"update-skill": _handle_update_skill,
"synthesize": _handle_synthesize,
"serve": _handle_serve,
"install-mcp": _handle_install_mcp,
"watch": _handle_watch,
"setup": handle_setup,
"projects": handle_projects,
"list": _handle_list,
"config": _handle_config,
"doctor": handle_doctor,
"stats": handle_stats,
"share": handle_share,
"export": _run_export,
}

Choose a reason for hiding this comment

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

medium

For simple command handlers that don't use the args parameter, you can use lambda functions directly in the dispatch table. This makes the code more concise by avoiding the need for separate wrapper functions like _handle_status, _handle_serve, and _handle_install_mcp, which can then be removed.

Suggested change
COMMAND_HANDLERS = {
"prep": _handle_prep,
"status": _handle_status,
"confirm": _handle_confirm,
"update-skill": _handle_update_skill,
"synthesize": _handle_synthesize,
"serve": _handle_serve,
"install-mcp": _handle_install_mcp,
"watch": _handle_watch,
"setup": handle_setup,
"projects": handle_projects,
"list": _handle_list,
"config": _handle_config,
"doctor": handle_doctor,
"stats": handle_stats,
"share": handle_share,
"export": _run_export,
}
COMMAND_HANDLERS = {
"prep": _handle_prep,
"status": lambda _args: status(),
"confirm": _handle_confirm,
"update-skill": _handle_update_skill,
"synthesize": _handle_synthesize,
"serve": lambda _args: handle_serve(),
"install-mcp": lambda _args: handle_install_mcp(),
"watch": _handle_watch,
"setup": handle_setup,
"projects": handle_projects,
"list": _handle_list,
"config": _handle_config,
"doctor": handle_doctor,
"stats": handle_stats,
"share": handle_share,
"export": _run_export,
}

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