-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tman check manifest-json & check property-json command (#447)
- Loading branch information
Showing
9 changed files
with
382 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
core/src/ten_manager/src/cmd/cmd_check/cmd_check_manifest_json.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Copyright © 2024 Agora | ||
// This file is part of TEN Framework, an open source project. | ||
// Licensed under the Apache License, Version 2.0, with certain conditions. | ||
// Refer to the "LICENSE" file in the root directory for more information. | ||
// | ||
use anyhow::Result; | ||
use clap::{Arg, ArgMatches, Command}; | ||
use console::Emoji; | ||
use ten_rust::json_schema::ten_validate_manifest_json_string; | ||
|
||
use crate::{config::TmanConfig, utils::read_file_to_string}; | ||
|
||
#[derive(Debug)] | ||
pub struct CheckManifestJsonCommand { | ||
pub path: String, | ||
} | ||
|
||
pub fn create_sub_cmd(_args_cfg: &crate::cmd_line::ArgsCfg) -> Command { | ||
Command::new("manifest-json") | ||
.about( | ||
"Check if the manifest.json is valid according to the json schema", | ||
) | ||
.arg( | ||
Arg::new("PATH") | ||
.long("path") | ||
.help("The file path of manifest.json to be checked") | ||
.required(true) | ||
.num_args(1), | ||
) | ||
} | ||
|
||
pub fn parse_sub_cmd(sub_cmd_args: &ArgMatches) -> CheckManifestJsonCommand { | ||
let cmd = CheckManifestJsonCommand { | ||
path: sub_cmd_args.get_one::<String>("PATH").cloned().unwrap(), | ||
}; | ||
|
||
cmd | ||
} | ||
|
||
pub async fn execute_cmd( | ||
_tman_config: &TmanConfig, | ||
command_data: CheckManifestJsonCommand, | ||
) -> Result<()> { | ||
let content = read_file_to_string(&command_data.path)?; | ||
match ten_validate_manifest_json_string(&content) { | ||
Ok(_) => { | ||
println!("{} Conforms to JSON schema.", Emoji("👍", "Passed")); | ||
Ok(()) | ||
} | ||
Err(e) => Err(e), | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
core/src/ten_manager/src/cmd/cmd_check/cmd_check_property_json.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Copyright © 2024 Agora | ||
// This file is part of TEN Framework, an open source project. | ||
// Licensed under the Apache License, Version 2.0, with certain conditions. | ||
// Refer to the "LICENSE" file in the root directory for more information. | ||
// | ||
use anyhow::Result; | ||
use clap::{Arg, ArgMatches, Command}; | ||
use console::Emoji; | ||
use ten_rust::json_schema::ten_validate_property_json_string; | ||
|
||
use crate::utils::read_file_to_string; | ||
|
||
#[derive(Debug)] | ||
pub struct CheckPropertyJsonCommand { | ||
pub path: String, | ||
} | ||
|
||
pub fn create_sub_cmd(_args_cfg: &crate::cmd_line::ArgsCfg) -> Command { | ||
Command::new("property-json") | ||
.about( | ||
"Check if the property.json is valid according to the json schema", | ||
) | ||
.arg( | ||
Arg::new("PATH") | ||
.long("path") | ||
.help("The file path of property.json to be checked") | ||
.required(true) | ||
.num_args(1), | ||
) | ||
} | ||
|
||
pub fn parse_sub_cmd(sub_cmd_args: &ArgMatches) -> CheckPropertyJsonCommand { | ||
let cmd = CheckPropertyJsonCommand { | ||
path: sub_cmd_args.get_one::<String>("PATH").cloned().unwrap(), | ||
}; | ||
|
||
cmd | ||
} | ||
|
||
pub async fn execute_cmd( | ||
_tman_config: &crate::config::TmanConfig, | ||
command_data: CheckPropertyJsonCommand, | ||
) -> Result<()> { | ||
let content = read_file_to_string(&command_data.path)?; | ||
match ten_validate_property_json_string(&content) { | ||
Ok(_) => { | ||
println!("{} Conforms to JSON schema.", Emoji("👍", "Passed")); | ||
Ok(()) | ||
} | ||
Err(e) => Err(e), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.