From 23a91620bb9b40a1b6bdbca605dd3dd2944b0d52 Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Tue, 20 Feb 2024 23:49:18 +0100 Subject: [PATCH] feat: Allow https cloning --- internal/pkg/command/clone.go | 5 +++++ internal/pkg/command/org.go | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/pkg/command/clone.go b/internal/pkg/command/clone.go index 030a6c5..0629dbf 100644 --- a/internal/pkg/command/clone.go +++ b/internal/pkg/command/clone.go @@ -15,6 +15,8 @@ import ( giturls "github.com/whilp/git-urls" ) +var cloneProtocol string + func getCloneCmd() *cobra.Command { cloneCmd := &cobra.Command{ Use: "clone REPO_URL", @@ -29,6 +31,9 @@ func getCloneCmd() *cobra.Command { fmt.Fprintf(CmdOutput, "cd %s \n", dir) }, } + + cloneCmd.Flags().StringVarP(&cloneProtocol, "clone-protocol", "p", "ssh", "Clone protocol (ssh, https)") + return cloneCmd } diff --git a/internal/pkg/command/org.go b/internal/pkg/command/org.go index 9ce71c1..1d5b789 100644 --- a/internal/pkg/command/org.go +++ b/internal/pkg/command/org.go @@ -71,7 +71,14 @@ The credentials are read from the environment variables: logrus.Infof("Found %d repos", len(repos)) for _, repo := range repos { - if _, err := cloneRepo(repo.SSHURL); err != nil { + var cloneURL string + if cloneProtocol == "https" { + cloneURL = repo.CloneURL + } else { + cloneURL = repo.SSHURL + } + + if _, err := cloneRepo(cloneURL); err != nil { if err == ErrDirectoryAlreadyExists || errors.Unwrap(err) == ErrDirectoryAlreadyExists { logrus.Debugf("Skipping existing repo: %s", repo.Name) } else { @@ -86,6 +93,7 @@ The credentials are read from the environment variables: cmd.Flags().BoolVarP(&cloneForks, "forks", "f", false, "Clone forks") cmd.Flags().StringVarP(&typeHint, "type-hint", "t", "", "Add a type hint to the URL to force a specific provider") + cmd.Flags().StringVarP(&cloneProtocol, "clone-protocol", "p", "ssh", "Clone protocol (ssh, https)") return cmd }