Skip to content

Commit 6f0321c

Browse files
committed
feat: add --overwrite flag
1 parent f5d41b8 commit 6f0321c

4 files changed

Lines changed: 20 additions & 15 deletions

File tree

cmd/go-cat/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func main() {
2525

2626
&cli.StringFlag{Name: "title", Usage: "Title of the infrastructure"},
2727
&cli.BoolFlag{Name: "archive", Usage: "Add archive infra.json file"},
28+
&cli.BoolFlag{Name: "overwrite", Usage: "Replace infra.json, and do not perform deep merge"},
2829
}
2930
infraFlags := []cli.Flag{
3031
&cli.StringFlag{Name: "name", Usage: "Name of the service or endpoint"},

config/base.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ type GlobalConfig struct {
1616
GitUsername string
1717
GitPassword string
1818

19-
Title string
20-
Archive bool
19+
Title string
20+
Archive bool
21+
Overwrite bool
2122
}
2223

2324
func NewGlobalConfigFromCliContext(context *cli.Context) GlobalConfig {
@@ -26,7 +27,8 @@ func NewGlobalConfigFromCliContext(context *cli.Context) GlobalConfig {
2627
GitUsername: context.String("git.username"),
2728
GitPassword: context.String("git.password"),
2829

29-
Title: context.String("title"),
30-
Archive: context.Bool("archive"),
30+
Title: context.String("title"),
31+
Archive: context.Bool("archive"),
32+
Overwrite: context.Bool("overwrite"),
3133
}
3234
}

ops/push.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ func PushWithDbQueue(cfg config.GlobalConfig, queueDB string) error {
5252
}
5353

5454
func PushFromStorage(repo *git.Repository, fs billy.Filesystem, infraMetaQueue *infrastructure.MetadataGroup, cfg config.GlobalConfig) error {
55-
infraJson, err := storage.ReadInfraDb(fs)
56-
if err != nil {
57-
return err
58-
}
59-
6055
infraMeta := &infrastructure.MetadataGroup{}
61-
err = json.Unmarshal(infraJson, infraMeta)
62-
if err != nil {
63-
return err
56+
57+
if !cfg.Overwrite {
58+
infraJson, err := storage.ReadInfraDb(fs)
59+
if err != nil {
60+
return err
61+
}
62+
err = json.Unmarshal(infraJson, infraMeta)
63+
if err != nil {
64+
return err
65+
}
6466
}
6567

6668
logger.Info("Adding infrastructure")

ui/go-cat-ui/src/App.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
const relativeTime = new RelativeTime();
2525
2626
import infra_json from './infra.json';
27-
import Monitoring from './Monitoring.svelte';
28-
import InfraType from './InfraType.svelte';
27+
import Monitoring from './Monitoring.svelte';
28+
import InfraType from './InfraType.svelte';
2929
3030
let data = infra_json["infra"];
3131
let catalog_name = import.meta.env.VITE_APP_CATALOG_NAME;
@@ -81,7 +81,7 @@ import InfraType from './InfraType.svelte';
8181
<section class="section">
8282
<div class="container">
8383

84-
<h1 class="title">{catalog_name}</h1>
84+
<h1 class="title">{infra_json["title"]} | {catalog_name}</h1>
8585
<p id="last_updated" class="subtitle is-loading">
8686
Last updated <strong>{relativeTime.from(new Date(infra_json["updated_at"]))}</strong>.
8787
</p>

0 commit comments

Comments
 (0)