Skip to content

Commit 58c75c7

Browse files
committed
feat: add cobra cli with run and version commands
1 parent 41b2890 commit 58c75c7

3 files changed

Lines changed: 100 additions & 0 deletions

File tree

cmd/root.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var rootCmd = &cobra.Command{
11+
Use: "rift",
12+
Short: "Rift - a production ready PostgreSQL CDC pipeline",
13+
Long: `Rift streams PostgreSQL changes (INSERT/UPDATE/DELETE/DDL) to webhooks, Postgres, and redis destinations using logical replication.
14+
15+
Single binary. Single config. No kafka required.`,
16+
}
17+
18+
func Execute() {
19+
if err := rootCmd.Execute(); err != nil {
20+
fmt.Println(err)
21+
os.Exit(1)
22+
}
23+
}

cmd/run.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"os/signal"
8+
9+
"github.com/mujib77/rift/internal/config"
10+
"github.com/mujib77/rift/internal/engine"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var configPath string
15+
16+
var runCmd = &cobra.Command{
17+
Use: "run",
18+
Short: "Start the Rift CDC pipeline",
19+
Run: func(cmd *cobra.Command, args []string) {
20+
cfg, err := config.Load(configPath)
21+
if err != nil {
22+
fmt.Println("error loading config:", err)
23+
os.Exit(1)
24+
}
25+
26+
ctx, cancel := context.WithCancel(context.Background())
27+
defer cancel()
28+
29+
go func() {
30+
sig := make(chan os.Signal, 1)
31+
signal.Notify(sig, os.Interrupt)
32+
<-sig
33+
fmt.Println("\n signal received, shutting down...")
34+
cancel()
35+
}()
36+
37+
eng, err := engine.New(cfg)
38+
if err != nil {
39+
fmt.Println("error creating engine:", err)
40+
os.Exit(1)
41+
}
42+
43+
if err := eng.Start(ctx); err != nil {
44+
fmt.Println("error:", err)
45+
os.Exit(1)
46+
}
47+
},
48+
}
49+
50+
func init() {
51+
runCmd.Flags().StringVarP(&configPath, "config", "c", "rift.yaml", "path to config file")
52+
rootCmd.AddCommand(runCmd)
53+
}

cmd/version.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var (
10+
version = "dev"
11+
commit = "none"
12+
)
13+
14+
var versionCmd = &cobra.Command{
15+
Use: "version",
16+
Short: "Print the version number of Rift",
17+
Run: func(cmd *cobra.Command, args []string) {
18+
fmt.Printf("rift version %s (%s)\n", version, commit)
19+
},
20+
}
21+
22+
func init() {
23+
rootCmd.AddCommand(versionCmd)
24+
}

0 commit comments

Comments
 (0)