Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions bin/sozo/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use tracing_log::{AsTrace, LogTracer};
use tracing_subscriber::FmtSubscriber;

use crate::commands::Commands;
use crate::utils::generate_version;

#[derive(Parser, Debug)]
#[command(author, about, long_about = None)]
#[command(disable_version_flag = true)]
#[command(author, version=generate_version(), about, long_about = None)]
pub struct SozoArgs {
#[arg(long)]
#[arg(global = true)]
Expand All @@ -34,9 +34,6 @@ pub struct SozoArgs {
#[arg(help = "Run without accessing the network.")]
pub offline: bool,

#[arg(short = 'V', long, help = "Print version")]
pub version: bool,

#[command(subcommand)]
pub command: Commands,
}
Expand Down
13 changes: 13 additions & 0 deletions bin/sozo/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use dojo_world::config::ProfileConfig;
use dojo_world::contracts::ContractInfo;
use dojo_world::diff::WorldDiff;
use dojo_world::local::WorldLocal;
use scarb_interop::Scarb;
use scarb_metadata::Metadata;
use scarb_metadata_ext::MetadataDojoExt;
use semver::{Version, VersionReq};
Expand Down Expand Up @@ -208,6 +209,18 @@ fn is_compatible_version(provided_version: &str, expected_version: &str) -> Resu
Ok(expected_ver_req.matches(&provided_ver))
}

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)
}

Comment on lines +212 to +223
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).

// Returns the contracts from the manifest or from the diff.
#[allow(clippy::unnecessary_unwrap)]
pub async fn contracts_from_manifest_or_diff(
Expand Down
10 changes: 10 additions & 0 deletions crates/sozo/scarb_interop/src/scarb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ pub enum Features {
pub struct Scarb {}

impl Scarb {
pub fn version() -> Option<String> {
Command::new("scarb").args(["--version"]).output().ok().and_then(|output| {
if output.status.success() {
String::from_utf8(output.stdout).ok()
} else {
String::from_utf8(output.stderr).ok()
}
})
}

/// Executes a Scarb command for the given manifest path.
fn execute(manifest_path: &Utf8Path, args: Vec<&str>) -> Result<()> {
// To not change the current dir at this level, we rely
Expand Down
Loading