github.com/r2d2-ai/cli@v1.20.0/commands/list.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/r2d2-ai/cli/api"
     8  	"github.com/r2d2-ai/cli/common"
     9  	"github.com/spf13/cobra"
    10  )
    11  
    12  var json bool
    13  var orphaned bool
    14  var listFilter string
    15  
    16  func init() {
    17  	listCmd.Flags().BoolVarP(&json, "json", "j", true, "print in json format")
    18  	listCmd.Flags().BoolVarP(&orphaned, "orphaned", "", false, "list orphaned refs")
    19  	listCmd.Flags().StringVarP(&listFilter, "filter", "", "", "apply list filter [used, unused]")
    20  	rootCmd.AddCommand(listCmd)
    21  }
    22  
    23  var listCmd = &cobra.Command{
    24  	Use:   "list [flags]",
    25  	Short: "list installed flogo contributions",
    26  	Long:  "List installed flogo contributions",
    27  	Run: func(cmd *cobra.Command, args []string) {
    28  
    29  		if orphaned {
    30  			err := api.ListOrphanedRefs(common.CurrentProject(), json)
    31  			if err != nil {
    32  				fmt.Fprintf(os.Stderr, "Error getting orphaned refs: %v\n", err)
    33  				os.Exit(1)
    34  			}
    35  
    36  			return
    37  		}
    38  
    39  		err := api.ListContribs(common.CurrentProject(), json, listFilter)
    40  		if err != nil {
    41  			fmt.Fprintf(os.Stderr, "Error getting list of contributions: %v\n", err)
    42  			os.Exit(1)
    43  		}
    44  	},
    45  }