Skip to content

Conversation

@remybar
Copy link
Collaborator

@remybar remybar commented Aug 16, 2025

Description

Fix sozo --version output.

Tests

  • Yes
  • No, because they aren't needed
  • No, because I need help

Added to documentation?

  • README.md
  • Dojo Book
  • No documentation needed

Checklist

  • I've formatted my code (scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • I've commented my code
  • I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features
    • CLI --version now shows a dynamic banner including both Dojo and Scarb versions.
    • manifest_path can be supplied via the DOJO_MANIFEST_PATH environment variable in addition to CLI options.
  • Refactor
    • Version handling consolidated to use the built-in --version behavior; the separate explicit version flag has been removed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 16, 2025

ohayo sensei!

Walkthrough

Adds dynamic version generation for the Sozo CLI using a new utility that queries Scarb; removes the explicit CLI version flag; allows manifest_path to be provided via DOJO_MANIFEST_PATH environment variable; and implements Scarb interop to run scarb --version.

Changes

Cohort / File(s) Change Summary
CLI Args and Version Wiring
bin/sozo/src/args.rs
Switches Clap to version = generate_version() (imports generate_version), removes pub version: bool, and binds manifest_path to the DOJO_MANIFEST_PATH env var (#[arg(env = "DOJO_MANIFEST_PATH")]).
Version Banner Utility
bin/sozo/src/utils.rs
Adds pub fn generate_version() -> String that composes CARGO_PKG_VERSION with the Scarb version (via Scarb::version()), falling back when Scarb isn’t found.
Scarb Version Interop
crates/sozo/scarb_interop/src/scarb.rs
Adds pub fn version() -> Option<String> which runs scarb --version, returning stdout on success or stderr on failure as Some(String), otherwise None.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Clap as Clap/SozoArgs
  participant Utils as utils::generate_version
  participant Scarb as scarb_interop::Scarb
  participant OS as scarb process

  User->>Clap: sozo --version
  Clap->>Utils: generate_version()
  Utils->>Scarb: version()
  Scarb->>OS: run "scarb --version"
  OS-->>Scarb: stdout or stderr
  Scarb-->>Utils: Some(version) / None
  Utils-->>Clap: "<dojo_version>\nscarb: <ver|not found>"
  Clap-->>User: print version banner
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • glihm

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 19cf5ad and fa6c189.

📒 Files selected for processing (3)
  • bin/sozo/src/args.rs (1 hunks)
  • bin/sozo/src/utils.rs (2 hunks)
  • crates/sozo/scarb_interop/src/scarb.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • bin/sozo/src/utils.rs
  • bin/sozo/src/args.rs
  • crates/sozo/scarb_interop/src/scarb.rs
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-sozo_version

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 0

🧹 Nitpick comments (4)
crates/sozo/scarb_interop/src/scarb.rs (1)

18-24: Ohayo, sensei — trim stdout and check exit status to avoid extra newline and false positives

Right now we don't verify the process exit status and we propagate the raw stdout (which typically includes a trailing newline). This can lead to funky formatting in --version and to returning junk on failure. Suggest checking status.success() and trimming.

Apply this diff:

-    pub fn version() -> Option<String> {
-        Command::new("scarb")
-            .args(["--version"])
-            .output()
-            .ok()
-            .and_then(|output| String::from_utf8(output.stdout).ok())
-    }
+    pub fn version() -> Option<String> {
+        let output = Command::new("scarb").args(["--version"]).output().ok()?;
+        if !output.status.success() {
+            return None;
+        }
+        let stdout = String::from_utf8(output.stdout).ok()?;
+        Some(stdout.trim().to_owned())
+    }
bin/sozo/src/utils.rs (1)

212-223: Make version banner stable: remove embedded newline and trim Scarb output

Scarb::version() (and the fallback) can include trailing newlines, yielding awkward --version output like extra blank lines. Trim the Scarb output and drop the newline from the fallback.

Apply this diff:

 pub fn generate_version() -> String {
     const DOJO_VERSION: &str = env!("CARGO_PKG_VERSION");
 
-    let scarb_version = if let Some(scarb) = Scarb::version() {
-        scarb
-    } else {
-        "not found in your PATH\n".to_string()
-    };
+    let scarb_version = Scarb::version()
+        .map(|s| s.trim().to_string())
+        .unwrap_or_else(|| "not found in your PATH".to_string());
 
     format!("{}\nscarb: {}", DOJO_VERSION, scarb_version)
 }
bin/sozo/src/args.rs (2)

15-16: Use long_version for the multi-line banner; keep version to the Dojo semver

Feeding a multi-line String into version works, but clap traditionally uses long_version for extended, multi-line info while version is the short semver. This keeps sozo <semver> tidy and still shows Scarb details.

Additionally, if clap derive ever tightens what it accepts for version, this avoids potential macro parsing issues around calling a function in the attribute.

Consider this tweak:

-#[command(author, version=generate_version(), about, long_about = None)]
+#[command(
+    author,
+    version = env!("CARGO_PKG_VERSION"),
+    long_version = generate_version(),
+    about,
+    long_about = None
+)]

Would you confirm your clap version supports expressions in derive attributes here? If not, the above change will be safer across versions.


17-22: Env support for manifest_path: nice usability win; optional UX hint

Binding DOJO_MANIFEST_PATH is solid. As a tiny UX boost, you can hint shells that this expects a directory path.

You could add:

 #[arg(long)]
 #[arg(global = true)]
 #[arg(env = "DOJO_MANIFEST_PATH")]
+#[arg(value_hint = clap::ValueHint::DirPath)]
 #[arg(help = "Override path to a directory containing a Scarb.toml file.")]
 pub manifest_path: Option<Utf8PathBuf>,

Note: this is purely a nicety for completion helpers; feel free to skip.

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 67aeb9f and 19cf5ad.

📒 Files selected for processing (3)
  • bin/sozo/src/args.rs (1 hunks)
  • bin/sozo/src/utils.rs (2 hunks)
  • crates/sozo/scarb_interop/src/scarb.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
bin/sozo/src/utils.rs (1)
crates/sozo/scarb_interop/src/scarb.rs (1)
  • version (18-24)
bin/sozo/src/args.rs (2)
bin/sozo/src/utils.rs (1)
  • generate_version (212-222)
crates/sozo/scarb_interop/src/scarb.rs (1)
  • version (18-24)
🔇 Additional comments (2)
bin/sozo/src/utils.rs (1)

12-12: Ohayo, sensei — import looks good

Importing Scarb here is appropriate for the version banner generation.

bin/sozo/src/args.rs (1)

12-12: Ohayo, sensei — dependency on generate_version is wired correctly

Bringing generate_version into scope here is needed for the command metadata.

Copy link
Member

@kariy kariy left a comment

Choose a reason for hiding this comment

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

LGTM. Not a blocker, but added a comment worth noting

Comment on lines +212 to +223
pub fn generate_version() -> String {
const DOJO_VERSION: &str = env!("CARGO_PKG_VERSION");

let scarb_version = if let Some(scarb) = Scarb::version() {
scarb
} else {
"not found in your PATH\n".to_string()
};

format!("{}\nscarb: {}", DOJO_VERSION, scarb_version)
}

Copy link
Member

Choose a reason for hiding this comment

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

I think considering we have strong dependency on scarb, it may be more appropriate to return this as a concrete error (or panic).

@kariy kariy merged commit f229f9f into main Aug 18, 2025
18 of 19 checks passed
@kariy kariy deleted the fix-sozo_version branch August 18, 2025 01:50
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.

3 participants