From 8a1a483c95794644dc9d4d390ce04c0d8cd63792 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" <12751435+giautm@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:16:05 +0700 Subject: [PATCH] atlasexec: added URL params to schema/push (#100) --- atlasexec/atlas.go | 12 ++++++++++++ atlasexec/atlas_schema.go | 12 +++++++----- atlasexec/atlas_schema_test.go | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/atlasexec/atlas.go b/atlasexec/atlas.go index f63aadf..6859d60 100644 --- a/atlasexec/atlas.go +++ b/atlasexec/atlas.go @@ -390,6 +390,18 @@ func jsonDecodeErr[T any](fn func([]*T, string) error) func(io.Reader, error) ([ } } +// repeatFlag repeats the flag for each value. +func repeatFlag(flag string, values []string) []string { + if len(values) == 0 { + return nil + } + out := make([]string, 0, len(values)*2) + for _, v := range values { + out = append(out, flag, v) + } + return out +} + func listString(args []string) string { return strings.Join(args, ",") } diff --git a/atlasexec/atlas_schema.go b/atlasexec/atlas_schema.go index 263e9b2..d0f80f6 100644 --- a/atlasexec/atlas_schema.go +++ b/atlasexec/atlas_schema.go @@ -18,10 +18,11 @@ type ( Context *RunContext DevURL string - Name string // Name of the schema (repo) to push to. - Tag string // Tag to push the schema with - Version string // Version of the schema to push. Defaults to the current timestamp. - Description string // Description of the schema changes. + URL []string // Desired schema URL(s) to push + Name string // Name of the schema (repo) to push to. + Tag string // Tag to push the schema with + Version string // Version of the schema to push. Defaults to the current timestamp. + Description string // Description of the schema changes. } // SchemaPush represents the result of a 'schema push' command. SchemaPush struct { @@ -37,7 +38,7 @@ type ( DevURL string URL string - To string + To string // TODO: change to []string TxMode string Exclude []string Schema []string @@ -241,6 +242,7 @@ func (c *Client) SchemaPush(ctx context.Context, params *SchemaPushParams) (*Sch args = append(args, "--context", string(buf)) } // Flags of the 'schema push' sub-commands + args = append(args, repeatFlag("--url", params.URL)...) if params.DevURL != "" { args = append(args, "--dev-url", params.DevURL) } diff --git a/atlasexec/atlas_schema_test.go b/atlasexec/atlas_schema_test.go index 6349da3..6cd92d8 100644 --- a/atlasexec/atlas_schema_test.go +++ b/atlasexec/atlas_schema_test.go @@ -538,6 +538,20 @@ func TestSchema_Push(t *testing.T) { params: &atlasexec.SchemaPushParams{}, args: "schema push --format {{ json . }}", }, + { + name: "push with 1 URL", + params: &atlasexec.SchemaPushParams{ + URL: []string{"file://foo.hcl"}, + }, + args: "schema push --format {{ json . }} --url file://foo.hcl", + }, + { + name: "push with 2 URLs", + params: &atlasexec.SchemaPushParams{ + URL: []string{"file://foo.hcl", "file://bupisu.hcl"}, + }, + args: "schema push --format {{ json . }} --url file://foo.hcl --url file://bupisu.hcl", + }, { name: "with repo", params: &atlasexec.SchemaPushParams{