feat: add up command

This commit is contained in:
2024-07-07 11:43:57 -04:00
parent 3167f017c1
commit d565c4d8c2
5 changed files with 114 additions and 20 deletions

View File

@ -1,16 +1,16 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
Copyright © 2024 James Walker <walkah@walkah.net>
*/
package cmd
import (
"fmt"
"os"
"strings"
git "github.com/go-git/go-git/v5"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"walkah.dev/walkah/gotem/internal/util"
)
// addCmd represents the add command
@ -20,7 +20,7 @@ var addCmd = &cobra.Command{
Long: `This command adds the current path to the list of git clones to track.`,
Run: func(cmd *cobra.Command, args []string) {
if cwd, err := os.Getwd(); err == nil {
relativePath, err := getRelativePath(cwd)
relativePath, err := util.GetRelativePath(cwd)
if err != nil {
panic(err)
}
@ -44,17 +44,3 @@ var addCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(addCmd)
}
func getRelativePath(absolutePath string) (string, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
return "", err
}
if strings.HasPrefix(absolutePath, homeDir) {
relativePath := strings.TrimPrefix(absolutePath, fmt.Sprintf("%s/", homeDir))
return relativePath, nil
}
return absolutePath, nil
}

32
cmd/up.go Normal file
View File

@ -0,0 +1,32 @@
/*
Copyright © 2024 James Walker <walkah@walkah.net>
*/
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"walkah.dev/walkah/gotem/internal/git"
)
// upCmd represents the up command
var upCmd = &cobra.Command{
Use: "up",
Short: "Update yer git",
Long: `Pulls the latest in all repos`,
Run: func(cmd *cobra.Command, args []string) {
for _, project := range viper.AllSettings() {
path := project.(map[string]interface{})["path"].(string)
err := git.PullLatest(path)
if err != nil {
fmt.Println(err)
}
}
},
}
func init() {
rootCmd.AddCommand(upCmd)
}