-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Ragot
committed
Jul 6, 2023
1 parent
e1e9d31
commit 20b5f8b
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package workflows | ||
|
||
import ( | ||
"fmt" | ||
|
||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/formancehq/formance-sdk-go/pkg/models/operations" | ||
"github.com/pkg/errors" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewDeleteCommand() *cobra.Command { | ||
return fctl.NewCommand("delete <workflow-id>", | ||
fctl.WithAliases("del", "d"), | ||
fctl.WithShortDescription("Soft delete a workflow"), | ||
fctl.WithArgs(cobra.ExactArgs(1)), | ||
fctl.WithRunE(func(cmd *cobra.Command, args []string) error { | ||
|
||
cfg, err := fctl.GetConfig(cmd) | ||
if err != nil { | ||
return errors.Wrap(err, "retrieving config") | ||
} | ||
|
||
organizationID, err := fctl.ResolveOrganizationID(cmd, cfg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
stack, err := fctl.ResolveStack(cmd, cfg, organizationID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
client, err := fctl.NewStackClient(cmd, cfg, stack) | ||
if err != nil { | ||
return errors.Wrap(err, "creating stack client") | ||
} | ||
|
||
response, err := client.Orchestration.DeleteWorkflow( | ||
cmd.Context(), | ||
operations.DeleteWorkflowRequest{ | ||
FlowID: args[0], | ||
}, | ||
) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if response.Error != nil { | ||
return fmt.Errorf("%s: %s", response.Error.ErrorCode, response.Error.ErrorMessage) | ||
} | ||
|
||
if response.StatusCode >= 300 { | ||
return fmt.Errorf("unexpected status code: %d", response.StatusCode) | ||
} | ||
|
||
pterm.Success.WithWriter(cmd.OutOrStdout()).Printfln("Workflow %s deleted!", args[0]) | ||
return nil | ||
}), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters