<commit_before>package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strings"
	"text/template"

	"github.com/codegangsta/cli"
	"github.com/hashicorp/atlas-go/v1"
)

var (
	Version string
)

func init() {
	log.SetOutput(ioutil.Discard)
}

func ToJson(obj interface{}) (interface{}, error) {
	data, err := json.Marshal(obj)
	if err != nil {
		return nil, err
	}
	return string(data), nil
}

func search(c *cli.Context) {

	if c.String("user") == "" || c.String("artifact") == "" || c.String("type") == "" {
		cli.ShowAppHelp(c)
		os.Exit(1)
	}

	searchOpts := &atlas.ArtifactSearchOpts{
		User: c.String("user"),
		Name: c.String("artifact"),
		Type: c.String("type"),
	}
	if len(c.StringSlice("meta")) > 0 {
		filter := map[string]string{}
		for _, m := range c.StringSlice("meta") {
			pair := strings.Split(m, "=")
			filter[pair[0]] = pair[1]
		}
		fmt.Fprintf(os.Stderr, "FILTER: %#v\n", filter)
		searchOpts.Metadata = filter
	}
	client := atlas.DefaultClient()

	versions, err := client.ArtifactSearch(searchOpts)
	if err != nil {
		fmt.Errorf("search error: %#v", err)
		os.Exit(1)
	}

	fnMap := template.FuncMap{}
	fnMap["json"] = ToJson
	tmpl, err := template.New("artifact").Funcs(fnMap).Parse(c.String("format") + "\n")
	if err != nil {
		panic(err)
	}

	for _, v := range versions {
		//fmt.Println("ver: %#v", v)
		err = tmpl.Execute(os.Stdout, v)
		if err != nil {
			panic(err)
		}
	}

}

func main() {
	fmt.Fprintln(os.Stderr, "Search atlas.hashicorp artifacts ...")

	app := cli.NewApp()
	app.Name = "atlifacts"
	app.Usage = "query atlas.hashicorp.com artifacts"
	app.Version = Version

	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "user, u",
			Usage:  "atlas user",
			EnvVar: "ATLAS_USER",
		},
		cli.StringFlag{
			Name:   "artifact, a",
			Usage:  "atlas artifact",
			EnvVar: "ATLAS_ARTIFACT_NAME",
		},
		cli.StringFlag{
			Name:   "type, t",
			Usage:  "atlas artifact type",
			EnvVar: "ATLAS_ARTIFACT_TYPE",
		},
		cli.StringFlag{
			Name:  "format, f",
			Value: "{{.Slug}}",
			Usage: "output format in golang template",
		},
		cli.StringSliceFlag{
			Name:  "meta, m",
			Usage: "meta field as fielter",
		},
	}
	app.Action = search

	app.Run(os.Args)

}<commit_msg>Fixing typo<commit_after>package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strings"
	"text/template"

	"github.com/codegangsta/cli"
	"github.com/hashicorp/atlas-go/v1"
)

var (
	Version string
)

func init() {
	log.SetOutput(ioutil.Discard)
}

func ToJson(obj interface{}) (interface{}, error) {
	data, err := json.Marshal(obj)
	if err != nil {
		return nil, err
	}
	return string(data), nil
}

func search(c *cli.Context) {

	if c.String("user") == "" || c.String("artifact") == "" || c.String("type") == "" {
		cli.ShowAppHelp(c)
		os.Exit(1)
	}

	searchOpts := &atlas.ArtifactSearchOpts{
		User: c.String("user"),
		Name: c.String("artifact"),
		Type: c.String("type"),
	}
	if len(c.StringSlice("meta")) > 0 {
		filter := map[string]string{}
		for _, m := range c.StringSlice("meta") {
			pair := strings.Split(m, "=")
			filter[pair[0]] = pair[1]
		}
		fmt.Fprintf(os.Stderr, "FILTER: %#v\n", filter)
		searchOpts.Metadata = filter
	}
	client := atlas.DefaultClient()

	versions, err := client.ArtifactSearch(searchOpts)
	if err != nil {
		fmt.Errorf("search error: %#v", err)
		os.Exit(1)
	}

	fnMap := template.FuncMap{}
	fnMap["json"] = ToJson
	tmpl, err := template.New("artifact").Funcs(fnMap).Parse(c.String("format") + "\n")
	if err != nil {
		panic(err)
	}

	for _, v := range versions {
		//fmt.Println("ver: %#v", v)
		err = tmpl.Execute(os.Stdout, v)
		if err != nil {
			panic(err)
		}
	}

}

func main() {
	fmt.Fprintln(os.Stderr, "Search atlas.hashicorp artifacts ...")

	app := cli.NewApp()
	app.Name = "atlifacts"
	app.Usage = "query atlas.hashicorp.com artifacts"
	app.Version = Version

	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "user, u",
			Usage:  "atlas user",
			EnvVar: "ATLAS_USER",
		},
		cli.StringFlag{
			Name:   "artifact, a",
			Usage:  "atlas artifact",
			EnvVar: "ATLAS_ARTIFACT_NAME",
		},
		cli.StringFlag{
			Name:   "type, t",
			Usage:  "atlas artifact type",
			EnvVar: "ATLAS_ARTIFACT_TYPE",
		},
		cli.StringFlag{
			Name:  "format, f",
			Value: "{{.Slug}}",
			Usage: "output format in golang template",
		},
		cli.StringSliceFlag{
			Name:  "meta, m",
			Usage: "meta field as filter",
		},
	}
	app.Action = search

	app.Run(os.Args)

}
{'fraction_non_alphanumeric': 0.18979087024960647, 'fraction_numerical': 0.0026984483921744995, 'mean_word_length': 3.465863453815261, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6447796', 'n_tokens_mistral': 1962, 'n_tokens_neox': 1796, 'n_words': 361}