NewListCertificationTargetsCommand returns a cobra command for the `list` subcommand
()
| 79 | |
| 80 | // NewListCertificationTargetsCommand returns a cobra command for the `list` subcommand |
| 81 | func NewListCertificationTargetsCommand() *cobra.Command { |
| 82 | cmd := &cobra.Command{ |
| 83 | Use: "list", |
| 84 | Short: "Lists all target certification targets", |
| 85 | RunE: func(cmd *cobra.Command, args []string) error { |
| 86 | var ( |
| 87 | err error |
| 88 | session *cli.Session |
| 89 | client orchestrator.OrchestratorClient |
| 90 | res *orchestrator.ListCertificationTargetsResponse |
| 91 | target []*orchestrator.CertificationTarget |
| 92 | ) |
| 93 | |
| 94 | if session, err = cli.ContinueSession(); err != nil { |
| 95 | fmt.Printf("Error while retrieving the session. Please re-authenticate.\n") |
| 96 | return nil |
| 97 | } |
| 98 | |
| 99 | client = orchestrator.NewOrchestratorClient(session) |
| 100 | |
| 101 | target, err = api.ListAllPaginated(&orchestrator.ListCertificationTargetsRequest{}, client.ListCertificationTargets, func(res *orchestrator.ListCertificationTargetsResponse) []*orchestrator.CertificationTarget { |
| 102 | return res.Targets |
| 103 | }) |
| 104 | |
| 105 | // Build a response with all certification targets |
| 106 | res = &orchestrator.ListCertificationTargetsResponse{ |
| 107 | Targets: target, |
| 108 | } |
| 109 | |
| 110 | return session.HandleResponse(res, err) |
| 111 | }, |
| 112 | ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 113 | return []string{}, cobra.ShellCompDirectiveNoFileComp |
| 114 | }, |
| 115 | } |
| 116 | |
| 117 | return cmd |
| 118 | } |
| 119 | |
| 120 | // NewGetCertificationTargetCommand returns a cobra command for the `get` subcommand |
| 121 | func NewGetCertificationTargetCommand() *cobra.Command { |