mdexec

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2021 License: MIT Imports: 11 Imported by: 0

README

mdexec

Executes commands in a markdown file and embeds the result

Format

Prefix the commands as inline blocks e.g.:

`$ cat examples/log.yaml`

Which will embed the content of examples/log.yaml in the output markdown text.

Installation

go install github.com/aquilax/mdexec/cmd/mdexec

Cmd Usage

Run the command from the working directory

mdexec md_template_file.md > output.md

or

cat md_template_file.md | mdexec > output.md
mdexec -h
Usage: mdexec [OPTIONS] [FILE]
Execute commands in markdown and embeds the result in the output

FILE can be both file name or - to read from stdin

  -template string
        Template to use when rendering a command block (default "```sh\n$ {{ .Command }}\n{{ .Output }}\n```\n")

Fields available in the template:
  {{ .Command }}  string - the command that was executed
  {{ .Output }}   string - command output
  {{ .Error }}    error  - Execution error
  {{ .Duration }} int64  - execution duration in ns

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessStream

func ProcessStream(inStream io.Reader, outStream io.Writer, tmpl *template.Template) error

ProcessStream processes commands in the inStream rendering the tmpl template and writing the output to the outStream

func ProcessStreamWithExecutor

func ProcessStreamWithExecutor(inStream io.Reader, outStream io.Writer, tmpl *template.Template, executor Executor) error

ProcessStreamWithExecutor processes commands in the inStream rendering the tmpl template and writing the output to the outStream calling the executor function for each command

Types

type Executor

type Executor func(command string) (string, int64, error)

Executor is a function that when given command must return the output, the duration and optional error

type TemplateContext

type TemplateContext struct {
	Command  string
	Output   string
	Duration int64
	Error    error
}

TemplateContext contains all fields available in the template

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL