Skip to content

Commit

Permalink
feat: add command in fctl
Browse files Browse the repository at this point in the history
  • Loading branch information
David Ragot committed Jul 6, 2023
1 parent e1e9d31 commit 20b5f8b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
63 changes: 63 additions & 0 deletions components/fctl/cmd/orchestration/workflows/delete.go
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
}),
)
}
1 change: 1 addition & 0 deletions components/fctl/cmd/orchestration/workflows/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func NewCommand() *cobra.Command {
NewCreateCommand(),
NewRunCommand(),
NewShowCommand(),
NewDeleteCommand(),
),
)
}

0 comments on commit 20b5f8b

Please sign in to comment.