|
| 1 | +// |
| 2 | +// Copyright 2023 The Chainloop Authors. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +package cmd |
| 17 | + |
| 18 | +import ( |
| 19 | + "context" |
| 20 | + "fmt" |
| 21 | + "time" |
| 22 | + |
| 23 | + "github.com/chainloop-dev/chainloop/app/cli/internal/action" |
| 24 | + "github.com/jedib0t/go-pretty/v6/table" |
| 25 | + "github.com/spf13/cobra" |
| 26 | +) |
| 27 | + |
| 28 | +func newOrganizationInvitationListSentCmd() *cobra.Command { |
| 29 | + cmd := &cobra.Command{ |
| 30 | + Use: "list", |
| 31 | + Aliases: []string{"ls"}, |
| 32 | + Short: "List sent invitations", |
| 33 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 34 | + res, err := action.NewOrgInvitationListSent(actionOpts).Run(context.Background()) |
| 35 | + if err != nil { |
| 36 | + return err |
| 37 | + } |
| 38 | + |
| 39 | + return encodeOutput(res, orgInvitationTableOutput) |
| 40 | + }, |
| 41 | + } |
| 42 | + |
| 43 | + return cmd |
| 44 | +} |
| 45 | + |
| 46 | +func orgInvitationTableOutput(items []*action.OrgInvitationItem) error { |
| 47 | + if len(items) == 0 { |
| 48 | + fmt.Println("there are no sent invitations") |
| 49 | + return nil |
| 50 | + } |
| 51 | + |
| 52 | + t := newTableWriter() |
| 53 | + t.AppendHeader(table.Row{"ID", "Org Name", "Receiver Email", "Status", "Created At"}) |
| 54 | + |
| 55 | + for _, i := range items { |
| 56 | + t.AppendRow(table.Row{i.ID, i.Organization.Name, i.ReceiverEmail, i.Status, i.CreatedAt.Format(time.RFC822)}) |
| 57 | + t.AppendSeparator() |
| 58 | + } |
| 59 | + |
| 60 | + t.Render() |
| 61 | + return nil |
| 62 | +} |
0 commit comments