mirror of https://github.com/databricks/cli.git
fix: Remove extra dependency
This commit is contained in:
parent
33bd3b81cb
commit
b91bb4d167
|
@ -5,18 +5,10 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
md "github.com/nao1215/markdown"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func buildMarkdown(nodes []rootNode, outputFile, header string) error {
|
func buildMarkdown(nodes []rootNode, outputFile, header string) error {
|
||||||
f, err := os.Create(outputFile)
|
m := newMardownRenderer()
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
m := md.NewMarkdown(f)
|
|
||||||
m = m.PlainText(header)
|
m = m.PlainText(header)
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
m = m.LF()
|
m = m.LF()
|
||||||
|
@ -56,12 +48,15 @@ func buildMarkdown(nodes []rootNode, outputFile, header string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = m.Build()
|
f, err := os.Create(outputFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
_, err = f.WriteString(m.String())
|
||||||
return nil
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func pickLastWord(s string) string {
|
func pickLastWord(s string) string {
|
||||||
|
@ -70,7 +65,7 @@ func pickLastWord(s string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build a custom table which we use in Databricks website
|
// Build a custom table which we use in Databricks website
|
||||||
func buildCustomAttributeTable(m *md.Markdown, attributes []attributeNode) *md.Markdown {
|
func buildAttributeTable(m *markdownRenderer, attributes []attributeNode) *markdownRenderer {
|
||||||
m = m.LF()
|
m = m.LF()
|
||||||
m = m.PlainText(".. list-table::")
|
m = m.PlainText(".. list-table::")
|
||||||
m = m.PlainText(" :header-rows: 1")
|
m = m.PlainText(" :header-rows: 1")
|
||||||
|
@ -90,23 +85,6 @@ func buildCustomAttributeTable(m *md.Markdown, attributes []attributeNode) *md.M
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildAttributeTable(m *md.Markdown, attributes []attributeNode) *md.Markdown {
|
|
||||||
return buildCustomAttributeTable(m, attributes)
|
|
||||||
|
|
||||||
// Rows below are useful for debugging since it renders the table in a regular markdown format
|
|
||||||
|
|
||||||
// rows := [][]string{}
|
|
||||||
// for _, n := range attributes {
|
|
||||||
// rows = append(rows, []string{fmt.Sprintf("`%s`", n.Title), n.Type, formatDescription(n.Description)})
|
|
||||||
// }
|
|
||||||
// m = m.CustomTable(md.TableSet{
|
|
||||||
// Header: []string{"Key", "Type", "Description"},
|
|
||||||
// Rows: rows,
|
|
||||||
// }, md.TableOptions{AutoWrapText: false, AutoFormatHeaders: false})
|
|
||||||
|
|
||||||
// return m
|
|
||||||
}
|
|
||||||
|
|
||||||
func formatDescription(a attributeNode) string {
|
func formatDescription(a attributeNode) string {
|
||||||
s := strings.ReplaceAll(a.Description, "\n", " ")
|
s := strings.ReplaceAll(a.Description, "\n", " ")
|
||||||
if a.Reference != "" {
|
if a.Reference != "" {
|
||||||
|
@ -115,7 +93,7 @@ func formatDescription(a attributeNode) string {
|
||||||
} else if s != "" {
|
} else if s != "" {
|
||||||
s += ". "
|
s += ". "
|
||||||
}
|
}
|
||||||
s += fmt.Sprintf("See %s.", md.Link("_", "#"+a.Reference))
|
s += fmt.Sprintf("See [_](#%s).", a.Reference)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type markdownRenderer struct {
|
||||||
|
nodes []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMardownRenderer() *markdownRenderer {
|
||||||
|
return &markdownRenderer{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *markdownRenderer) add(s string) *markdownRenderer {
|
||||||
|
m.nodes = append(m.nodes, s)
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *markdownRenderer) PlainText(s string) *markdownRenderer {
|
||||||
|
return m.add(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *markdownRenderer) LF() *markdownRenderer {
|
||||||
|
return m.add(" ")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *markdownRenderer) H2(s string) *markdownRenderer {
|
||||||
|
return m.add("## " + s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *markdownRenderer) H3(s string) *markdownRenderer {
|
||||||
|
return m.add("### " + s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *markdownRenderer) CodeBlocks(lang, s string) *markdownRenderer {
|
||||||
|
return m.add(fmt.Sprintf("```%s%s%s%s```", lang, lineFeed(), s, lineFeed()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *markdownRenderer) String() string {
|
||||||
|
return strings.Join(m.nodes, lineFeed())
|
||||||
|
}
|
||||||
|
|
||||||
|
func lineFeed() string {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return "\r\n"
|
||||||
|
}
|
||||||
|
return "\n"
|
||||||
|
}
|
5
go.mod
5
go.mod
|
@ -34,8 +34,6 @@ require (
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/nao1215/markdown v0.6.0
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cloud.google.com/go/auth v0.4.2 // indirect
|
cloud.google.com/go/auth v0.4.2 // indirect
|
||||||
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
|
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
|
||||||
|
@ -56,10 +54,7 @@ require (
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||||
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
|
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/karrick/godirwalk v1.17.0 // indirect
|
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
|
||||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/stretchr/objx v0.5.2 // indirect
|
github.com/stretchr/objx v0.5.2 // indirect
|
||||||
github.com/tidwall/gjson v1.18.0 // indirect
|
github.com/tidwall/gjson v1.18.0 // indirect
|
||||||
|
|
|
@ -115,8 +115,6 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
|
||||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
||||||
github.com/karrick/godirwalk v1.17.0 h1:b4kY7nqDdioR/6qnbHQyDvmA17u5G1cZ6J+CZXwSWoI=
|
|
||||||
github.com/karrick/godirwalk v1.17.0/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
|
|
||||||
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
|
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
|
||||||
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||||
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
|
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
|
||||||
|
@ -129,14 +127,8 @@ github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOA
|
||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
|
||||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
|
||||||
github.com/nao1215/markdown v0.6.0 h1:kqhrC47K434YA1jMTUwJwSV/hla8ifN3NzehMEffI/E=
|
|
||||||
github.com/nao1215/markdown v0.6.0/go.mod h1:ObBhnNduWwPN+bu4dtv4JoLRt57ONla7l//03iHIVhY=
|
|
||||||
github.com/nwidger/jsoncolor v0.3.2 h1:rVJJlwAWDJShnbTYOQ5RM7yTA20INyKXlJ/fg4JMhHQ=
|
github.com/nwidger/jsoncolor v0.3.2 h1:rVJJlwAWDJShnbTYOQ5RM7yTA20INyKXlJ/fg4JMhHQ=
|
||||||
github.com/nwidger/jsoncolor v0.3.2/go.mod h1:Cs34umxLbJvgBMnVNVqhji9BhoT/N/KinHqZptQ7cf4=
|
github.com/nwidger/jsoncolor v0.3.2/go.mod h1:Cs34umxLbJvgBMnVNVqhji9BhoT/N/KinHqZptQ7cf4=
|
||||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
|
||||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
|
||||||
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
|
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
|
||||||
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
|
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
|
||||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
|
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
|
||||||
|
|
Loading…
Reference in New Issue