Skip to content

Commit

Permalink
feat: adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
1739616529 committed Aug 7, 2024
1 parent 130bd36 commit 5c1b6f6
Showing 1 changed file with 42 additions and 10 deletions.
52 changes: 42 additions & 10 deletions crates/nsv/src/command/adapt.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
use async_trait::async_trait;
use root::core::NsvCore;
use thiserror::Error;

use crate::print_log_1;

use super::Command;
use async_trait::async_trait;
use root::node::NsvCoreError;
use root::{core::NsvCore, node::NodeDispose};
use thiserror::Error;
use tokio::fs::read_to_string;

#[derive(clap::Parser, Debug)]
pub struct Adapt {
}
pub struct Adapt {}

#[async_trait]
impl Command for Adapt {
async fn apply(&self, _core: &mut NsvCore) -> Result<(), NsvCoreError> {
print_log_1!("adapt {}", "功能待开发");
async fn apply(&self, core: &mut NsvCore) -> Result<(), NsvCoreError> {
if !core.config.adapt {
return Ok(());
}
let file = core
.config
.adapt_version_match
.clone()
.unwrap_or(".nsvrc".to_string());

let version = read_to_string(file).await;

if version.is_err() {
return Ok(());
}

let version = version.unwrap();
let version = version.trim();

core.set_version_target(version)?;
let mut local_node_version = core.get_version_by_local().await;
if local_node_version.is_none() && core.config.auto {
let remote_node_version = core.get_version_by_remote().await;
if remote_node_version.is_none() {
return Err(NsvCoreError::NodeVersionRemoteNotFound);
};
let remote_node_version = remote_node_version.unwrap().clone();
let version = remote_node_version.get_version();
let download_node_info = core
.sync_node_by_remote(&version)
.await;
core.unzip_node_file(&download_node_info.target).await;
local_node_version = Some(version);
}

let local_node_version = local_node_version.as_ref().unwrap();
core.sync_mate_file_by_version(local_node_version).await;

Ok(())
}
Expand Down

0 comments on commit 5c1b6f6

Please sign in to comment.