@@ -178,7 +178,6 @@ def is_curdir_inside_path(base_path):
178178 self .local_repo = (meta ['alias' ], meta ['uid' ])
179179 # Create a Repo object and add it to the list
180180 repos_list .append (Repo (path = repo_path , meta = meta ))
181-
182181 return repos_list
183182
184183 def load_repos (self ):
@@ -1007,20 +1006,73 @@ def unregister_repo(self, repo_path):
10071006 return {'return' : 0 }
10081007
10091008 def find (self , run_args ):
1010- repo = run_args .get ('item' , run_args .get ('artifact' ))
1011- repo_split = repo .split ("," )
1012- if len (repo_split ) > 1 :
1013- repo_uid = repo_split [1 ]
1014- repo_name = repo_split [0 ]
1015-
1016- lst = []
1017- for i in self .repos :
1018- if repo_uid and i .meta ['uid' ] == repo_uid :
1019- lst .append (i )
1020- elif repo_name == i .meta ['alias' ]:
1021- lst .append (i )
1009+ try :
1010+ # Get repos_list using the existing method
1011+ repos_list = self .load_repos_and_meta ()
1012+ if (run_args .get ('item' , run_args .get ('artifact' ))):
1013+ repo = run_args .get ('item' , run_args .get ('artifact' ))
1014+ else :
1015+ repo = run_args .get ('repo' , run_args .get ('item' , run_args .get ('artifact' )))
1016+
1017+ # Check if repo is None or empty
1018+ if not repo :
1019+ return {"return" : 1 , "error" : "Please enter a Repo Alias, Repo UID, or Repo URL in one of the following formats:\n "
1020+ "- <repo_owner>@<repos_name>\n "
1021+ "- <repo_url>\n "
1022+ "- <repo_uid>\n "
1023+ "- <repo_alias>\n "
1024+ "- <repo_alias>,<repo_uid>" }
1025+
1026+ # Handle the different repo input formats
1027+ repo_name = None
1028+ repo_uid = None
1029+
1030+ # Check if the repo is in the format of a repo UID (alphanumeric string)
1031+ if self .is_uid (repo ):
1032+ repo_uid = repo
1033+ if "," in repo :
1034+ repo_split = repo .split ("," )
1035+ repo_name = repo_split [0 ]
1036+ if len (repo_split ) > 1 :
1037+ repo_uid = repo_split [1 ]
1038+ elif "@" in repo :
1039+ repo_name = repo
1040+ elif "github.com" in repo :
1041+ result = self .github_url_to_user_repo_format (repo )
1042+ if result ["return" ] == 0 :
1043+ repo_name = result ["value" ]
1044+ else :
1045+ return result
1046+
1047+ # Check if repo_name exists in repos.json
1048+ matched_repo_path = None
1049+ for repo_obj in repos_list :
1050+ if repo_name and repo_name == os .path .basename (repo_obj .path ) :
1051+ matched_repo_path = repo_obj
1052+ break
1053+
1054+ # Search through self.repos for matching repos
1055+ lst = []
1056+ for i in self .repos :
1057+ if repo_uid and i .meta ['uid' ] == repo_uid :
1058+ lst .append (i )
1059+ elif repo_name == i .meta ['alias' ]:
1060+ lst .append (i )
1061+ elif self .is_uid (repo ) and not any (i .meta ['uid' ] == repo_uid for i in self .repos ):
1062+ return {"return" : 1 , "error" : f"No repository with UID: '{ repo_uid } ' was found" }
1063+ elif "," in repo and not matched_repo_path and not any (i .meta ['uid' ] == repo_uid for i in self .repos ) and not any (i .meta ['alias' ] == repo_name for i in self .repos ):
1064+ return {"return" : 1 , "error" : f"No repository with alias: '{ repo_name } ' and UID: '{ repo_uid } ' was found" }
1065+ elif not matched_repo_path and not any (i .meta ['alias' ] == repo_name for i in self .repos ) and not any (i .meta ['uid' ] == repo_uid for i in self .repos ):
1066+ return {"return" : 1 , "error" : f"No repository with alias: '{ repo_name } ' was found" }
10221067
1023- return {'return' : 0 , 'list' : lst }
1068+ # Append the matched repo path
1069+ if (len (lst )== 0 ):
1070+ lst .append (matched_repo_path )
1071+
1072+ return {'return' : 0 , 'list' : lst }
1073+ except Exception as e :
1074+ # Return error message if any exception occurs
1075+ return {"return" : 1 , "error" : str (e )}
10241076
10251077 def github_url_to_user_repo_format (self , url ):
10261078 """
@@ -1462,14 +1514,14 @@ def mlcr():
14621514
14631515def process_console_output (res , target , action , run_args ):
14641516 if action == "find" :
1517+ if "list" not in res :
1518+ return # Exit function if there's an error
14651519 if len (res ['list' ]) == 0 :
14661520 logger .warn (f"""No { target } entry found for the specified tags: { run_args ['tags' ]} !""" )
14671521 else :
14681522 for item in res ['list' ]:
14691523 logger .info (f"""Item path: { item .path } """ )
14701524
1471-
1472-
14731525# Main CLI function
14741526def main ():
14751527 parser = argparse .ArgumentParser (prog = 'mlc' , description = 'A CLI tool for managing repos, scripts, and caches.' )
@@ -1511,9 +1563,8 @@ def main():
15111563 run_args = res ['args_dict' ]
15121564 if hasattr (args , 'repo' ) and args .repo :
15131565 run_args ['repo' ] = args .repo
1514-
1515-
1516- if args .command in ['pull' , 'rm' , 'add' ]:
1566+
1567+ if args .command in ['pull' , 'rm' , 'add' , 'find' ]:
15171568 if args .target == "repo" :
15181569 run_args ['repo' ] = args .details
15191570
0 commit comments