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

7
go.mod
View File

@@ -1,3 +1,10 @@
module github.com/taigrr/mg module github.com/taigrr/mg
go 1.20 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
)

10
go.sum Normal file
View File

@@ -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=