From c4ffb83be40e09d12a8a18d7910bb7043adf5a5f Mon Sep 17 00:00:00 2001 From: Diana Date: Mon, 23 Oct 2023 23:34:12 -0700 Subject: [PATCH] Refactor code to fix linting --- src/controller/init/submodules/mod.rs | 2 +- src/controller/mod.rs | 4 ++-- src/helpers/docker/docker_compose/file.rs | 3 +-- src/helpers/filesystem/dir.rs | 7 ++----- src/helpers/filesystem/path.rs | 6 ++---- src/main.rs | 7 +++---- src/models/project/mod.rs | 2 +- 7 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/controller/init/submodules/mod.rs b/src/controller/init/submodules/mod.rs index 5c75946..9b66d3a 100644 --- a/src/controller/init/submodules/mod.rs +++ b/src/controller/init/submodules/mod.rs @@ -28,7 +28,7 @@ pub fn get_submodule_paths() -> Vec<(String, String, bool)> { .collect::>(); // return the submodule paths - return map_dirs(sub_module_paths); + map_dirs(sub_module_paths) } // check_if_submodule_init_run_needed(sub_module_paths: Vec<(String, String, bool)>) diff --git a/src/controller/mod.rs b/src/controller/mod.rs index 53e57df..7127b20 100644 --- a/src/controller/mod.rs +++ b/src/controller/mod.rs @@ -27,8 +27,8 @@ pub fn run(command: String, args: &[String]) { "status" => status(args), "-v" | "--version" => { // print the version number of the program - print!("Tools Version: {}\n", env!("CARGO_PKG_VERSION")); - print!("Project Version: {}\n", CONFIG.get_version()); + println!("Tools Version: {}", env!("CARGO_PKG_VERSION")); + println!("Project Version: {}", CONFIG.get_version()); } _ => { helpers::help::main_help::print_help(); diff --git a/src/helpers/docker/docker_compose/file.rs b/src/helpers/docker/docker_compose/file.rs index 93f3a27..3f719c9 100644 --- a/src/helpers/docker/docker_compose/file.rs +++ b/src/helpers/docker/docker_compose/file.rs @@ -13,8 +13,7 @@ fn get_path_to_docker_compose() -> PathBuf { let raw_project_path = &CONFIG.project_path; let project_path = PathBuf::from(raw_project_path); let docker_compose_filename = &CONFIG.docker_compose; - let docker_compose_path = append_path(&project_path, docker_compose_filename); - docker_compose_path + append_path(&project_path, docker_compose_filename) } /// ## get_docker_compose_file() -> DockerCompose diff --git a/src/helpers/filesystem/dir.rs b/src/helpers/filesystem/dir.rs index 5adc23a..c5b196a 100644 --- a/src/helpers/filesystem/dir.rs +++ b/src/helpers/filesystem/dir.rs @@ -93,14 +93,11 @@ pub fn recursively_delete_directory(path: &str) -> bool { /// - String - The absolute path of the directory pub fn get_absolute_path(path: &str) -> String { // check if the path starts with root, and if not, prepend the project path - let path = if path.starts_with("/") { + if path.starts_with("/") { path.to_string() } else { format!("{}/{}", CONFIG.project_path, path) - }; - - // return the absolute path without checking if it exists - path + } } /// ## map_dirs(list_dirs: Vec) -> Vec<(String, String, bool)> diff --git a/src/helpers/filesystem/path.rs b/src/helpers/filesystem/path.rs index 90c0736..82a5ff7 100644 --- a/src/helpers/filesystem/path.rs +++ b/src/helpers/filesystem/path.rs @@ -8,8 +8,7 @@ /// - PathBuf - The path to the file or directory #[allow(dead_code)] pub fn get_path(path: &str) -> std::path::PathBuf { - let path = std::fs::canonicalize(path).unwrap(); - path + std::fs::canonicalize(path).unwrap() } /// ## append_path(base_path: &PathBuf, file: &str) @@ -22,6 +21,5 @@ pub fn get_path(path: &str) -> std::path::PathBuf { /// ## Returns /// - PathBuf - The path to the file or directory pub fn append_path(base_path: &std::path::PathBuf, file: &str) -> std::path::PathBuf { - let file_path = base_path.join(file); - file_path + base_path.join(file) } diff --git a/src/main.rs b/src/main.rs index 3bbcb60..736241b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,19 +6,18 @@ mod controller; mod helpers; mod models; -pub static CONFIG: Lazy = Lazy::new(|| config::app_config::get_config()); +pub static CONFIG: Lazy = Lazy::new(config::app_config::get_config); /// ## main() /// This function is the entry point for the program fn main() { // if the config project path is not the current directory, // warn the user that this may cause unexpected behavior - if CONFIG.project_path - != std::env::current_dir() + if *CONFIG.project_path + != *std::env::current_dir() .expect("Couldn't get current directory") .to_str() .unwrap() - .to_string() { println!("WARNING: The project path in the configuration file is not the current directory. This may cause unexpected behavior."); } diff --git a/src/models/project/mod.rs b/src/models/project/mod.rs index 8538333..0e43024 100644 --- a/src/models/project/mod.rs +++ b/src/models/project/mod.rs @@ -12,7 +12,7 @@ pub struct Project { pub description: String, // required - This is the description of the project that serves as the description of the repository pub languages: Option>, // optional - This is a list of programming languages used in the service pub frameworks: Option>, // optional - This is the framework the service is developed - pub services: Option>>, // required for parent projects, or hierarchical projects - This is the list of services/children in the project + pub services: Option>, // required for parent projects, or hierarchical projects - This is the list of services/children in the project pub repo: Option>, // optional - This is the configuration for the repository pub parent: Option>, // required for hierarchical projects - This is the parent project of the microservice pub from_template: Option, // optional - This indicates if the repository was created from a templates