Skip to content

Commit a75df59

Browse files
committed
Initial commit
0 parents  commit a75df59

File tree

8 files changed

+174
-0
lines changed

8 files changed

+174
-0
lines changed

cmd/initialize/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package initialize
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
// Cmd line declaration
10+
var Cmd = &cobra.Command{
11+
Use: "init",
12+
Short: "Initialize a repo",
13+
Long: ``,
14+
Args: cobra.ExactArgs(0),
15+
RunE: func(cmd *cobra.Command, args []string) error {
16+
fmt.Printf("Running init\n")
17+
return nil
18+
},
19+
}

cmd/list/main.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package list
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
8+
"github.com/bmeg/git-gen3/git"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// Cmd line declaration
13+
var Cmd = &cobra.Command{
14+
Use: "list",
15+
Aliases: []string{"ls"},
16+
Short: "list files",
17+
Long: ``,
18+
Args: cobra.MinimumNArgs(0),
19+
RunE: func(cmd *cobra.Command, args []string) error {
20+
gitTop, err := git.GitTopLevel()
21+
if err != nil {
22+
fmt.Printf("Error: %s\n", err)
23+
return err
24+
}
25+
manifestDir := filepath.Join(gitTop, "MANIFEST")
26+
fmt.Printf("Manifest: %s\n", manifestDir)
27+
s, err := os.Stat(manifestDir)
28+
if err != nil {
29+
return err
30+
}
31+
if s.IsDir() {
32+
files, err := filepath.Glob(filepath.Join(manifestDir, "*"))
33+
if err != nil {
34+
return err
35+
}
36+
for _, i := range files {
37+
fmt.Printf("%s\n", i)
38+
}
39+
}
40+
return nil
41+
},
42+
}

cmd/pull/main.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package pull
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
// Cmd line declaration
10+
var Cmd = &cobra.Command{
11+
Use: "pull",
12+
Short: "Pull a file",
13+
Long: ``,
14+
Args: cobra.MinimumNArgs(1),
15+
RunE: func(cmd *cobra.Command, args []string) error {
16+
for i := range args {
17+
fmt.Printf("Pulling file %s\n", args[i])
18+
}
19+
return nil
20+
},
21+
}

cmd/push/main.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package push
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
// Cmd line declaration
10+
var Cmd = &cobra.Command{
11+
Use: "push",
12+
Short: "Push a repo",
13+
Long: ``,
14+
Args: cobra.MinimumNArgs(1),
15+
RunE: func(cmd *cobra.Command, args []string) error {
16+
for i := range args {
17+
fmt.Printf("Pushing %s\n", args[i])
18+
}
19+
return nil
20+
},
21+
}

cmd/root.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
6+
"github.com/bmeg/git-gen3/cmd/initialize"
7+
"github.com/bmeg/git-gen3/cmd/list"
8+
"github.com/bmeg/git-gen3/cmd/pull"
9+
"github.com/bmeg/git-gen3/cmd/push"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
// RootCmd represents the root command
14+
var RootCmd = &cobra.Command{
15+
Use: "git-gen3",
16+
SilenceErrors: true,
17+
SilenceUsage: true,
18+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
19+
//pre-run code can go here
20+
},
21+
}
22+
23+
func init() {
24+
RootCmd.AddCommand(initialize.Cmd)
25+
RootCmd.AddCommand(push.Cmd)
26+
RootCmd.AddCommand(pull.Cmd)
27+
RootCmd.AddCommand(list.Cmd)
28+
RootCmd.AddCommand(genBashCompletionCmd)
29+
}
30+
31+
var genBashCompletionCmd = &cobra.Command{
32+
Use: "bash",
33+
Short: "Generate bash completions file",
34+
Run: func(cmd *cobra.Command, args []string) {
35+
RootCmd.GenBashCompletion(os.Stdout)
36+
},
37+
}

git-gen3.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/bmeg/git-gen3/cmd"
8+
)
9+
10+
func main() {
11+
if err := cmd.RootCmd.Execute(); err != nil {
12+
fmt.Println("Error:", err.Error())
13+
os.Exit(1)
14+
}
15+
}

go.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module github.com/bmeg/git-gen3
2+
3+
go 1.24.0
4+
5+
require (
6+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
7+
github.com/spf13/cobra v1.9.1 // indirect
8+
github.com/spf13/pflag v1.0.6 // indirect
9+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
2+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
5+
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
6+
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
7+
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
8+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)