(ctx context.Context, app string)
| 13 | ) |
| 14 | |
| 15 | func List(ctx context.Context, app string) error { |
| 16 | c, err := config.ScalingoClient(ctx) |
| 17 | if err != nil { |
| 18 | return errors.Wrapf(ctx, err, "fail to get Scalingo client") |
| 19 | } |
| 20 | notifiers, err := c.NotifiersList(ctx, app) |
| 21 | if err != nil { |
| 22 | return errors.Wrapf(ctx, err, "list notifiers on app %s", app) |
| 23 | } |
| 24 | |
| 25 | t := tablewriter.NewWriter(os.Stdout) |
| 26 | t.Header([]string{"ID", "Type", "Name", "Enabled", "Send all events", "Selected events"}) |
| 27 | |
| 28 | eventTypes, err := c.EventTypesList(ctx) |
| 29 | if err != nil { |
| 30 | return errors.Wrapf(ctx, err, "fail to list event types") |
| 31 | } |
| 32 | |
| 33 | for _, notifier := range notifiers { |
| 34 | selectedEvents := "All" |
| 35 | if !notifier.GetSendAllEvents() { |
| 36 | selectedEvents = eventTypesToString(eventTypes, notifier.GetSelectedEventIDs()) |
| 37 | } |
| 38 | t.Append([]string{ |
| 39 | notifier.GetID(), string(notifier.GetType()), notifier.GetName(), |
| 40 | strconv.FormatBool(notifier.IsActive()), strconv.FormatBool(notifier.GetSendAllEvents()), |
| 41 | selectedEvents, |
| 42 | }) |
| 43 | } |
| 44 | t.Render() |
| 45 | |
| 46 | return nil |
| 47 | } |
| 48 | |
| 49 | func eventTypesToString(eventTypes []scalingo.EventType, ids []string) string { |
| 50 | res := "" |
no test coverage detected