Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor: deprecate cli/file helper #7

Closed
mh-cbon opened this issue Apr 11, 2017 · 0 comments
Closed

minor: deprecate cli/file helper #7

mh-cbon opened this issue Apr 11, 2017 · 0 comments

Comments

@mh-cbon
Copy link
Owner

mh-cbon commented Apr 11, 2017

file and cli helpers are defined as

https://github.com/mh-cbon/emd/blob/master/std/emd.go#L17
https://github.com/mh-cbon/emd/blob/master/std/emd.go#L59

they both embed the body response with a md block code markup like this,

res := `
###### $ ` + fbin + ` ` + strings.Join(args, " ") + `
` + "```sh" + `
` + strings.TrimSpace(string(out)) + `
` + "```"

It is made that way because when they was written,
the generator instance g *emd.Generator did not implement,
GetOut method,
https://github.com/mh-cbon/emd/blob/master/emd/emd.go#L75

They simply returned a formatted string block.

Now that getout method exists, it is possible to change that.

  1. write a new helper to decorate a string block color, to produce the same output as today
{{exec "ls" | color "sh"}}
{{exec "cat maing.go" | color "go"}}
  1. deprecate cli / file, but keep them for compatibility (avoid major bump)

  2. add new exec/cat

the implementation must differ to take advantage of GetOut method to
directly write on it, and return only the body response.

	g.AddFunc("cat", func(f string) (string, error) {
		s, err := ioutil.ReadFile(f)
if err != nil {
return "", err
}
		res := "\n###### > " + f + "\n"
g.GetOut.Write([]byte(res))// err ?
		return strings.TrimSpace(string(s)), nil
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant