feat: port influx export stack subcommand (#150)

* confirmed subcommand parsing

* feat: port influx export stack subcommand

* refactor: removed redundant code and improved error messages

* chore: ran make fmt to fix code formatting issues

Co-authored-by: Michelle McFarland <michellemcfarland@Michelles-MacBook-Pro.local>
This commit is contained in:
mcfarlm3
2021-06-28 09:02:49 -07:00
committed by GitHub
parent 7ea63d6a96
commit 72d1ad8361
2 changed files with 83 additions and 0 deletions

View File

@ -110,3 +110,26 @@ func (c Client) ExportAll(ctx context.Context, params *AllParams) error {
}
return nil
}
type StackParams struct {
OutParams
StackId string
}
func (c Client) ExportStack(ctx context.Context, params *StackParams) error {
if params.StackId == "" {
return fmt.Errorf("no stack id provided")
}
exportReq := api.TemplateExport{StackID: &params.StackId}
tmpl, err := c.ExportTemplate(ctx).TemplateExport(exportReq).Execute()
if err != nil {
return fmt.Errorf("failed to export stack %q: %w", params.StackId, err)
}
if err := params.OutParams.writeTemplate(tmpl); err != nil {
return fmt.Errorf("failed to write exported template: %w", err)
}
return nil
}