1+ use std:: path:: Path ;
12use std:: path:: PathBuf ;
23
34use cli_args:: Cli ;
@@ -10,6 +11,8 @@ use helpers::generic_select;
1011use idf_im_lib:: get_log_directory;
1112use idf_im_lib:: idf_config:: IdfConfig ;
1213use idf_im_lib:: settings:: Settings ;
14+ use idf_im_lib:: utils:: find_by_name_and_extension;
15+ use idf_im_lib:: utils:: parse_esp_idf_json;
1316use idf_im_lib:: utils:: try_import_existing_idf;
1417use idf_im_lib:: version_manager:: remove_single_idf_version;
1518use idf_im_lib:: version_manager:: select_idf_version;
@@ -294,10 +297,48 @@ pub async fn run_cli(cli: Cli) {
294297 }
295298 }
296299 }
297- Commands :: Discover => {
298- // todo: first parse existing esp_idf.json (using parse_esp_idf_json)
300+ Commands :: Discover { path } => {
299301 info ! ( "Discovering available versions... (This can take couple of minutes)" ) ;
300- let idf_dirs = idf_im_lib:: version_manager:: find_esp_idf_folders ( "/" ) ;
302+ // TODO: add warning and confirmation
303+ let path = path. unwrap_or_else ( || {
304+ let default_path = match std:: env:: consts:: OS {
305+ "windows" => {
306+ "C:\\ " . to_string ( )
307+ }
308+ _ => {
309+ "/" . to_string ( )
310+ }
311+ } ;
312+
313+
314+ debug ! ( "No path provided, using default: {}" , default_path) ;
315+ default_path
316+ } ) ;
317+ // first parse existing esp_idf.json (using parse_esp_idf_json)
318+
319+ let search_patch = Path :: new ( & path) ;
320+ let esp_idf_json_path = find_by_name_and_extension (
321+ search_patch,
322+ "esp_idf" ,
323+ "json" ,
324+ ) ;
325+ if esp_idf_json_path. is_empty ( ) {
326+ info ! ( "No esp_idf.json found" ) ;
327+ } else {
328+ info ! ( "Found {} esp_idf.json files:" , esp_idf_json_path. len( ) ) ;
329+ }
330+ for path in esp_idf_json_path {
331+ info ! ( "- {} " , & path) ;
332+ match parse_esp_idf_json ( & path) {
333+ Ok ( _) => {
334+ info ! ( "Parsed config: {:?}" , path) ;
335+ }
336+ Err ( err) => {
337+ info ! ( "Failed to parse esp_idf.json: {}" , err) ;
338+ }
339+ }
340+ }
341+ let idf_dirs = idf_im_lib:: version_manager:: find_esp_idf_folders ( & path) ;
301342 if idf_dirs. is_empty ( ) {
302343 info ! ( "No IDF directories found" ) ;
303344 } else {
0 commit comments