implement own folder for linking

This commit is contained in:
daveberrys committed 2026-07-19 03:06:58 +08:00
1 parent 664d8a8da6
commit 99e2b8d92f
6 files changed
+64 -30

No files matched your search

-29
View File
@@ -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
}
},
}
-1
View File
@@ -9,7 +9,6 @@ func init() {
cmd.RootCmd.AddCommand(createCmd)
createCmd.AddCommand(createBranchCmd)
createCmd.AddCommand(createAccountCmd)
createCmd.AddCommand(linkRepoCmd)
}
var createCmd = &cobra.Command{
+21
View File
@@ -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
},
}
+20
View File
@@ -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
},
}
+22
View File
@@ -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
},
}