Skip to content

Commit 8f2ca6e

Browse files
committed
fix: refine codes
1 parent ccd4a5e commit 8f2ca6e

File tree

117 files changed

+1380
-1975
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1380
-1975
lines changed

core/src/ten_manager/src/cmd/cmd_check/cmd_check_manifest_json.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ten_rust::{
1414
};
1515

1616
use crate::{
17-
config::{internal::TmanInternalConfig, TmanConfig},
17+
config::{metadata::TmanMetadata, TmanConfig},
1818
output::TmanOutput,
1919
};
2020

@@ -48,8 +48,8 @@ pub fn parse_sub_cmd(
4848
}
4949

5050
pub async fn execute_cmd(
51-
_tman_config: Arc<TmanConfig>,
52-
_tman_internal_config: Arc<TmanInternalConfig>,
51+
_tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
52+
_tman_metadata: Arc<tokio::sync::RwLock<TmanMetadata>>,
5353
command_data: CheckManifestJsonCommand,
5454
out: Arc<Box<dyn TmanOutput>>,
5555
) -> Result<()> {

core/src/ten_manager/src/cmd/cmd_check/cmd_check_property_json.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ten_rust::{
1414
};
1515

1616
use crate::{
17-
config::{internal::TmanInternalConfig, TmanConfig},
17+
config::{metadata::TmanMetadata, TmanConfig},
1818
output::TmanOutput,
1919
};
2020

@@ -48,8 +48,8 @@ pub fn parse_sub_cmd(
4848
}
4949

5050
pub async fn execute_cmd(
51-
_tman_config: Arc<TmanConfig>,
52-
_tman_internal_config: Arc<TmanInternalConfig>,
51+
_tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
52+
_tman_metadata: Arc<tokio::sync::RwLock<TmanMetadata>>,
5353
command_data: CheckPropertyJsonCommand,
5454
out: Arc<Box<dyn TmanOutput>>,
5555
) -> Result<()> {

core/src/ten_manager/src/cmd/cmd_check/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use anyhow::Result;
1313
use clap::{ArgMatches, Command};
1414

1515
use crate::{
16-
config::{internal::TmanInternalConfig, TmanConfig},
16+
config::{metadata::TmanMetadata, TmanConfig},
1717
output::TmanOutput,
1818
};
1919

@@ -64,16 +64,16 @@ pub fn parse_sub_cmd(sub_cmd_args: &ArgMatches) -> Result<CheckCommandData> {
6464
}
6565

6666
pub async fn execute_cmd(
67-
tman_config: Arc<TmanConfig>,
68-
tman_internal_config: Arc<TmanInternalConfig>,
67+
tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
68+
tman_metadata: Arc<tokio::sync::RwLock<TmanMetadata>>,
6969
command_data: CheckCommandData,
7070
out: Arc<Box<dyn TmanOutput>>,
7171
) -> Result<()> {
7272
match command_data {
7373
CheckCommandData::CheckManifestJson(cmd) => {
7474
crate::cmd::cmd_check::cmd_check_manifest_json::execute_cmd(
7575
tman_config,
76-
tman_internal_config,
76+
tman_metadata,
7777
cmd,
7878
out,
7979
)
@@ -82,7 +82,7 @@ pub async fn execute_cmd(
8282
CheckCommandData::CheckPropertyJson(cmd) => {
8383
crate::cmd::cmd_check::cmd_check_property_json::execute_cmd(
8484
tman_config,
85-
tman_internal_config,
85+
tman_metadata,
8686
cmd,
8787
out,
8888
)

core/src/ten_manager/src/cmd/cmd_create.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use ten_rust::pkg_info::{
1919
};
2020

2121
use crate::{
22-
config::{internal::TmanInternalConfig, TmanConfig},
22+
config::{metadata::TmanMetadata, TmanConfig},
2323
create::create_pkg_in_path,
2424
output::TmanOutput,
2525
version_utils::parse_pkg_name_version_req,
@@ -154,8 +154,8 @@ pub fn parse_sub_cmd(sub_cmd_args: &ArgMatches) -> Result<CreateCommand> {
154154
}
155155

156156
pub async fn execute_cmd(
157-
tman_config: Arc<TmanConfig>,
158-
_tman_internal_config: Arc<TmanInternalConfig>,
157+
tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
158+
_tman_metadata: Arc<tokio::sync::RwLock<TmanMetadata>>,
159159
command_data: CreateCommand,
160160
out: Arc<Box<dyn TmanOutput>>,
161161
) -> Result<()> {
@@ -166,7 +166,7 @@ pub async fn execute_cmd(
166166
.context("Failed to get current working directory")?;
167167

168168
create_pkg_in_path(
169-
&tman_config,
169+
tman_config,
170170
&cwd,
171171
&command_data.pkg_type,
172172
&command_data.pkg_name,

core/src/ten_manager/src/cmd/cmd_delete.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use semver::Version;
1616

1717
use ten_rust::pkg_info::pkg_type::PkgType;
1818

19-
use crate::config::internal::TmanInternalConfig;
19+
use crate::config::is_verbose;
20+
use crate::config::metadata::TmanMetadata;
2021
use crate::output::TmanOutput;
2122
use crate::{config::TmanConfig, registry::delete_package};
2223

@@ -77,12 +78,12 @@ pub fn parse_sub_cmd(
7778
}
7879

7980
pub async fn execute_cmd(
80-
tman_config: Arc<TmanConfig>,
81-
_tman_internal_config: Arc<TmanInternalConfig>,
81+
tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
82+
_tman_metadata: Arc<tokio::sync::RwLock<TmanMetadata>>,
8283
command_data: DeleteCommand,
8384
out: Arc<Box<dyn TmanOutput>>,
8485
) -> Result<()> {
85-
if tman_config.verbose {
86+
if is_verbose(tman_config.clone()).await {
8687
out.normal_line("Executing delete command");
8788
out.normal_line(&format!("{:?}", command_data));
8889
}

core/src/ten_manager/src/cmd/cmd_designer.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
// Licensed under the Apache License, Version 2.0, with certain conditions.
55
// Refer to the "LICENSE" file in the root directory for more information.
66
//
7-
use std::{
8-
collections::HashMap,
9-
path::Path,
10-
sync::{Arc, RwLock},
11-
};
7+
use std::{collections::HashMap, path::Path, sync::Arc};
128

139
use actix_cors::Cors;
1410
use actix_web::{http::header, web, App, HttpServer};
@@ -17,7 +13,7 @@ use clap::{value_parser, Arg, ArgMatches, Command};
1713
use console::Emoji;
1814

1915
use crate::{
20-
config::{internal::TmanInternalConfig, TmanConfig},
16+
config::{is_verbose, metadata::TmanMetadata, TmanConfig},
2117
constants::DESIGNER_BACKEND_DEFAULT_PORT,
2218
designer::{configure_routes, frontend::get_frontend_asset, DesignerState},
2319
fs::{check_is_app_folder, get_cwd},
@@ -85,12 +81,12 @@ pub fn parse_sub_cmd(
8581
}
8682

8783
pub async fn execute_cmd(
88-
tman_config: Arc<TmanConfig>,
89-
tman_internal_config: Arc<TmanInternalConfig>,
84+
tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
85+
tman_metadata: Arc<tokio::sync::RwLock<TmanMetadata>>,
9086
command_data: DesignerCommand,
9187
out: Arc<Box<dyn TmanOutput>>,
9288
) -> Result<()> {
93-
if tman_config.verbose {
89+
if is_verbose(tman_config.clone()).await {
9490
out.normal_line("Executing designer command");
9591
out.normal_line(&format!("{:?}", command_data));
9692
out.normal_line(&format!("{:?}", tman_config));
@@ -115,13 +111,13 @@ pub async fn execute_cmd(
115111
}
116112
};
117113

118-
let state = Arc::new(RwLock::new(DesignerState {
114+
let state = Arc::new(DesignerState {
119115
tman_config,
120-
tman_internal_config,
116+
tman_metadata,
121117
out: Arc::new(Box::new(TmanOutputCli)),
122118
pkgs_cache: tokio::sync::RwLock::new(HashMap::new()),
123119
graphs_cache: tokio::sync::RwLock::new(HashMap::new()),
124-
}));
120+
});
125121

126122
let mut actual_base_dir_opt: Option<String> = Some(base_dir);
127123

@@ -138,11 +134,8 @@ pub async fn execute_cmd(
138134
}
139135

140136
if let Some(actual_base_dir) = actual_base_dir_opt.as_ref() {
141-
// =-=-=
142-
let state_write = state.write().unwrap();
143-
144-
let mut pkgs_cache = state_write.pkgs_cache.write().await;
145-
let mut graphs_cache = state_write.graphs_cache.write().await;
137+
let mut pkgs_cache = state.pkgs_cache.write().await;
138+
let mut graphs_cache = state.graphs_cache.write().await;
146139

147140
get_all_pkgs_in_app(
148141
&mut pkgs_cache,

core/src/ten_manager/src/cmd/cmd_fetch.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ten_rust::pkg_info::{
2020
};
2121

2222
use crate::{
23-
config::{internal::TmanInternalConfig, TmanConfig},
23+
config::{metadata::TmanMetadata, TmanConfig},
2424
output::TmanOutput,
2525
package_file::unpackage::extract_and_process_tpkg_file,
2626
registry::{get_package, get_package_list},
@@ -121,8 +121,8 @@ pub fn parse_sub_cmd(sub_cmd_args: &ArgMatches) -> Result<FetchCommand> {
121121
}
122122

123123
pub async fn execute_cmd(
124-
tman_config: Arc<TmanConfig>,
125-
_tman_internal_config: Arc<TmanInternalConfig>,
124+
tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
125+
_tman_metadata: Arc<tokio::sync::RwLock<TmanMetadata>>,
126126
command_data: FetchCommand,
127127
out: Arc<Box<dyn TmanOutput>>,
128128
) -> Result<()> {
@@ -135,7 +135,7 @@ pub async fn execute_cmd(
135135

136136
// Query the package from the registry.
137137
let mut found_packages = get_package_list(
138-
&tman_config,
138+
tman_config.clone(),
139139
Some(command_data.pkg_type),
140140
Some(command_data.pkg_name.clone()),
141141
Some(command_data.version_req.clone()),
@@ -157,7 +157,7 @@ pub async fn execute_cmd(
157157

158158
let mut temp_file = tempfile::NamedTempFile::new()?;
159159
get_package(
160-
tman_config.clone(),
160+
tman_config,
161161
&package.basic_info.type_and_name.pkg_type,
162162
&package.basic_info.type_and_name.name,
163163
&package.basic_info.version,

core/src/ten_manager/src/cmd/cmd_install.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use ten_rust::pkg_info::{
3434
};
3535

3636
use crate::{
37-
config::{internal::TmanInternalConfig, TmanConfig},
37+
config::{is_verbose, metadata::TmanMetadata, TmanConfig},
3838
constants::{APP_DIR_IN_DOT_TEN_DIR, DOT_TEN_DIR},
3939
dep_and_candidate::get_all_candidates_from_deps,
4040
fs::{check_is_addon_folder, find_nearest_app_dir},
@@ -282,7 +282,7 @@ ten_package("app_for_standalone") {
282282
}
283283

284284
fn prepare_basic_standalone_app_dir(
285-
_tman_config: Arc<TmanConfig>,
285+
_tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
286286
extension_dir: &Path,
287287
) -> Result<PathBuf> {
288288
let dot_ten_app_dir =
@@ -314,7 +314,7 @@ fn prepare_basic_standalone_app_dir(
314314

315315
/// Prepare the `.ten/app/` folder in the extension standalone mode.
316316
async fn prepare_standalone_app_dir(
317-
tman_config: Arc<TmanConfig>,
317+
tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
318318
extension_dir: &Path,
319319
) -> Result<PathBuf> {
320320
let dot_ten_app_dir =
@@ -330,7 +330,7 @@ async fn prepare_standalone_app_dir(
330330

331331
/// Path logic for standalone mode and non-standalone mode.
332332
async fn determine_app_dir_to_work_with(
333-
tman_config: Arc<TmanConfig>,
333+
tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
334334
standalone: bool,
335335
specified_cwd: &Path,
336336
) -> Result<PathBuf> {
@@ -356,12 +356,12 @@ async fn determine_app_dir_to_work_with(
356356
}
357357

358358
pub async fn execute_cmd(
359-
tman_config: Arc<TmanConfig>,
360-
_tman_internal_config: Arc<TmanInternalConfig>,
359+
tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
360+
_tman_metadata: Arc<tokio::sync::RwLock<TmanMetadata>>,
361361
command_data: InstallCommand,
362362
out: Arc<Box<dyn TmanOutput>>,
363363
) -> Result<()> {
364-
if tman_config.verbose {
364+
if is_verbose(tman_config.clone()).await {
365365
out.normal_line("Executing install command");
366366
out.normal_line(&format!("command_data: {:?}", command_data));
367367
out.normal_line(&format!("tman_config: {:?}", tman_config));
@@ -446,7 +446,8 @@ pub async fn execute_cmd(
446446
tman_config.clone(),
447447
&app_dir_to_work_with,
448448
out.clone(),
449-
)?;
449+
)
450+
.await?;
450451

451452
out.normal_line(&format!(
452453
"{} Filter compatible packages...",
@@ -459,7 +460,8 @@ pub async fn execute_cmd(
459460
&mut all_compatible_installed_pkgs,
460461
&command_data.support,
461462
out.clone(),
462-
);
463+
)
464+
.await?;
463465

464466
if command_data.local_path.is_some() {
465467
// tman install <local_path>
@@ -630,22 +632,23 @@ from manifest-lock.json...",
630632
&all_candidates,
631633
locked_pkgs.as_ref(),
632634
out.clone(),
633-
)?;
635+
)
636+
.await?;
634637

635638
// If there are answers are found, print out all the answers.
636-
if tman_config.verbose {
639+
if is_verbose(tman_config.clone()).await {
637640
out.normal_line("\n");
638641
out.normal_line("Result:");
639642
}
640643

641644
if let Some(ref usable_model) = usable_model {
642645
for result in usable_model {
643-
if tman_config.verbose {
646+
if is_verbose(tman_config.clone()).await {
644647
out.normal_line(&format!(" {:?}", result));
645648
}
646649
}
647650
}
648-
if tman_config.verbose {
651+
if is_verbose(tman_config.clone()).await {
649652
out.normal_line("");
650653
}
651654

@@ -676,7 +679,7 @@ from manifest-lock.json...",
676679
out.clone(),
677680
);
678681

679-
if has_conflict && !tman_config.assume_yes {
682+
if has_conflict && !tman_config.read().await.assume_yes {
680683
if out.is_interactive() {
681684
// "y" for continuing to install, "n" for stopping.
682685
let ans = Confirm::new(

core/src/ten_manager/src/cmd/cmd_modify/cmd_modify_graph.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use ten_rust::{
1616

1717
use crate::{
1818
cmd::cmd_modify::jq_util::jq_run,
19-
config::{internal::TmanInternalConfig, TmanConfig},
19+
config::{metadata::TmanMetadata, TmanConfig},
2020
output::TmanOutput,
2121
};
2222

@@ -87,8 +87,8 @@ pub fn parse_sub_cmd(sub_cmd_args: &ArgMatches) -> Result<ModifyGraphCommand> {
8787
}
8888

8989
pub async fn execute_cmd(
90-
_tman_config: Arc<TmanConfig>,
91-
_tman_internal_config: Arc<TmanInternalConfig>,
90+
_tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
91+
_tman_metadata: Arc<tokio::sync::RwLock<TmanMetadata>>,
9292
command_data: ModifyGraphCommand,
9393
out: Arc<Box<dyn TmanOutput>>,
9494
) -> Result<()> {

core/src/ten_manager/src/cmd/cmd_modify/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use anyhow::Result;
1313
use clap::{ArgMatches, Command};
1414

1515
use crate::{
16-
config::{internal::TmanInternalConfig, TmanConfig},
16+
config::{metadata::TmanMetadata, TmanConfig},
1717
output::TmanOutput,
1818
};
1919

@@ -47,16 +47,16 @@ pub fn parse_sub_cmd(sub_cmd_args: &ArgMatches) -> Result<ModifyCommandData> {
4747
}
4848

4949
pub async fn execute_cmd(
50-
tman_config: Arc<TmanConfig>,
51-
tman_internal_config: Arc<TmanInternalConfig>,
50+
tman_config: Arc<tokio::sync::RwLock<TmanConfig>>,
51+
tman_metadata: Arc<tokio::sync::RwLock<TmanMetadata>>,
5252
command_data: ModifyCommandData,
5353
out: Arc<Box<dyn TmanOutput>>,
5454
) -> Result<()> {
5555
match command_data {
5656
ModifyCommandData::ModifyGraph(cmd) => {
5757
crate::cmd::cmd_modify::cmd_modify_graph::execute_cmd(
5858
tman_config,
59-
tman_internal_config,
59+
tman_metadata,
6060
cmd,
6161
out,
6262
)

0 commit comments

Comments
 (0)