<commit_before>/*
 * Minio Client (C) 2016 Minio, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package mc

import (
	"encoding/json"

	"github.com/fatih/color"
	"github.com/minio/cli"
	"github.com/minio/mc/pkg/console"
	"github.com/minio/minio/pkg/probe"
)

var (
	eventsListFlags = []cli.Flag{}
)

var eventsListCmd = cli.Command{
	Name:   "list",
	Usage:  "List bucket notifications.",
	Action: mainEventsList,
	Flags:  append(eventsListFlags, globalFlags...),
	CustomHelpTemplate: `NAME:
   mc events {{.Name}} - {{.Usage}}

USAGE:
   mc events {{.Name}} ALIAS/BUCKET ARN [FLAGS]

FLAGS:
  {{range .Flags}}{{.}}
  {{end}}
EXAMPLES:
   1. List notification configurations associated to a specific arn
     $ mc events {{.Name}} myminio/mybucket arn:aws:sqs:us-west-2:444455556666:your-queue 
   2. List all notification configurations
     $ mc events {{.Name}} s3/mybucket
`,
}

// checkEventsListSyntax - validate all the passed arguments
func checkEventsListSyntax(ctx *cli.Context) {
	if len(ctx.Args()) != 2 && len(ctx.Args()) != 1 {
		cli.ShowCommandHelpAndExit(ctx, "list", 1) // last argument is exit code
	}
}

// eventsListMessage container
type eventsListMessage struct {
	Status string   `json:"status"`
	ID     string   `json:"id"`
	Events []string `json:"events"`
	Prefix string   `json:"prefix"`
	Suffix string   `json:"suffix"`
	Arn    string   `json:"arn"`
}

func (u eventsListMessage) JSON() string {
	u.Status = "success"
	eventsListMessageJSONBytes, e := json.Marshal(u)
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
	return string(eventsListMessageJSONBytes)
}

func (u eventsListMessage) String() string {
	msg := console.Colorize("Events", u.ID+"\t"+u.Arn+"\t")
	for i, event := range u.Events {
		msg += console.Colorize("Events", event)
		if i != len(u.Events)-1 {
			msg += ","
		}
	}
	if u.Prefix != "" {
		msg += "\tprefix:" + u.Prefix
	}
	if u.Suffix != "" {
		msg += "\tsuffix:" + u.Suffix
	}
	return msg
}

func mainEventsList(ctx *cli.Context) {
	console.SetColor("Events", color.New(color.FgGreen, color.Bold))
<commit_msg>Add colors properly for events.<commit_after>/*
 * Minio Client (C) 2016 Minio, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package mc

import (
	"encoding/json"
	"fmt"

	"github.com/fatih/color"
	"github.com/minio/cli"
	"github.com/minio/mc/pkg/console"
	"github.com/minio/minio/pkg/probe"
)

var (
	eventsListFlags = []cli.Flag{}
)

var eventsListCmd = cli.Command{
	Name:   "list",
	Usage:  "List bucket notifications.",
	Action: mainEventsList,
	Flags:  append(eventsListFlags, globalFlags...),
	CustomHelpTemplate: `NAME:
   mc events {{.Name}} - {{.Usage}}

USAGE:
   mc events {{.Name}} ALIAS/BUCKET ARN [FLAGS]

FLAGS:
  {{range .Flags}}{{.}}
  {{end}}
EXAMPLES:
   1. List notification configurations associated to a specific arn
     $ mc events {{.Name}} myminio/mybucket arn:aws:sqs:us-west-2:444455556666:your-queue 
   2. List all notification configurations
     $ mc events {{.Name}} s3/mybucket
`,
}

// checkEventsListSyntax - validate all the passed arguments
func checkEventsListSyntax(ctx *cli.Context) {
	if len(ctx.Args()) != 2 && len(ctx.Args()) != 1 {
		cli.ShowCommandHelpAndExit(ctx, "list", 1) // last argument is exit code
	}
}

// eventsListMessage container
type eventsListMessage struct {
	Status string   `json:"status"`
	ID     string   `json:"id"`
	Events []string `json:"events"`
	Prefix string   `json:"prefix"`
	Suffix string   `json:"suffix"`
	Arn    string   `json:"arn"`
}

func (u eventsListMessage) JSON() string {
	u.Status = "success"
	eventsListMessageJSONBytes, e := json.Marshal(u)
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
	return string(eventsListMessageJSONBytes)
}

func (u eventsListMessage) String() string {
	msg := console.Colorize("ARN", fmt.Sprintf("%s   ", u.Arn))
	for i, event := range u.Events {
		msg += console.Colorize("Events", event)
		if i != len(u.Events)-1 {
			msg += ","
		}
	}
	msg += console.Colorize("Filter", fmt.Sprintf("   Filter: "))
	if u.Prefix != "" {
		msg += console.Colorize("Filter", fmt.Sprintf("prefix=\"%s\"", u.Prefix))
	}
	if u.Suffix != "" {
		msg += console.Colorize("Filter", fmt.Sprintf("suffix=\"%s\"", u.Suffix))
	}
	return msg
}

func mainEventsList(ctx *cli.Context) {
	console.SetColor("ARN", color.New(color.FgGreen, color.Bold))
	console.SetColor("Events", color.New(color.FgCyan, color.Bold))
	console.SetColor("Filter", color.New(color.Bold))

{'fraction_non_alphanumeric': 0.14658158614402916, 'fraction_numerical': 0.010209662716499545, 'mean_word_length': 3.955736224028907, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2801132', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1811, 'n_words': 521}