processes bitches
This commit is contained in:
parent
2a5d37fad3
commit
7d8b99197f
@ -16,3 +16,4 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// todo: full command lines with bash
|
// todo: full command lines with bash
|
||||||
|
// todo: piping in stdin
|
||||||
|
@ -1,30 +1,54 @@
|
|||||||
|
// Generate HTTML document form a Go source file.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"io/ioutil"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Just be sure to blow up on non-nil errors.
|
||||||
func check(err error) {
|
func check(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func markdown(path, source string) string {
|
||||||
var err error
|
cmd := exec.Command(path)
|
||||||
|
in, err := cmd.StdinPipe()
|
||||||
|
check(err)
|
||||||
|
out, err := cmd.StdoutPipe()
|
||||||
|
check(err)
|
||||||
|
err = cmd.Start()
|
||||||
|
check(err)
|
||||||
|
in.Write([]byte(source))
|
||||||
|
check(err)
|
||||||
|
err = in.Close()
|
||||||
|
check(err)
|
||||||
|
bytes, err := ioutil.ReadAll(out)
|
||||||
|
check(err)
|
||||||
|
err = cmd.Wait()
|
||||||
|
check(err)
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
// Accept exactly 1 argument - the input filename.
|
// Accept exactly 1 argument - the input filename.
|
||||||
if len(os.Args) != 2 {
|
if len(os.Args) != 2 {
|
||||||
fmt.Fprintln(os.Stderr, "Usage: tool/generate input.go > output.html")
|
fmt.Fprintln(os.Stderr, "Usage: tool/generate input.go > output.html")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that we have `markdown` and `pygmentize` binaries.
|
// Ensure that we have `markdown` and `pygmentize`,
|
||||||
|
// binaries, remember their paths.
|
||||||
markdownPath, err := exec.LookPath("markdown");
|
markdownPath, err := exec.LookPath("markdown");
|
||||||
check(err)
|
check(err)
|
||||||
pygmentizePath, err := exec.LookPath("pygmentize")
|
fmt.Print(markdown(markdownPath, "## wat"))
|
||||||
check(err)
|
// pygmentizePath, err := exec.LookPath("pygmentize")
|
||||||
fmt.Println(markdownPath, pygmentizePath)
|
// check(err)
|
||||||
|
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user