Skip to content

Commit

Permalink
added MigrateLintError
Browse files Browse the repository at this point in the history
  • Loading branch information
dorav committed Sep 26, 2023
1 parent 3d8c326 commit 7075c2c
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions atlasexec/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type (
Web bool
Latest uint64
Vars Vars
Writer io.Writer
}
// SchemaApplyParams are the parameters for the `schema apply` command.
SchemaApplyParams struct {
Expand Down Expand Up @@ -283,9 +284,13 @@ func (c *Client) SchemaInspect(ctx context.Context, params *SchemaInspectParams)
return stringVal(c.runCommand(ctx, args))
}

// MigrateLint runs the 'migrate lint' command.
func (c *Client) MigrateLint(ctx context.Context, params *MigrateLintParams) (*SummaryReport, error) {
args := []string{"migrate", "lint", "--format", "{{ json . }}"}
func lintArgs(params *MigrateLintParams) []string {
args := []string{"migrate", "lint"}
if params.Web {
args = append(args, "-w")
} else {
args = append(args, "--format", "{{ json . }}")
}
if params.Env != "" {
args = append(args, "--env", params.Env)
}
Expand All @@ -301,14 +306,34 @@ func (c *Client) MigrateLint(ctx context.Context, params *MigrateLintParams) (*S
if params.BaseURL != "" {
args = append(args, "--base", params.BaseURL)
}
if params.Web {
args = append(args, "-w")
}
if params.Latest > 0 {
args = append(args, "--latest", strconv.FormatUint(params.Latest, 10))
}
args = append(args, params.Vars.AsArgs()...)
return jsonDecode[SummaryReport](c.runCommand(ctx, args, validJSON))
return args
}

// MigrateLint runs the 'migrate lint' command.
func (c *Client) MigrateLint(ctx context.Context, params *MigrateLintParams) (*SummaryReport, error) {
if params.Writer != nil {
return nil, errors.New("migrate lint params do not support a custom Writer, consider using MigrateLintErr")
}
newParams := *params
var buf bytes.Buffer
newParams.Writer = &buf
err := c.MigrateLintError(ctx, &newParams)
return jsonDecode[SummaryReport](&buf, err)
}

// MigrateLintError runs the 'migrate lint' command, the output is written to params.Writer
func (c *Client) MigrateLintError(ctx context.Context, params *MigrateLintParams) error {
args := lintArgs(params)
reader, err := c.runCommand(ctx, args, validJSON)
if err != nil {
return err
}
_, err = io.Copy(params.Writer, reader)
return err
}

// MigrateStatus runs the 'migrate status' command.
Expand Down

0 comments on commit 7075c2c

Please sign in to comment.