Skip to content

Commit f1d44e0

Browse files
committed
IDF installed using eim or eclipse can be discovered
parsing function for esp_idf.json file added POSIX discovery mvp updated activation script creation improved export paths in old version discovery added tool_set.json file parsing to the discovery returned the parse_tool_set_config back to working state
1 parent 529ba92 commit f1d44e0

File tree

4 files changed

+351
-26
lines changed

4 files changed

+351
-26
lines changed

src-tauri/src/cli/cli_args.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ pub enum Commands {
6565
},
6666

6767
/// Discover available ESP-IDF versions (not implemented yet)
68-
Discover,
68+
Discover {
69+
#[arg(help = "Discover available ESP-IDF versions and imports them")]
70+
path: Option<String>,
71+
},
6972

7073
/// Remove specific ESP-IDF version
7174
Remove {

src-tauri/src/cli/mod.rs

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::path::Path;
12
use std::path::PathBuf;
23

34
use anyhow::Context;
@@ -11,6 +12,9 @@ use helpers::generic_select;
1112
use idf_im_lib::get_log_directory;
1213
use idf_im_lib::idf_config::IdfConfig;
1314
use idf_im_lib::settings::Settings;
15+
use idf_im_lib::utils::find_by_name_and_extension;
16+
use idf_im_lib::utils::parse_esp_idf_json;
17+
use idf_im_lib::utils::try_import_existing_idf;
1418
use idf_im_lib::version_manager::remove_single_idf_version;
1519
use idf_im_lib::version_manager::select_idf_version;
1620
use log::debug;
@@ -316,9 +320,73 @@ pub async fn run_cli(cli: Cli) -> anyhow::Result<()> {
316320
}
317321
}
318322
}
319-
Commands::Discover => {
323+
Commands::Discover {path } => {
320324
info!("Discovering available versions... (This can take couple of minutes)");
321-
let idf_dirs = idf_im_lib::version_manager::find_esp_idf_folders("/tmp");
325+
// TODO: add warning and confirmation
326+
let path = path.unwrap_or_else(|| {
327+
let default_path = match std::env::consts::OS {
328+
"windows" => {
329+
"C:\\".to_string()
330+
}
331+
_ => {
332+
"/".to_string()
333+
}
334+
};
335+
336+
337+
debug!("No path provided, using default: {}", default_path);
338+
default_path
339+
});
340+
// first parse existing esp_idf.json (using parse_esp_idf_json) || previous VSCode installations
341+
info!("Searching for esp_idf.json files...");
342+
let search_patch = Path::new(&path);
343+
let esp_idf_json_path = find_by_name_and_extension(
344+
search_patch,
345+
"esp_idf",
346+
"json",
347+
);
348+
if esp_idf_json_path.is_empty() {
349+
info!("No esp_idf.json found");
350+
} else {
351+
info!("Found {} esp_idf.json files:", esp_idf_json_path.len());
352+
}
353+
for path in esp_idf_json_path {
354+
info!("- {} ", &path);
355+
match parse_esp_idf_json(&path) {
356+
Ok(_) => {
357+
info!("Parsed config: {:?}", path);
358+
}
359+
Err(err) => {
360+
info!("Failed to parse esp_idf.json: {}", err);
361+
}
362+
}
363+
}
364+
// second try to find tool_set_config.json (using parse_tool_set_config) || previous Eclipse installations
365+
info!("Searching for tool_set_config.json files...");
366+
let tool_set_config_path = find_by_name_and_extension(
367+
search_patch,
368+
"tool_set_config",
369+
"json",
370+
);
371+
if tool_set_config_path.is_empty() {
372+
info!("No tool_set_config.json found");
373+
} else {
374+
info!("Found {} tool_set_config.json files:", tool_set_config_path.len());
375+
}
376+
for path in tool_set_config_path {
377+
info!("- {} ", &path);
378+
match idf_im_lib::utils::parse_tool_set_config(&path) {
379+
Ok(_) => {
380+
info!("Parsed config: {:?}", path);
381+
}
382+
Err(err) => {
383+
info!("Failed to parse tool_set_config.json: {}", err);
384+
}
385+
}
386+
}
387+
// third try to find IDF directories (using find_esp_idf_folders) || previous instalation from cli
388+
info!("Searching for any other IDF directories...");
389+
let idf_dirs = idf_im_lib::version_manager::find_esp_idf_folders(&path);
322390
if idf_dirs.is_empty() {
323391
info!("No IDF directories found");
324392
} else {
@@ -349,6 +417,17 @@ pub async fn run_cli(cli: Cli) -> anyhow::Result<()> {
349417
}
350418

351419
}
420+
// TODO: ask the user to select which IDFs to add
421+
for p in paths_to_add {
422+
match try_import_existing_idf(&p) {
423+
Ok(_) => {
424+
info!("Added to config: {}", p);
425+
}
426+
Err(err) => {
427+
error!("Failed to add: {} - reason :{}",p, err);
428+
}
429+
}
430+
}
352431
Ok(())
353432
}
354433
Commands::Import { path } => match path {

src-tauri/src/lib/idf_config.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ impl IdfConfig {
260260
}
261261
}
262262

263-
pub fn is_path_in_config(self, path:String) -> bool {
264-
self.idf_installed.iter().find(|i| i.path == path).is_some()
265-
}
266263
}
267264

268265
pub fn parse_idf_config<P: AsRef<Path>>(path: P) -> Result<IdfConfig> {

0 commit comments

Comments
 (0)