diff --git a/cmd/mg/cmd/commit.go b/cmd/mg/cmd/commit.go new file mode 100644 index 0000000..6b6f7f7 --- /dev/null +++ b/cmd/mg/cmd/commit.go @@ -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) +} diff --git a/cmd/mg/cmd/diff.go b/cmd/mg/cmd/diff.go new file mode 100644 index 0000000..b1f4f96 --- /dev/null +++ b/cmd/mg/cmd/diff.go @@ -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) +} diff --git a/cmd/mg/cmd/fetch.go b/cmd/mg/cmd/fetch.go new file mode 100644 index 0000000..6689490 --- /dev/null +++ b/cmd/mg/cmd/fetch.go @@ -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) +} diff --git a/cmd/mg/cmd/pull.go b/cmd/mg/cmd/pull.go new file mode 100644 index 0000000..96968fc --- /dev/null +++ b/cmd/mg/cmd/pull.go @@ -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) +} diff --git a/cmd/mg/cmd/push.go b/cmd/mg/cmd/push.go new file mode 100644 index 0000000..8a2f511 --- /dev/null +++ b/cmd/mg/cmd/push.go @@ -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) +} diff --git a/cmd/mg/cmd/register.go b/cmd/mg/cmd/register.go new file mode 100644 index 0000000..fa49f04 --- /dev/null +++ b/cmd/mg/cmd/register.go @@ -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) +} diff --git a/cmd/mg/cmd/root.go b/cmd/mg/cmd/root.go new file mode 100644 index 0000000..c4f94fd --- /dev/null +++ b/cmd/mg/cmd/root.go @@ -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) + } +} diff --git a/cmd/mg/cmd/status.go b/cmd/mg/cmd/status.go new file mode 100644 index 0000000..610d3b6 --- /dev/null +++ b/cmd/mg/cmd/status.go @@ -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) +} diff --git a/cmd/mg/cmd/unregister.go b/cmd/mg/cmd/unregister.go new file mode 100644 index 0000000..223f97c --- /dev/null +++ b/cmd/mg/cmd/unregister.go @@ -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) +} diff --git a/cmd/mg/main.go b/cmd/mg/main.go index 65f9777..369cd81 100644 --- a/cmd/mg/main.go +++ b/cmd/mg/main.go @@ -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() { diff --git a/go.mod b/go.mod index 595f720..de72474 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,10 @@ module github.com/taigrr/mg go 1.20 + +require github.com/spf13/cobra v1.7.0 + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f3366a9 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=