MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / newWorkflowListCmd

Function newWorkflowListCmd

app/cli/cmd/workflow_list.go:29–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27)
28
29func newWorkflowListCmd() *cobra.Command {
30 var paginationOpts = &options.OffsetPaginationOpts{}
31
32 cmd := &cobra.Command{
33 Use: "list",
34 Aliases: []string{"ls"},
35 Short: "List existing Workflows",
36 Example: ` # Let the default pagination apply
37 chainloop workflow list
38
39 # Specify the page and page size
40 chainloop workflow list --page 2 --limit 10
41
42 # Output in json format to paginate using scripts
43 chainloop workflow list --page 2 --limit 10 --output json
44
45 # Show the full report
46 chainloop workflow list --full
47`,
48 PreRunE: func(_ *cobra.Command, _ []string) error {
49 if paginationOpts.Page < 1 {
50 return fmt.Errorf("--page must be greater or equal than 1")
51 }
52 if paginationOpts.Limit < 1 {
53 return fmt.Errorf("--limit must be greater or equal than 1")
54 }
55
56 return nil
57 },
58 RunE: func(_ *cobra.Command, _ []string) error {
59 res, err := action.NewWorkflowList(ActionOpts).Run(paginationOpts.Page, paginationOpts.Limit)
60 if err != nil {
61 return err
62 }
63
64 if err := output.EncodeOutput(flagOutputFormat, res, WorkflowListTableOutput); err != nil {
65 return err
66 }
67
68 pgResponse := res.Pagination
69
70 if pgResponse.TotalPages >= paginationOpts.Page {
71 inPage := min(paginationOpts.Limit, len(res.Workflows))
72 lowerBound := (paginationOpts.Page - 1) * paginationOpts.Limit
73 logger.Info().Msg(fmt.Sprintf("Showing [%d-%d] out of %d", lowerBound+1, lowerBound+inPage, pgResponse.TotalCount))
74 }
75
76 if pgResponse.TotalCount > pgResponse.Page*pgResponse.PageSize {
77 logger.Info().Msg(fmt.Sprintf("Next page available: %d", pgResponse.Page+1))
78 }
79
80 return nil
81 },
82 }
83
84 cmd.Flags().BoolVar(&full, "full", false, "show the full report")
85 paginationOpts.AddFlags(cmd)
86

Callers 1

newWorkflowCmdFunction · 0.85

Calls 5

NewWorkflowListFunction · 0.92
EncodeOutputFunction · 0.92
InfoMethod · 0.65
AddFlagsMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected