Skip to content

Commit

Permalink
[feat] Print warning for addition of more than 50 projects
Browse files Browse the repository at this point in the history
(rebased by @mriehl for commit signing)
  • Loading branch information
Nigel-Lee Volkmann authored and mriehl committed Jun 9, 2021
1 parent 8b5bac5 commit e9c1457
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,16 @@ For further information please have a look at our README https://github.com/broc
.arg(Arg::with_name("PROJECT_NAME").value_name("PROJECT_NAME").index(1).required(true)),
)
.subcommand(SubCommand::with_name("projectile").about("Write projectile bookmarks"))
.subcommand(SubCommand::with_name("intellij").about("Add projects to intellijs list of recent projects"))
.subcommand(
SubCommand::with_name("intellij")
.about("Add projects to intellijs list of recent projects")
.arg(
Arg::with_name("no-warn")
.long("no-warn")
.short("-n")
.help("Disables warning message if more than 50 projects would be added"),
),
)
.subcommand(
SubCommand::with_name("ls").about("List projects").arg(
Arg::with_name("tag")
Expand Down
16 changes: 15 additions & 1 deletion src/intellij/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io::Write;
use std::option::Option::Some;
use std::path::PathBuf;

pub fn intellij(maybe_config: Result<Config, AppError>, logger: &Logger) -> Result<(), AppError> {
pub fn intellij(maybe_config: Result<Config, AppError>, logger: &Logger, warn: bool) -> Result<(), AppError> {
let config: Config = maybe_config?;
let projects_paths: Vec<PathBuf> = config.projects.iter().map(|(_, p)| config.actual_path_to_project(p, logger)).collect();
let recent_projects_candidates = get_recent_projects_candidates()?;
Expand All @@ -26,6 +26,13 @@ pub fn intellij(maybe_config: Result<Config, AppError>, logger: &Logger) -> Resu
}
writeln!(writer, "</map></option></component></application>")?;
}

let number_of_projects = projects_paths.len();

if number_of_projects > 50 && warn {
print_number_of_projects_warning(number_of_projects)
}

Ok(())
}

Expand All @@ -49,3 +56,10 @@ fn get_recent_projects_candidates() -> Result<Vec<PathBuf>, AppError> {
}
Ok(recent_projects_candidates)
}

fn print_number_of_projects_warning(number_of_projects: usize) {
print!("WARNING: {} ", number_of_projects);
print!("projects were added to the list. Intellij only lists 50 projects by default. You can change this in Intellij by going to ");
print!(r#""Help -> Find Action -> Registry -> ide.max.recent.projects" "#);
println!("and adjusting the number accordingly. A high number is recommended since it won't do any harm to the system.");
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn _main() -> i32 {
&subcommand_logger,
),
"projectile" => projectile::projectile(config, &subcommand_logger),
"intellij" => intellij::intellij(config, &subcommand_logger),
"intellij" => intellij::intellij(config, &subcommand_logger, !subcommand_matches.is_present("no-warn")),
"print-path" => project::print_path(
config,
subcommand_matches.value_of("PROJECT_NAME").expect("argument required by clap.rs"),
Expand Down

0 comments on commit e9c1457

Please sign in to comment.