diff --git a/mepo.d/cmdline/parser.py b/mepo.d/cmdline/parser.py index 131fa58..86917aa 100644 --- a/mepo.d/cmdline/parser.py +++ b/mepo.d/cmdline/parser.py @@ -53,9 +53,21 @@ def __clone(self): description = "Clone repositories.") clone.add_argument( 'repo_url', + metavar = 'URL', nargs = '?', default = None, help = 'URL to clone') + clone.add_argument( + 'directory', + nargs = '?', + default = None, + help = "Directory to clone into (Only allowed with URL!)") + clone.add_argument( + '--branch','-b', + metavar = 'name', + nargs = '?', + default = None, + help = 'Branch/tag of URL to initially clone (Only allowed with URL!)') clone.add_argument( '--config', metavar = 'config-file', diff --git a/mepo.d/command/clone/clone.py b/mepo.d/command/clone/clone.py index 486cf82..51722a8 100644 --- a/mepo.d/command/clone/clone.py +++ b/mepo.d/command/clone/clone.py @@ -9,17 +9,25 @@ def run(args): + # This protects against someone using branch without a URL + if args.branch and not args.repo_url: + raise RuntimeError("The branch argument can only be used with a URL") + if args.repo_url: p = urlparse(args.repo_url) last_url_node = p.path.rsplit('/')[-1] url_suffix = pathlib.Path(last_url_node).suffix - if url_suffix == '.git': - git_url_directory = pathlib.Path(last_url_node).stem + if args.directory: + local_clone(args.repo_url,args.branch,args.directory) + os.chdir(args.directory) else: - git_url_directory = last_url_node + if url_suffix == '.git': + git_url_directory = pathlib.Path(last_url_node).stem + else: + git_url_directory = last_url_node - local_clone(args.repo_url) - os.chdir(git_url_directory) + local_clone(args.repo_url,args.branch) + os.chdir(git_url_directory) # This tries to read the state and if not, calls init, # loops back, and reads the state @@ -45,7 +53,11 @@ def print_clone_info(comp, name_width): ver_name_type = '({}) {}'.format(comp.version.type, comp.version.name) print('{:<{width}} | {: