add in cobra stubs for the subcommands

This commit is contained in:
2023-05-25 15:30:38 -07:00
parent 9a4f8023d8
commit 399faba8ef
12 changed files with 227 additions and 28 deletions

20
cmd/mg/cmd/commit.go Normal file
View File

@@ -0,0 +1,20 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// commitCmd represents the commit command
var commitCmd = &cobra.Command{
Use: "commit",
Short: "commit all current repos with the same message",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("commit called")
},
}
func init() {
rootCmd.AddCommand(commitCmd)
}

20
cmd/mg/cmd/diff.go Normal file
View File

@@ -0,0 +1,20 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// diffCmd represents the diff command
var diffCmd = &cobra.Command{
Use: "diff",
Short: "compute a collective diff",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("diff called")
},
}
func init() {
rootCmd.AddCommand(diffCmd)
}

19
cmd/mg/cmd/fetch.go Normal file
View File

@@ -0,0 +1,19 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var fetchCmd = &cobra.Command{
Use: "fetch",
Short: "fetch all git repos without merging",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("fetch called")
},
}
func init() {
rootCmd.AddCommand(fetchCmd)
}

20
cmd/mg/cmd/pull.go Normal file
View File

@@ -0,0 +1,20 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// pullCmd represents the pull command
var pullCmd = &cobra.Command{
Use: "pull",
Short: "pull all git repos",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("pull called")
},
}
func init() {
rootCmd.AddCommand(pullCmd)
}

20
cmd/mg/cmd/push.go Normal file
View File

@@ -0,0 +1,20 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// pushCmd represents the push command
var pushCmd = &cobra.Command{
Use: "push",
Short: "push all git repos",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("push called")
},
}
func init() {
rootCmd.AddCommand(pushCmd)
}

29
cmd/mg/cmd/register.go Normal file
View File

@@ -0,0 +1,29 @@
package cmd
import (
"fmt"
"log"
"os"
"github.com/spf13/cobra"
)
var registerCmd = &cobra.Command{
Use: "register",
Short: "add current path to list of repos",
Run: func(cmd *cobra.Command, args []string) {
path, err := os.Getwd()
if err != nil {
log.Println(err)
os.Exit(1)
}
if len(args) == 1 {
path = args[0]
}
fmt.Printf("register called for %s\n", path)
},
}
func init() {
rootCmd.AddCommand(registerCmd)
}

22
cmd/mg/cmd/root.go Normal file
View File

@@ -0,0 +1,22 @@
package cmd
import (
"os"
"github.com/spf13/cobra"
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "mg",
Short: "go replacement for myrepos which only supports git repos",
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

20
cmd/mg/cmd/status.go Normal file
View File

@@ -0,0 +1,20 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// statusCmd represents the status command
var statusCmd = &cobra.Command{
Use: "status",
Short: "get the combined git status for all git repos",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("status called")
},
}
func init() {
rootCmd.AddCommand(statusCmd)
}

20
cmd/mg/cmd/unregister.go Normal file
View File

@@ -0,0 +1,20 @@
package cmd
import (
"fmt"
"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")
},
}
func init() {
rootCmd.AddCommand(unregisterCmd)
}

View File

@@ -1,38 +1,30 @@
package main
import (
"flag"
"log"
"os"
"github.com/taigrr/mg/parse"
)
var jobs = flag.Int("j", 1, "number of jobs to run in parallel")
import "github.com/taigrr/mg/cmd/mg/cmd"
func main() {
flag.Parse()
conf, err := parse.LoadMGConfig()
if err != nil {
if os.IsNotExist(err) {
// Try to load mr config instead
mrconf, err := parse.LoadMRConfig()
if err != nil {
log.Println(err)
os.Exit(1)
}
// conf, err := parse.LoadMGConfig()
// if err != nil {
// if os.IsNotExist(err) {
// // Try to load mr config instead
// mrconf, err := parse.LoadMRConfig()
// if err != nil {
// log.Println(err)
// os.Exit(1)
// }
conf = mrconf.ToMGConfig()
log.Println("migrated mrconfig to mgconfig")
err = conf.Save()
if err != nil {
log.Println(err)
os.Exit(1)
}
}
}
// conf = mrconf.ToMGConfig()
// log.Println("migrated mrconfig to mgconfig")
// err = conf.Save()
// if err != nil {
// log.Println(err)
// os.Exit(1)
// }
// }
//}
// fmt.Println(conf)
cmd.Execute()
}
func Register() {