cmd/doc: added import path + better titles for package fields
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
parent
28a1e6a4c5
commit
776814910d
@ -46,6 +46,7 @@ type Field struct {
|
|||||||
|
|
||||||
type Package struct {
|
type Package struct {
|
||||||
Name string
|
Name string
|
||||||
|
ShortName string
|
||||||
Description string
|
Description string
|
||||||
Fields []Field
|
Fields []Field
|
||||||
}
|
}
|
||||||
@ -78,6 +79,8 @@ func Parse(ctx context.Context, packageName string, val *compiler.Value) *Packag
|
|||||||
pkg := &Package{}
|
pkg := &Package{}
|
||||||
// Package Name + Description
|
// Package Name + Description
|
||||||
pkg.Name = packageName
|
pkg.Name = packageName
|
||||||
|
parts := strings.Split(packageName, "/")
|
||||||
|
pkg.ShortName = parts[len(parts)-1:][0]
|
||||||
pkg.Description = common.ValueDocFull(val)
|
pkg.Description = common.ValueDocFull(val)
|
||||||
|
|
||||||
// Package Fields
|
// Package Fields
|
||||||
@ -140,6 +143,8 @@ func (p *Package) Text() string {
|
|||||||
fmt.Fprintf(w, "Package %s\n", p.Name)
|
fmt.Fprintf(w, "Package %s\n", p.Name)
|
||||||
fmt.Fprintf(w, "\n%s\n", p.Description)
|
fmt.Fprintf(w, "\n%s\n", p.Description)
|
||||||
|
|
||||||
|
fmt.Fprintf(w, "\nimport %q\n", p.Name)
|
||||||
|
|
||||||
printValuesText := func(values []Value) {
|
printValuesText := func(values []Value) {
|
||||||
tw := tabwriter.NewWriter(w, 0, 4, len(textPadding), ' ', 0)
|
tw := tabwriter.NewWriter(w, 0, 4, len(textPadding), ' ', 0)
|
||||||
for _, i := range values {
|
for _, i := range values {
|
||||||
@ -151,7 +156,7 @@ func (p *Package) Text() string {
|
|||||||
|
|
||||||
// Package Fields
|
// Package Fields
|
||||||
for _, field := range p.Fields {
|
for _, field := range p.Fields {
|
||||||
fmt.Fprintf(w, "\n%s\n\n%s%s\n", field.Name, textPadding, field.Description)
|
fmt.Fprintf(w, "\n%s.%s\n\n%s%s\n", p.ShortName, field.Name, textPadding, field.Description)
|
||||||
if len(field.Inputs) == 0 {
|
if len(field.Inputs) == 0 {
|
||||||
fmt.Fprintf(w, "\n%sInputs: none\n", textPadding)
|
fmt.Fprintf(w, "\n%sInputs: none\n", textPadding)
|
||||||
} else {
|
} else {
|
||||||
@ -197,6 +202,8 @@ func (p *Package) Markdown() string {
|
|||||||
fmt.Fprintf(w, "\n%s\n", mdEscape(p.Description))
|
fmt.Fprintf(w, "\n%s\n", mdEscape(p.Description))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(w, "\n```cue\nimport %q\n```\n", p.Name)
|
||||||
|
|
||||||
printValuesMarkdown := func(values []Value) {
|
printValuesMarkdown := func(values []Value) {
|
||||||
tw := tabwriter.NewWriter(w, 0, 4, len(textPadding), ' ', 0)
|
tw := tabwriter.NewWriter(w, 0, 4, len(textPadding), ' ', 0)
|
||||||
fmt.Fprintf(tw, "| Name\t| Type\t| Description \t|\n")
|
fmt.Fprintf(tw, "| Name\t| Type\t| Description \t|\n")
|
||||||
@ -213,19 +220,21 @@ func (p *Package) Markdown() string {
|
|||||||
|
|
||||||
// Package Fields
|
// Package Fields
|
||||||
for _, field := range p.Fields {
|
for _, field := range p.Fields {
|
||||||
fmt.Fprintf(w, "\n## %s\n\n", field.Name)
|
fieldLabel := fmt.Sprintf("%s.%s", p.ShortName, field.Name)
|
||||||
|
|
||||||
|
fmt.Fprintf(w, "\n## %s\n\n", fieldLabel)
|
||||||
if field.Description != "-" {
|
if field.Description != "-" {
|
||||||
fmt.Fprintf(w, "%s\n\n", mdEscape(field.Description))
|
fmt.Fprintf(w, "%s\n\n", mdEscape(field.Description))
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(w, "### %s Inputs\n\n", mdEscape(field.Name))
|
fmt.Fprintf(w, "### %s Inputs\n\n", mdEscape(fieldLabel))
|
||||||
if len(field.Inputs) == 0 {
|
if len(field.Inputs) == 0 {
|
||||||
fmt.Fprintf(w, "_No input._\n")
|
fmt.Fprintf(w, "_No input._\n")
|
||||||
} else {
|
} else {
|
||||||
printValuesMarkdown(field.Inputs)
|
printValuesMarkdown(field.Inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(w, "\n### %s Outputs\n\n", mdEscape(field.Name))
|
fmt.Fprintf(w, "\n### %s Outputs\n\n", mdEscape(fieldLabel))
|
||||||
if len(field.Outputs) == 0 {
|
if len(field.Outputs) == 0 {
|
||||||
fmt.Fprintf(w, "_No output._\n")
|
fmt.Fprintf(w, "_No output._\n")
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user