<commit_before>package std

import (
	"io/ioutil"
	"os/exec"
	"path/filepath"
	"strings"

	"github.com/mh-cbon/emd/emd"
)

// Register standard helpers to the generator.
func Register(g *emd.Generator) error {

	g.AddFunc("file", func(f string) (string, error) {
		s, err := ioutil.ReadFile(f)
		res := `
__> ` + f + `__
` + "```go" + `
` + strings.TrimSpace(string(s)) + `
` + "```"
		return res, err
	})

	g.AddFunc("cli", func(bin string, args ...string) (string, error) {
		cmd := exec.Command(bin, args...)
		out, err := cmd.CombinedOutput()
		fbin := filepath.Base(bin)
		res := `
__$ ` + fbin + ` ` + strings.Join(args, " ") + `__
` + "```sh" + `
` + strings.TrimSpace(string(out)) + `
` + "```"
		return res, err
	})

	g.AddTemplate(`{{define "gh/releases" -}}
Check the [release page](https://github.com/{{.User}}/{{.Name}}/releases)!
{{- end}}`)

	g.AddTemplate(`{{define "badge/travis" -}}
[![Build Status](https://travis-ci.org/{{.User}}/{{.Name}}.svg?branch={{.Branch}})](https://travis-ci.org/{{.User}}/{{.Name}})
{{- end}}`)

	g.AddTemplate(`{{define "badge/appveyor" -}}
[![Build Status](https://ci.appveyor.com/api/projects/status/.ProviderName/{{.User}}/{{.Name}}?branch={{.Branch}}&svg=true)](https://ci.appveyor.com/api/projects/status/.ProviderName/{{.User}}/{{.Name}}?branch={{.Branch}}&svg=true)
{{- end}}`)

	g.AddTemplate(`{{define "choco/install" -}}
` + "```sh" + `
choco install {{.Name}}
` + "```" + `
{{- end}}`)

	g.AddTemplate(`{{define "linux/gh_src_repo" -}}
` + "```sh" + `
wget -O - https://raw.githubusercontent.com/mh-cbon/latest/master/source.sh \
| GH={{.User}}/{{.Name}} sh -xe
# or
curl -L https://raw.githubusercontent.com/mh-cbon/latest/master/source.sh \
| GH={{.User}}/{{.Name}} sh -xe
` + "```" + `
{{- end}}`)

	g.AddTemplate(`{{define "linux/gh_pkg" -}}
` + "```sh" + `<commit_msg>badge(update): update text displayed in ci badges<commit_after>package std

import (
	"io/ioutil"
	"os/exec"
	"path/filepath"
	"strings"

	"github.com/mh-cbon/emd/emd"
)

// Register standard helpers to the generator.
func Register(g *emd.Generator) error {

	g.AddFunc("file", func(f string) (string, error) {
		s, err := ioutil.ReadFile(f)
		res := `
__> ` + f + `__
` + "```go" + `
` + strings.TrimSpace(string(s)) + `
` + "```"
		return res, err
	})

	g.AddFunc("cli", func(bin string, args ...string) (string, error) {
		cmd := exec.Command(bin, args...)
		out, err := cmd.CombinedOutput()
		fbin := filepath.Base(bin)
		res := `
__$ ` + fbin + ` ` + strings.Join(args, " ") + `__
` + "```sh" + `
` + strings.TrimSpace(string(out)) + `
` + "```"
		return res, err
	})

	g.AddTemplate(`{{define "gh/releases" -}}
Check the [release page](https://github.com/{{.User}}/{{.Name}}/releases)!
{{- end}}`)

	g.AddTemplate(`{{define "badge/travis" -}}
[![travis Status](https://travis-ci.org/{{.User}}/{{.Name}}.svg?branch={{.Branch}})](https://travis-ci.org/{{.User}}/{{.Name}})
{{- end}}`)

	g.AddTemplate(`{{define "badge/appveyor" -}}
[![appveyor Status](https://ci.appveyor.com/api/projects/status/.ProviderName/{{.User}}/{{.Name}}?branch={{.Branch}}&svg=true)](https://ci.appveyor.com/api/projects/status/.ProviderName/{{.User}}/{{.Name}}?branch={{.Branch}}&svg=true)
{{- end}}`)

	g.AddTemplate(`{{define "choco/install" -}}
` + "```sh" + `
choco install {{.Name}}
` + "```" + `
{{- end}}`)

	g.AddTemplate(`{{define "linux/gh_src_repo" -}}
` + "```sh" + `
wget -O - https://raw.githubusercontent.com/mh-cbon/latest/master/source.sh \
| GH={{.User}}/{{.Name}} sh -xe
# or
curl -L https://raw.githubusercontent.com/mh-cbon/latest/master/source.sh \
| GH={{.User}}/{{.Name}} sh -xe
` + "```" + `
{{- end}}`)

	g.AddTemplate(`{{define "linux/gh_pkg" -}}
` + "```sh" + `
{'fraction_non_alphanumeric': 0.2797297297297297, 'fraction_numerical': 0.0, 'mean_word_length': 3.9280958721704393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 14, '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': '556097', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1491, 'n_words': 206}