diff --git a/cmd/clone.go b/cmd/clone.go index d59327f..ceb843f 100644 --- a/cmd/clone.go +++ b/cmd/clone.go @@ -11,7 +11,8 @@ import ( ) type cloneOption struct { - ws bool + ws bool + protocol string } // NewCloneCommand returns the clone command @@ -26,6 +27,7 @@ func NewCloneCommand() (cmd *cobra.Command) { flags := cmd.Flags() flags.BoolVarP(&opt.ws, "ws", "", false, "Clone the code into ~/ws/github/org/repo if it is true") + flags.StringVarP(&opt.protocol, "protocol", "p", "https", "The protocol, support: https, ssh, git") return } @@ -39,7 +41,7 @@ func (o *cloneOption) runE(_ *cobra.Command, args []string) (err error) { if !o.ws { output = nil } - args = pkg.ParseShortCode(args, output) + args = pkg.ParseShortCodeWithProtocol(args, o.protocol, output) var targetDir string gitAddress := args[0] diff --git a/pkg/shortcode.go b/pkg/shortcode.go index 1941853..ca59ae1 100644 --- a/pkg/shortcode.go +++ b/pkg/shortcode.go @@ -7,6 +7,11 @@ import ( // ParseShortCode parses a short org/repo to a GitHub URL func ParseShortCode(args []string, output func(string) string) []string { + return ParseShortCodeWithProtocol(args, "https", output) +} + +// ParseShortCodeWithProtocol parses a short org/repo with protocol +func ParseShortCodeWithProtocol(args []string, protocol string, output func(string) string) []string { if len(args) <= 0 { return args } @@ -14,7 +19,14 @@ func ParseShortCode(args []string, output func(string) string) []string { output = defaultOutput } - result := []string{fmt.Sprintf("https://github.com/%s", args[0])} + var result []string + switch protocol { + case "https": + result = []string{fmt.Sprintf("https://github.com/%s", args[0])} + case "ssh", "git": + result = []string{fmt.Sprintf("git@github.com:%s.git", args[0])} + } + if len(args) > 1 { result = append(result, args[1:]...) } else {