Skip to content

Commit 67ad8ba

Browse files
committed
feat: add support for providing queue db file name in 'gocat push' subcommand
1 parent bbe7790 commit 67ad8ba

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

cmd/go-cat/cli.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ func catInfrastructureCliContext(context *cli.Context) error {
4545

4646
func pushInfrastructureCliContext(context *cli.Context) error {
4747
o := func() error {
48-
err := ops.Push(config.NewGlobalConfigFromCliContext(context))
48+
var err error
49+
if context.String("queue") == "" {
50+
err = ops.Push(config.NewGlobalConfigFromCliContext(context))
51+
} else {
52+
err = ops.PushWithDbQueue(config.NewGlobalConfigFromCliContext(context), context.String("queue"))
53+
}
54+
4955
if err != nil {
5056
fmt.Println(err)
5157
fmt.Println("retrying...")

cmd/go-cat/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ func main() {
3636
&cli.StringFlag{Name: "monitoring-links", Usage: "Multiple HTTP URLs of the monitoring dashboard of the servide, separated by comma"},
3737
&cli.StringFlag{Name: "parameters", Usage: "Additional parameters"},
3838
}
39+
queueFlags := []cli.Flag{
40+
&cli.StringFlag{Name: "queue", Required: false, Usage: "Specifies a file path to store the queue in."},
41+
}
3942
app := &cli.App{
4043
Name: "go-cat",
4144
Usage: "CLI tool to have an overview of Infrastructure, as an API as well as Markdown",
@@ -53,16 +56,14 @@ func main() {
5356
Usage: "Add infrastructure to queue",
5457
Action: addInfrastructureCliContext,
5558

56-
Flags: append(infraFlags,
57-
&cli.StringFlag{Name: "queue", Required: false, Usage: "Specifies a file path to store the queue in."},
58-
),
59+
Flags: append(infraFlags, queueFlags...),
5960
},
6061
{
6162
Name: "push",
6263
Usage: "Push changes from infrastructure queue to git",
6364
Action: pushInfrastructureCliContext,
6465

65-
Flags: gitFlags,
66+
Flags: append(gitFlags, queueFlags...),
6667
},
6768
{
6869
Name: "cat",

ops/push.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@ import (
1111
"gitlab.com/sorcero/community/go-cat/meta"
1212
"gitlab.com/sorcero/community/go-cat/parser"
1313
"gitlab.com/sorcero/community/go-cat/storage"
14-
"io/ioutil"
1514
"os"
1615
)
1716

1817
// Push pushes all the infrastructure from queue
1918
func Push(cfg config.GlobalConfig) error {
19+
queueDB := meta.QueueDbName
20+
return PushWithDbQueue(cfg, queueDB)
21+
}
22+
23+
func PushWithDbQueue(cfg config.GlobalConfig, queueDB string) error {
2024
repo, fs, err := storage.Clone(cfg)
2125
if err != nil {
2226
return err
2327
}
2428

2529
infraMetaQueue := &infrastructure.MetadataGroup{}
26-
if helpers.CheckFileExists(meta.QueueDbName) {
27-
data, err := ioutil.ReadFile(meta.QueueDbName)
30+
if helpers.CheckFileExists(queueDB) {
31+
data, err := os.ReadFile(queueDB)
2832
if err != nil {
2933
return err
3034
}

0 commit comments

Comments
 (0)