Skip to content

Commit

Permalink
clean the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Its-Just-Nans committed Feb 15, 2025
1 parent f7bfa70 commit b7d0c45
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/config/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod test;
use anyhow::{bail, Context, Result};
use schemars::JsonSchema;
use serde::Deserialize;
use source::{workspace, Source};
use source::{workspace::WorkspaceConfig, Source};
use std::path::{Path, PathBuf};
use tracing::log;

Expand Down Expand Up @@ -120,7 +120,7 @@ pub async fn load_workspace_config(
) -> Result<Option<PathBuf>> {
let cargo_toml = current_path.join("Cargo.toml");
if cargo_toml.exists() {
if let Ok(workspace) = workspace::workspace_from_manifest(&cargo_toml).await {
if let Ok(workspace) = WorkspaceConfig::new(&cargo_toml).await {
match workspace_name {
Some(name) => {
if let Some(workspace) = workspace.get_workspace_by_name(&name) {
Expand Down
13 changes: 4 additions & 9 deletions src/config/models/source/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use anyhow::{Context, Result};
use cargo_metadata::{Metadata, MetadataCommand};
use serde::{Deserialize, Serialize};
use std::path::Path;
use std::path::PathBuf;
use tokio::task::spawn_blocking;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkspaceConfig {
pub metadata: Metadata,
}
Expand All @@ -21,12 +22,12 @@ impl WorkspaceConfig {
}

pub fn get_default_workspace(self) -> Option<PathBuf> {
if let Some(default_members) = self.metadata.workspace_default_members.first() {
if let Some(default_member) = self.metadata.workspace_default_members.first() {
if let Some(found) = self
.metadata
.packages
.into_iter()
.find(|p| p.id == *default_members)
.find(|p| p.id == *default_member)
{
return Some(found.manifest_path.clone().into());
}
Expand All @@ -51,9 +52,3 @@ impl WorkspaceConfig {
None
}
}

/// Load the trunk configuration from the cargo manifest
pub async fn workspace_from_manifest(file: impl AsRef<Path>) -> anyhow::Result<WorkspaceConfig> {
let workspace_config = WorkspaceConfig::new(file.as_ref()).await?;
Ok(workspace_config)
}

0 comments on commit b7d0c45

Please sign in to comment.