add unregister command

This commit is contained in:
2023-05-25 16:28:43 -07:00
parent 809d4a0711
commit 2818cfb61d
3 changed files with 67 additions and 5 deletions

View File

@@ -20,6 +20,9 @@ var registerCmd = &cobra.Command{
}
if len(args) == 1 {
path = args[0]
} else if len(args) > 1 {
log.Println("too many arguments")
os.Exit(1)
}
r, err := git.PlainOpenWithOptions(path, &(git.PlainOpenOptions{DetectDotGit: true}))
if err != nil {

View File

@@ -1,17 +1,57 @@
package cmd
import (
"fmt"
"log"
"os"
git "github.com/go-git/go-git/v5"
"github.com/spf13/cobra"
)
// unregisterCmd represents the unregister command
var unregisterCmd = &cobra.Command{
Use: "unregister",
Short: "remove the current repo from the config",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("unregister called")
Short: "add current path to list of repos",
Run: func(_ *cobra.Command, args []string) {
conf := GetConfig()
path, err := os.Getwd()
if err != nil {
log.Println(err)
os.Exit(1)
}
if len(args) == 1 {
path = args[0]
err = conf.DelRepo(path)
if err != nil {
log.Println(err)
os.Exit(1)
}
return
} else if len(args) > 1 {
log.Println("too many arguments")
os.Exit(1)
}
r, err := git.PlainOpenWithOptions(path, &(git.PlainOpenOptions{DetectDotGit: true}))
if err != nil {
log.Println(err)
os.Exit(1)
}
newPath, err := r.Worktree()
if err != nil {
log.Println(err)
os.Exit(1)
}
path = newPath.Filesystem.Root()
err = conf.DelRepo(path)
if err != nil {
log.Println(err)
os.Exit(1)
}
err = conf.Save()
if err != nil {
log.Println(err)
os.Exit(1)
}
},
}