Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(katana): katana config #2972

Merged
merged 1 commit into from
Jan 29, 2025
Merged

feat(katana): katana config #2972

merged 1 commit into from
Jan 29, 2025

Conversation

kariy
Copy link
Member

@kariy kariy commented Jan 29, 2025

New subcommand:

katana config

for managing chain configuration files created by katana init. Currently, all it does is just displaying the config file.

$ katana config fartchain
File: /Users/kariy/Library/Application Support/katana/0x66617274636861696e/config.toml

[id]
Id = "0x66617274636861696e"

[fee-contract]
strk = "0x2e7442625bab778683501c0eadbc1ea17b3535da040a12ac7d281066e915eea"

[settlement.starknet]
rpc_url = "https://api.cartridge.gg/x/starknet/sepolia"
account = "0x4ac0264c73207f9bc7b12801500324be647a8c2fc56964f8e1945ca993006a7"
core_contract = "0x3c5a55d09400e9e79d34535a48499ae87fbb1b17538ac6b5c093863445dfdc8"

[settlement.starknet.id]
Named = "Sepolia"

Summary by CodeRabbit

  • New Features

    • Added a new configuration command to retrieve and display chain configuration details
    • Enhanced CLI with configuration management capabilities for different chain IDs
  • Improvements

    • Improved error handling for configuration file operations
    • Made initialization command more visible in the command-line interface

Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

Ohayo, sensei! The pull request introduces a new configuration management feature for the Katana CLI. A new ConfigArgs structure is added to handle chain configuration arguments, allowing users to retrieve and display configuration details for a specific chain. The changes extend the CLI's capabilities by adding a new Config command that can read and output configuration file contents, providing a streamlined way to access chain-specific configuration information.

Changes

File Change Summary
bin/katana/src/cli/config.rs - Added ConfigArgs struct for handling configuration arguments
- Implemented execute() method to read and print configuration file contents
bin/katana/src/cli/mod.rs - Added new config module
- Introduced Config(config::ConfigArgs) command variant
- Modified Init command's visibility

Sequence Diagram

sequenceDiagram
    participant CLI
    participant ConfigArgs
    participant ChainConfigDir
    participant ConfigFile

    CLI->>ConfigArgs: Parse arguments
    ConfigArgs->>ChainConfigDir: Open config directory
    ChainConfigDir->>ConfigFile: Retrieve config file path
    ConfigFile->>ConfigArgs: Read file contents
    ConfigArgs->>CLI: Print file path and contents
Loading

Possibly related PRs


🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

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

@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: 0

🧹 Nitpick comments (2)
bin/katana/src/cli/config.rs (2)

1-11: Ohayo sensei! Consider adding documentation for the ConfigArgs struct.

The struct looks well-organized, but adding documentation would help users understand its purpose better. Consider adding a doc comment explaining what this command does and providing an example usage.

 #[derive(Debug, Args)]
+/// Manages chain configuration files created by `katana init`.
+/// 
+/// # Example
+/// ```bash
+/// katana config my-chain
+/// ```
 pub struct ConfigArgs {

14-20: Consider enhancing error handling and output formatting, sensei!

The execute method could benefit from:

  1. More descriptive error messages using .context()
  2. Better formatting of the configuration output
 pub fn execute(self) -> Result<()> {
-    let cs = ChainConfigDir::open(&self.chain)?;
-    let path = cs.config_path();
-    let config = std::fs::read_to_string(&path)?;
-    println!("File: {}\n\n{config}", path.display());
+    let cs = ChainConfigDir::open(&self.chain)
+        .context("Failed to open chain configuration directory")?;
+    let path = cs.config_path();
+    let config = std::fs::read_to_string(&path)
+        .context("Failed to read configuration file")?;
+    println!("Configuration file path: {}", path.display());
+    println!("\nConfiguration contents:");
+    println!("----------------------");
+    println!("{config}");
     Ok(())
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f3373e and 58f94b1.

📒 Files selected for processing (2)
  • bin/katana/src/cli/config.rs (1 hunks)
  • bin/katana/src/cli/mod.rs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: fmt
🔇 Additional comments (3)
bin/katana/src/cli/mod.rs (3)

41-42: Ohayo! The command documentation looks good, sensei!

The about description for the Config command is clear and consistent with other commands.


28-28: The command integration looks clean, sensei!

The Config command is properly integrated into the match statement.


7-7: Verify config file validation, sensei!

Let's verify that the implementation properly handles invalid config files and provides appropriate error messages.

✅ Verification successful

Ohayo! Config validation is properly implemented, sensei!

The codebase has comprehensive config validation including:

  • Type-safe config parsing with proper error handling
  • Validation of execution parameters and account settings
  • Gas price and RPC module configuration checks
  • Appropriate error messages for invalid values
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any existing config file validation logic
rg -A 5 "config.*validate|validate.*config" .

# Check for TOML parsing implementation
ast-grep --pattern 'use.*toml'

Length of output: 1058


Script:

#!/bin/bash
# Search for config parsing and error handling
ast-grep --pattern 'fn $_(config: $_) -> Result<$_, $_>'

# Look for config file loading implementation
rg -A 5 "config.*from_file|load.*config|parse.*config" .

# Check for any error type definitions related to config
rg -A 3 "Error.*Config|Config.*Error" .

Length of output: 81705

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

Attention: Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.

Project coverage is 57.17%. Comparing base (4f3373e) to head (58f94b1).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
bin/katana/src/cli/config.rs 0.00% 8 Missing ⚠️
bin/katana/src/cli/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2972      +/-   ##
==========================================
- Coverage   57.19%   57.17%   -0.02%     
==========================================
  Files         423      424       +1     
  Lines       56125    56134       +9     
==========================================
- Hits        32103    32097       -6     
- Misses      24022    24037      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kariy kariy merged commit 13ff596 into main Jan 29, 2025
13 of 15 checks passed
@kariy kariy deleted the katana/init-config branch January 29, 2025 22:29
@kariy kariy changed the title feat(katana): chain config management tool feat(katana): katana config Feb 2, 2025
@coderabbitai coderabbitai bot mentioned this pull request Feb 2, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant