Skip to content

Commit

Permalink
atlasexec: always quote the directive input (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm authored Oct 14, 2024
1 parent 99a5cdb commit 6e1a482
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion atlasexec/atlas_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
"time"

"ariga.io/atlas/sql/migrate"
Expand Down Expand Up @@ -420,7 +421,7 @@ func (c *Client) SchemaPlan(ctx context.Context, params *SchemaPlanParams) (*Sch
args = append(args, "--auto-approve")
}
for _, d := range params.Directives {
args = append(args, "--directive", d)
args = append(args, "--directive", strconv.Quote(d))
}
// NOTE: This command only support one result.
return firstResult(jsonDecode[SchemaPlan](c.runCommand(ctx, args)))
Expand Down
4 changes: 2 additions & 2 deletions atlasexec/atlas_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ func TestSchema_Plan(t *testing.T) {
params: &atlasexec.SchemaPlanParams{
From: []string{"1", "2"},
To: []string{"2", "3"},
Directives: []string{"atlas:nolint", "\"atlas:txmode none\""},
Directives: []string{"atlas:nolint", "atlas:txmode none"},
},
args: `schema plan --format {{ json . }} --from 1,2 --to 2,3 --auto-approve --directive atlas:nolint --directive "atlas:txmode none"`,
args: `schema plan --format {{ json . }} --from 1,2 --to 2,3 --auto-approve --directive "atlas:nolint" --directive "atlas:txmode none"`,
},
{
name: "with config",
Expand Down

0 comments on commit 6e1a482

Please sign in to comment.