Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/ctrlc/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/sync"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/ui"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/version"
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/workflow"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -59,6 +60,7 @@ func NewRootCmd() *cobra.Command {
cmd.AddCommand(run.NewRunCmd())
cmd.AddCommand(ui.NewUICmd())
cmd.AddCommand(version.NewVersionCmd())
cmd.AddCommand(workflow.NewWorkflowCmd())

return cmd
}
53 changes: 53 additions & 0 deletions cmd/ctrlc/root/workflow/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package workflow

import (
"fmt"

"github.com/ctrlplanedev/cli/internal/api"
"github.com/ctrlplanedev/cli/internal/cliutil"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func NewListCmd() *cobra.Command {
var limit int
var offset int

cmd := &cobra.Command{
Use: "list",
Short: "List workflows",
Long: `List all workflows in the workspace.`,
RunE: func(cmd *cobra.Command, args []string) error {
apiURL := viper.GetString("url")
apiKey := viper.GetString("api-key")
workspace := viper.GetString("workspace")

client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey)
if err != nil {
return fmt.Errorf("failed to create API client: %w", err)
}

workspaceID := client.GetWorkspaceID(cmd.Context(), workspace)
Comment thread
dacbd marked this conversation as resolved.
Outdated

params := &api.ListWorkflowsParams{}
if limit > 0 {
params.Limit = &limit
}
if offset > 0 {
params.Offset = &offset
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

resp, err := client.ListWorkflows(cmd.Context(), workspaceID.String(), params)
if err != nil {
return fmt.Errorf("failed to list workflows: %w", err)
}

return cliutil.HandleResponseOutput(cmd, resp)
},
}

cmd.Flags().IntVarP(&limit, "limit", "l", 50, "Limit the number of results")
cmd.Flags().IntVarP(&offset, "offset", "o", 0, "Offset the results")

return cmd
}
60 changes: 60 additions & 0 deletions cmd/ctrlc/root/workflow/trigger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package workflow

import (
"fmt"
"strings"

"github.com/ctrlplanedev/cli/internal/api"
"github.com/ctrlplanedev/cli/internal/cliutil"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func NewTriggerCmd() *cobra.Command {
var inputFlags []string

cmd := &cobra.Command{
Use: "trigger <workflow-id>",
Short: "Trigger a workflow run",
Long: `Trigger a workflow run with the given inputs.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
workflowID := args[0]

apiURL := viper.GetString("url")
apiKey := viper.GetString("api-key")
workspace := viper.GetString("workspace")

client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey)
if err != nil {
return fmt.Errorf("failed to create API client: %w", err)
}

workspaceID := client.GetWorkspaceID(cmd.Context(), workspace)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

inputs := make(map[string]interface{})
for _, input := range inputFlags {
key, value, found := strings.Cut(input, "=")
if !found {
return fmt.Errorf("invalid input format %q, expected key=value", input)
}
inputs[key] = value
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

body := api.CreateWorkflowRunJSONRequestBody{
Inputs: inputs,
}

resp, err := client.CreateWorkflowRun(cmd.Context(), workspaceID.String(), workflowID, body)
if err != nil {
return fmt.Errorf("failed to trigger workflow: %w", err)
}

return cliutil.HandleResponseOutput(cmd, resp)
},
}

cmd.Flags().StringArrayVarP(&inputFlags, "input", "i", nil, "Input key=value pair (can be specified multiple times)")

return cmd
}
21 changes: 21 additions & 0 deletions cmd/ctrlc/root/workflow/workflow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package workflow

import (
"github.com/spf13/cobra"
)

func NewWorkflowCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "workflow <subcommand>",
Short: "Manage workflows",
Long: `Commands for listing and triggering workflows.`,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}

cmd.AddCommand(NewListCmd())
cmd.AddCommand(NewTriggerCmd())

return cmd
}
Loading
Loading