Skip to content

Conversation

@jnmt
Copy link
Collaborator

@jnmt jnmt commented Nov 10, 2025

Description

This PR refactors the client CLI (and TableStore as well) commands before adding new commands for creating namespaces and so on. Basically, it follows what I did in the HashStore CLI, adding an abstract command class.

Related issues and/or PRs

N/A

Changes made

  • Introduce abstract commands for the primitive CLI and TableStore CLI so that all commands can handle config files and ClientException in the same manner.

Checklist

The following is a best-effort checklist. If any items in this checklist are not applicable to this PR or are dependent on other, unmerged PRs, please still mark the checkboxes after you have read and understood each item.

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • I have considered whether similar issues could occur in other products, components, or modules if this PR is for bug fixes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

N/A

Release notes

Refactored client CLI commands.

Copilot AI review requested due to automatic review settings November 10, 2025 10:06
@gemini-code-assist
Copy link

Summary of Changes

Hello @jnmt, 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-line interface (CLI) tools for both the general client and the table-store client. By introducing abstract base classes, AbstractClientCommand and AbstractTableStoreCommand, common functionalities such as client service initialization, configuration loading, and standardized exception handling are centralized. This change streamlines the individual CLI command implementations, making them more concise and easier to maintain. Furthermore, it improves error reporting for file output operations, enhancing the overall robustness of the CLI tools.

Highlights

  • Centralized CLI Logic: Introduced AbstractClientCommand and AbstractTableStoreCommand to consolidate common logic for client and table-store CLI tools, reducing code duplication across various commands.
  • Simplified Command Implementations: All existing client and table-store CLI commands now extend these new abstract classes, leading to cleaner, more concise, and more focused command-specific logic by delegating common setup and error handling.
  • Enhanced Error Handling: Added a new error type WRITING_RESULT_TO_FILE_FAILED and integrated its usage into contract and function registration processes for more robust error reporting when saving results to TOML files.
  • Updated Test Suite: Modified corresponding unit tests to reflect the refactored CLI structure, ensuring proper testing of the new abstract classes and simplified command implementations, including adjustments to factory mocking and verification.
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.

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 is a great refactoring that introduces AbstractClientCommand and AbstractTableStoreCommand to centralize common CLI logic, such as service creation, exception handling, and resource cleanup. This significantly reduces boilerplate code in individual command classes and improves maintainability.

My review has identified a few areas for improvement to enhance consistency and robustness:

  • Final methods: The call() method in the new abstract classes should be marked as final to prevent subclasses from accidentally bypassing the common execution logic.
  • Consistent Exception Handling: In a few places, exceptions are caught and handled in a way that bypasses the new centralized, JSON-based error reporting. Specifically:
    • IOException in ContractsRegistration and FunctionsRegistration should be wrapped in a ClientException and re-thrown.
    • Argument parsing exceptions in LedgerValidation should also be wrapped and re-thrown to ensure all errors are reported to the user in a consistent JSON format.

Overall, this is a solid improvement. Addressing these points will make the refactoring even more robust and consistent.

Comment on lines 104 to 108
} catch (IOException e) {
System.err.printf(ClientError.WRITING_RESULT_TO_FILE_FAILED.buildMessage(e.getMessage()));
printStackTrace(e);
return 1;
}

Choose a reason for hiding this comment

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

medium

The IOException is caught and handled here by printing a raw string to System.err and returning 1. This bypasses the centralized JSON error reporting mechanism in AbstractClientCommand. To maintain consistency in error reporting, this exception should be wrapped in a ClientException and re-thrown, allowing the abstract class to handle it.

      } catch (IOException e) {
        throw new ClientException(ClientError.WRITING_RESULT_TO_FILE_FAILED, e, e.getMessage());
      }

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 PR refactors command-line tools in both the client and table-store modules by extracting common command execution logic into abstract base classes (AbstractClientCommand and AbstractTableStoreCommand). The refactoring reduces code duplication by centralizing factory creation, service initialization, error handling, and resource cleanup.

  • Introduced abstract base classes to handle common command lifecycle (service creation, error handling, factory cleanup)
  • Simplified test methods to use the new execute() method directly or call call(factory) with proper mocking
  • Fixed error output to use System.err instead of System.out in client LedgerValidation
  • Added new error type for file writing failures

Reviewed Changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
AbstractTableStoreCommand.java New abstract base class consolidating common logic for table-store commands
AbstractClientCommand.java New abstract base class consolidating common logic for client commands
StatementExecution.java, LedgerValidation.java, Bootstrap.java (table-store) Refactored to extend AbstractTableStoreCommand and implement execute() method
Multiple client tool classes Refactored to extend AbstractClientCommand and implement execute() method
Test files Updated tests to use execute() for happy paths and call(factory) for error scenarios
ClientError.java Added WRITING_RESULT_TO_FILE_FAILED error enum
LedgerValidation.java (client) Changed error output from System.out to System.err
FunctionsRegistration.java, ContractsRegistration.java Updated file writing to use Files.newOutputStream and added IOException handling

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

@jnmt jnmt self-assigned this Nov 10, 2025
Copy link
Member

@josh-wong josh-wong left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!🙇🏻‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants