mirror of
https://github.com/daveberrys/guh.git
synced 2026-11-29 00:26:46 +08:00
implement own folder for linking
This commit is contained in:
1 parent
664d8a8da6
commit
99e2b8d92f
6 files changed
+64
-30
No files matched your search
@@ -5,6 +5,7 @@ import (
|
|||||||
_ "github.com/daveberrys/guh/src/cmd/create"
|
_ "github.com/daveberrys/guh/src/cmd/create"
|
||||||
_ "github.com/daveberrys/guh/src/cmd/switch"
|
_ "github.com/daveberrys/guh/src/cmd/switch"
|
||||||
_ "github.com/daveberrys/guh/src/cmd/browse"
|
_ "github.com/daveberrys/guh/src/cmd/browse"
|
||||||
|
_ "github.com/daveberrys/guh/src/cmd/link"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() { cmd.Execute() }
|
func main() { cmd.Execute() }
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package createcmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/daveberrys/guh/src/utils"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
var linkRepoCmd = &cobra.Command{
|
|
||||||
Use: "repo [url]",
|
|
||||||
Short: "Link a repository",
|
|
||||||
Args: cobra.ExactArgs(1),
|
|
||||||
RunE: func(c *cobra.Command, args []string) error {
|
|
||||||
switch args[0] {
|
|
||||||
case "":
|
|
||||||
return fmt.Errorf("repository URL cannot be empty")
|
|
||||||
case "what":
|
|
||||||
utils.RunGit(false, "remote", "get-url", "origin")
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
utils.RunGit(true, "remote", "remove", "origin")
|
|
||||||
utils.RunGit(false, "remote", "add", "origin", args[0])
|
|
||||||
|
|
||||||
fmt.Printf("Linked repository to: %s\n", args[0])
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,6 @@ func init() {
|
|||||||
cmd.RootCmd.AddCommand(createCmd)
|
cmd.RootCmd.AddCommand(createCmd)
|
||||||
createCmd.AddCommand(createBranchCmd)
|
createCmd.AddCommand(createBranchCmd)
|
||||||
createCmd.AddCommand(createAccountCmd)
|
createCmd.AddCommand(createAccountCmd)
|
||||||
createCmd.AddCommand(linkRepoCmd)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var createCmd = &cobra.Command{
|
var createCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package link
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/daveberrys/guh/src/utils"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var addLinkRepoCmd = &cobra.Command{
|
||||||
|
Use: "add [remote_name] [url]",
|
||||||
|
Short: "Links a remote to a repository",
|
||||||
|
Args: cobra.ExactArgs(2),
|
||||||
|
RunE: func(c *cobra.Command, args []string) error {
|
||||||
|
utils.RunGit(true, "remote", "remove", args[0])
|
||||||
|
utils.RunGit(false, "remote", "add", args[0], args[1])
|
||||||
|
|
||||||
|
fmt.Printf("Linked repository to: %s\n", args[1])
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package link
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/daveberrys/guh/src/utils"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var removeLinkRepoCmd = &cobra.Command{
|
||||||
|
Use: "remove [remote_name]",
|
||||||
|
Short: "Removes a remote from a repository",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(c *cobra.Command, args []string) error {
|
||||||
|
utils.RunGit(true, "remote", "remove", args[0])
|
||||||
|
|
||||||
|
fmt.Printf("Removed remote: %s\n", args[0])
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package link
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/daveberrys/guh/src/utils"
|
||||||
|
"github.com/daveberrys/guh/src/cmd"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cmd.RootCmd.AddCommand(linkCmd)
|
||||||
|
linkCmd.AddCommand(addLinkRepoCmd)
|
||||||
|
linkCmd.AddCommand(removeLinkRepoCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var linkCmd = &cobra.Command{
|
||||||
|
Use: "link",
|
||||||
|
Short: "Link repositories. Shows all linked repositories",
|
||||||
|
RunE: func(c *cobra.Command, args []string) error {
|
||||||
|
utils.RunGit(false, "remote", "-v")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
Reference in new issue
Block a user