Merge pull request #12153 from eparis/mangen

Update go-md2man so godep restore/save work
pull/6/head
Alex Mohr 2015-08-03 10:47:18 -07:00
commit 4575d4b155
9 changed files with 72 additions and 67 deletions

14
Godeps/Godeps.json generated
View File

@ -141,9 +141,9 @@
"Rev": "97e243d21a8e232e9d8af38ba2366dfcfceebeba" "Rev": "97e243d21a8e232e9d8af38ba2366dfcfceebeba"
}, },
{ {
"ImportPath": "github.com/cpuguy83/go-md2man/mangen", "ImportPath": "github.com/cpuguy83/go-md2man/md2man",
"Comment": "v1.0.2-5-g2831f11", "Comment": "v1.0.3-2-g71acacd",
"Rev": "2831f11f66ff4008f10e2cd7ed9a85e3d3fc2bed" "Rev": "71acacd42f85e5e82f70a55327789582a5200a90"
}, },
{ {
"ImportPath": "github.com/davecgh/go-spew/spew", "ImportPath": "github.com/davecgh/go-spew/spew",
@ -574,12 +574,12 @@
"Rev": "2e43671e4ad874a7bca65746ff3edb38e6e93762" "Rev": "2e43671e4ad874a7bca65746ff3edb38e6e93762"
}, },
{ {
"ImportPath": "gopkg.in/yaml.v2", "ImportPath": "gopkg.in/natefinch/lumberjack.v2",
"Rev": "d466437aa4adc35830964cffc5b5f262c63ddcb4" "Rev": "20b71e5b60d756d3d2f80def009790325acc2b23"
}, },
{ {
"ImportPath": "gopkg.in/natefinch/lumberjack.v2/", "ImportPath": "gopkg.in/yaml.v2",
"Rev": "20b71e5b60d756d3d2f80def009790325acc2b23" "Rev": "d466437aa4adc35830964cffc5b5f262c63ddcb4"
}, },
{ {
"ImportPath": "speter.net/go/exp/math/dec/inf", "ImportPath": "speter.net/go/exp/math/dec/inf",

View File

@ -0,0 +1,19 @@
package md2man
import (
"github.com/russross/blackfriday"
)
func Render(doc []byte) []byte {
renderer := RoffRenderer(0)
extensions := 0
extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
extensions |= blackfriday.EXTENSION_TABLES
extensions |= blackfriday.EXTENSION_FENCED_CODE
extensions |= blackfriday.EXTENSION_AUTOLINK
extensions |= blackfriday.EXTENSION_SPACE_HEADERS
extensions |= blackfriday.EXTENSION_FOOTNOTES
extensions |= blackfriday.EXTENSION_TITLEBLOCK
return blackfriday.Markdown(doc, renderer, extensions)
}

View File

@ -1,24 +1,25 @@
package mangen package md2man
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"html"
"strings" "strings"
"github.com/russross/blackfriday" "github.com/russross/blackfriday"
) )
type Man struct{} type roffRenderer struct{}
func ManRenderer(flags int) blackfriday.Renderer { func RoffRenderer(flags int) blackfriday.Renderer {
return &Man{} return &roffRenderer{}
} }
func (m *Man) GetFlags() int { func (r *roffRenderer) GetFlags() int {
return 0 return 0
} }
func (m *Man) TitleBlock(out *bytes.Buffer, text []byte) { func (r *roffRenderer) TitleBlock(out *bytes.Buffer, text []byte) {
out.WriteString(".TH ") out.WriteString(".TH ")
splitText := bytes.Split(text, []byte("\n")) splitText := bytes.Split(text, []byte("\n"))
@ -36,24 +37,23 @@ func (m *Man) TitleBlock(out *bytes.Buffer, text []byte) {
out.WriteString(" \"\"\n") out.WriteString(" \"\"\n")
} }
func (m *Man) BlockCode(out *bytes.Buffer, text []byte, lang string) { func (r *roffRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) {
out.WriteString("\n.PP\n.RS\n\n.nf\n") out.WriteString("\n.PP\n.RS\n\n.nf\n")
escapeSpecialChars(out, text) escapeSpecialChars(out, text)
out.WriteString("\n.fi\n.RE\n") out.WriteString("\n.fi\n.RE\n")
} }
func (m *Man) BlockQuote(out *bytes.Buffer, text []byte) { func (r *roffRenderer) BlockQuote(out *bytes.Buffer, text []byte) {
out.WriteString("\n.PP\n.RS\n") out.WriteString("\n.PP\n.RS\n")
out.Write(text) out.Write(text)
out.WriteString("\n.RE\n") out.WriteString("\n.RE\n")
} }
func (m *Man) BlockHtml(out *bytes.Buffer, text []byte) { func (r *roffRenderer) BlockHtml(out *bytes.Buffer, text []byte) {
fmt.Errorf("man: BlockHtml not supported")
out.Write(text) out.Write(text)
} }
func (m *Man) Header(out *bytes.Buffer, text func() bool, level int, id string) { func (r *roffRenderer) Header(out *bytes.Buffer, text func() bool, level int, id string) {
marker := out.Len() marker := out.Len()
switch { switch {
@ -74,11 +74,11 @@ func (m *Man) Header(out *bytes.Buffer, text func() bool, level int, id string)
} }
} }
func (m *Man) HRule(out *bytes.Buffer) { func (r *roffRenderer) HRule(out *bytes.Buffer) {
out.WriteString("\n.ti 0\n\\l'\\n(.lu'\n") out.WriteString("\n.ti 0\n\\l'\\n(.lu'\n")
} }
func (m *Man) List(out *bytes.Buffer, text func() bool, flags int) { func (r *roffRenderer) List(out *bytes.Buffer, text func() bool, flags int) {
marker := out.Len() marker := out.Len()
out.WriteString(".IP ") out.WriteString(".IP ")
if flags&blackfriday.LIST_TYPE_ORDERED != 0 { if flags&blackfriday.LIST_TYPE_ORDERED != 0 {
@ -94,12 +94,12 @@ func (m *Man) List(out *bytes.Buffer, text func() bool, flags int) {
} }
func (m *Man) ListItem(out *bytes.Buffer, text []byte, flags int) { func (r *roffRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
out.WriteString("\n\\item ") out.WriteString("\n\\item ")
out.Write(text) out.Write(text)
} }
func (m *Man) Paragraph(out *bytes.Buffer, text func() bool) { func (r *roffRenderer) Paragraph(out *bytes.Buffer, text func() bool) {
marker := out.Len() marker := out.Len()
out.WriteString("\n.PP\n") out.WriteString("\n.PP\n")
if !text() { if !text() {
@ -112,7 +112,7 @@ func (m *Man) Paragraph(out *bytes.Buffer, text func() bool) {
} }
// TODO: This might now work // TODO: This might now work
func (m *Man) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) { func (r *roffRenderer) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) {
out.WriteString(".TS\nallbox;\n") out.WriteString(".TS\nallbox;\n")
out.Write(header) out.Write(header)
@ -120,7 +120,7 @@ func (m *Man) Table(out *bytes.Buffer, header []byte, body []byte, columnData []
out.WriteString("\n.TE\n") out.WriteString("\n.TE\n")
} }
func (m *Man) TableRow(out *bytes.Buffer, text []byte) { func (r *roffRenderer) TableRow(out *bytes.Buffer, text []byte) {
if out.Len() > 0 { if out.Len() > 0 {
out.WriteString("\n") out.WriteString("\n")
} }
@ -128,7 +128,7 @@ func (m *Man) TableRow(out *bytes.Buffer, text []byte) {
out.WriteString("\n") out.WriteString("\n")
} }
func (m *Man) TableHeaderCell(out *bytes.Buffer, text []byte, align int) { func (r *roffRenderer) TableHeaderCell(out *bytes.Buffer, text []byte, align int) {
if out.Len() > 0 { if out.Len() > 0 {
out.WriteString(" ") out.WriteString(" ")
} }
@ -137,7 +137,7 @@ func (m *Man) TableHeaderCell(out *bytes.Buffer, text []byte, align int) {
} }
// TODO: This is probably broken // TODO: This is probably broken
func (m *Man) TableCell(out *bytes.Buffer, text []byte, align int) { func (r *roffRenderer) TableCell(out *bytes.Buffer, text []byte, align int) {
if out.Len() > 0 { if out.Len() > 0 {
out.WriteString("\t") out.WriteString("\t")
} }
@ -145,71 +145,68 @@ func (m *Man) TableCell(out *bytes.Buffer, text []byte, align int) {
out.WriteString("\t") out.WriteString("\t")
} }
func (m *Man) Footnotes(out *bytes.Buffer, text func() bool) { func (r *roffRenderer) Footnotes(out *bytes.Buffer, text func() bool) {
} }
func (m *Man) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) { func (r *roffRenderer) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) {
} }
func (m *Man) AutoLink(out *bytes.Buffer, link []byte, kind int) { func (r *roffRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) {
out.WriteString("\n\\[la]") out.WriteString("\n\\[la]")
out.Write(link) out.Write(link)
out.WriteString("\\[ra]") out.WriteString("\\[ra]")
} }
func (m *Man) CodeSpan(out *bytes.Buffer, text []byte) { func (r *roffRenderer) CodeSpan(out *bytes.Buffer, text []byte) {
out.WriteString("\\fB\\fC") out.WriteString("\\fB\\fC")
escapeSpecialChars(out, text) escapeSpecialChars(out, text)
out.WriteString("\\fR") out.WriteString("\\fR")
} }
func (m *Man) DoubleEmphasis(out *bytes.Buffer, text []byte) { func (r *roffRenderer) DoubleEmphasis(out *bytes.Buffer, text []byte) {
out.WriteString("\\fB") out.WriteString("\\fB")
out.Write(text) out.Write(text)
out.WriteString("\\fP") out.WriteString("\\fP")
} }
func (m *Man) Emphasis(out *bytes.Buffer, text []byte) { func (r *roffRenderer) Emphasis(out *bytes.Buffer, text []byte) {
out.WriteString("\\fI") out.WriteString("\\fI")
out.Write(text) out.Write(text)
out.WriteString("\\fP") out.WriteString("\\fP")
} }
func (m *Man) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) { func (r *roffRenderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) {
fmt.Errorf("man: Image not supported")
} }
func (m *Man) LineBreak(out *bytes.Buffer) { func (r *roffRenderer) LineBreak(out *bytes.Buffer) {
out.WriteString("\n.br\n") out.WriteString("\n.br\n")
} }
func (m *Man) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) { func (r *roffRenderer) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) {
m.AutoLink(out, link, 0) r.AutoLink(out, link, 0)
} }
func (m *Man) RawHtmlTag(out *bytes.Buffer, tag []byte) { func (r *roffRenderer) RawHtmlTag(out *bytes.Buffer, tag []byte) {
out.Write(tag) out.Write(tag)
} }
func (m *Man) TripleEmphasis(out *bytes.Buffer, text []byte) { func (r *roffRenderer) TripleEmphasis(out *bytes.Buffer, text []byte) {
out.WriteString("\\s+2") out.WriteString("\\s+2")
out.Write(text) out.Write(text)
out.WriteString("\\s-2") out.WriteString("\\s-2")
} }
func (m *Man) StrikeThrough(out *bytes.Buffer, text []byte) { func (r *roffRenderer) StrikeThrough(out *bytes.Buffer, text []byte) {
fmt.Errorf("man: strikethrough not supported")
} }
func (m *Man) FootnoteRef(out *bytes.Buffer, ref []byte, id int) { func (r *roffRenderer) FootnoteRef(out *bytes.Buffer, ref []byte, id int) {
} }
func (m *Man) Entity(out *bytes.Buffer, entity []byte) { func (r *roffRenderer) Entity(out *bytes.Buffer, entity []byte) {
// TODO: convert this into a unicode character or something out.WriteString(html.UnescapeString(string(entity)))
out.Write(entity)
} }
func processFooterText(text []byte) []byte { func processFooterText(text []byte) []byte {
@ -231,18 +228,18 @@ func processFooterText(text []byte) []byte {
return newText return newText
} }
func (m *Man) NormalText(out *bytes.Buffer, text []byte) { func (r *roffRenderer) NormalText(out *bytes.Buffer, text []byte) {
escapeSpecialChars(out, text) escapeSpecialChars(out, text)
} }
func (m *Man) DocumentHeader(out *bytes.Buffer) { func (r *roffRenderer) DocumentHeader(out *bytes.Buffer) {
} }
func (m *Man) DocumentFooter(out *bytes.Buffer) { func (r *roffRenderer) DocumentFooter(out *bytes.Buffer) {
} }
func needsBackslash(c byte) bool { func needsBackslash(c byte) bool {
for _, r := range []byte("-_{}&\\~") { for _, r := range []byte("-_&\\~") {
if c == r { if c == r {
return true return true
} }

View File

@ -26,8 +26,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/cmd/genutils" "github.com/GoogleCloudPlatform/kubernetes/cmd/genutils"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"github.com/cpuguy83/go-md2man/mangen" mangen "github.com/cpuguy83/go-md2man/md2man"
"github.com/russross/blackfriday"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@ -144,17 +143,7 @@ func genMarkdown(command *cobra.Command, parent, docsDir string) {
January 2015, Originally compiled by Eric Paris (eparis at redhat dot com) based on the kubernetes source material, but hopefully they have been automatically generated since! January 2015, Originally compiled by Eric Paris (eparis at redhat dot com) based on the kubernetes source material, but hopefully they have been automatically generated since!
`) `)
renderer := mangen.ManRenderer(0) final := mangen.Render(out.Bytes())
extensions := 0
extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
extensions |= blackfriday.EXTENSION_TABLES
extensions |= blackfriday.EXTENSION_FENCED_CODE
extensions |= blackfriday.EXTENSION_AUTOLINK
extensions |= blackfriday.EXTENSION_SPACE_HEADERS
extensions |= blackfriday.EXTENSION_FOOTNOTES
extensions |= blackfriday.EXTENSION_TITLEBLOCK
final := blackfriday.Markdown(out.Bytes(), renderer, extensions)
filename := docsDir + dname + ".1" filename := docsDir + dname + ".1"
outFile, err := os.Create(filename) outFile, err := os.Create(filename)

View File

@ -165,7 +165,7 @@ You can use \-\-output=template \-\-template=TEMPLATE to extract specific values
$ kubectl config view $ kubectl config view
// Get the password for the e2e user // Get the password for the e2e user
$ kubectl config view \-o template \-\-template='\{\{range .users\}\}\{\{ if eq .name "e2e" \}\}\{\{ index .user.password \}\}\{\{end\}\}\{\{end\}\}' $ kubectl config view \-o template \-\-template='{{range .users}}{{ if eq .name "e2e" }}{{ index .user.password }}{{end}}{{end}}'
.fi .fi
.RE .RE

View File

@ -19,7 +19,7 @@ config modifies kubeconfig files using subcommands like "kubectl config set curr
The loading order follows these rules: The loading order follows these rules:
1. If the \-\-kubeconfig flag is set, then only that file is loaded. The flag may only be set once and no merging takes place. 1. If the \-\-kubeconfig flag is set, then only that file is loaded. The flag may only be set once and no merging takes place.
2. If $KUBECONFIG environment variable is set, then it is used a list of paths (normal path delimitting rules for your system). These paths are merged together. When a value is modified, it is modified in the file that defines the stanza. When a value is created, it is created in the first file that exists. If no files in the chain exist, then it creates the last file in the list. 2. If $KUBECONFIG environment variable is set, then it is used a list of paths (normal path delimitting rules for your system). These paths are merged together. When a value is modified, it is modified in the file that defines the stanza. When a value is created, it is created in the first file that exists. If no files in the chain exist, then it creates the last file in the list.
3. Otherwise, $\{HOME\}/.kube/config is used and no merging takes place. 3. Otherwise, ${HOME}/.kube/config is used and no merging takes place.
.SH OPTIONS .SH OPTIONS

View File

@ -185,7 +185,7 @@ $ kubectl get replicationcontroller web
$ kubectl get \-o json pod web\-pod\-13je7 $ kubectl get \-o json pod web\-pod\-13je7
// Return only the phase value of the specified pod. // Return only the phase value of the specified pod.
$ kubectl get \-o template web\-pod\-13je7 \-\-template=\{\{.status.phase\}\} \-\-api\-version=v1 $ kubectl get \-o template web\-pod\-13je7 \-\-template={{.status.phase}} \-\-api\-version=v1
// List all replication controllers and services together in ps output format. // List all replication controllers and services together in ps output format.
$ kubectl get rc,services $ kubectl get rc,services

View File

@ -138,7 +138,7 @@ JSON and YAML formats are accepted.
.nf .nf
// Partially update a node using strategic merge patch // Partially update a node using strategic merge patch
kubectl patch node k8s\-node\-1 \-p '\{"spec":\{"unschedulable":true\}\}' kubectl patch node k8s\-node\-1 \-p '{"spec":{"unschedulable":true}}'
.fi .fi
.RE .RE

View File

@ -185,7 +185,7 @@ $ kubectl run nginx \-\-image=nginx \-\-replicas=5
$ kubectl run nginx \-\-image=nginx \-\-dry\-run $ kubectl run nginx \-\-image=nginx \-\-dry\-run
// Start a single instance of nginx, but overload the spec of the replication controller with a partial set of values parsed from JSON. // Start a single instance of nginx, but overload the spec of the replication controller with a partial set of values parsed from JSON.
$ kubectl run nginx \-\-image=nginx \-\-overrides='\{ "apiVersion": "v1", "spec": \{ ... \} \}' $ kubectl run nginx \-\-image=nginx \-\-overrides='{ "apiVersion": "v1", "spec": { ... } }'
.fi .fi
.RE .RE