Skip to content

Commit

Permalink
Add support for word wrap to disco
Browse files Browse the repository at this point in the history
  • Loading branch information
hasty committed Jul 15, 2024
1 parent acd55fb commit 2266b6d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
14 changes: 12 additions & 2 deletions cmd/disco/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package disco
import (
"context"

"github.com/project-chip/alchemy/asciidoc/render"
"github.com/project-chip/alchemy/disco"
"github.com/project-chip/alchemy/internal/files"
"github.com/project-chip/alchemy/internal/pipeline"
Expand All @@ -24,11 +25,10 @@ func discoBall(cmd *cobra.Command, args []string) (err error) {

pipelineOptions := pipeline.Flags(cmd)
fileOptions := files.Flags(cmd)
discoOptions := getDiscoOptions(cmd)

writer := files.NewWriter[string]("Writing disco-balled docs", fileOptions)

err = disco.Pipeline(cxt, specRoot, args, pipelineOptions, discoOptions, writer)
err = disco.Pipeline(cxt, specRoot, args, pipelineOptions, getDiscoOptions(cmd), getRenderOptions(cmd), writer)

return
}
Expand All @@ -50,6 +50,7 @@ func init() {
Command.Flags().Bool("addSpaceAfterPunctuation", true, "add missing space after punctuation")
Command.Flags().Bool("removeExtraSpaces", true, "remove extraneous spaces")
Command.Flags().Bool("disambiguateConformanceChoice", false, "ensure conformance choices are only used once per document")
Command.Flags().Int("wrap", 0, "the maximum length of a line")
}

type discoOption func(bool) disco.Option
Expand Down Expand Up @@ -82,3 +83,12 @@ func getDiscoOptions(cmd *cobra.Command) []disco.Option {
}
return discoOptions
}

func getRenderOptions(cmd *cobra.Command) []render.Option {
var renderOptions []render.Option
wrap, err := cmd.Flags().GetInt("wrap")
if err == nil {
renderOptions = append(renderOptions, render.Wrap(wrap))
}
return renderOptions
}
2 changes: 1 addition & 1 deletion cmd/github/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func Action(cmd *cobra.Command, args []string) error {
var out bytes.Buffer
writer := files.NewPatcher[string]("Generating patch file...", &out)

err = disco.Pipeline(cxt, ".", changedDocs, pipelineOptions, nil, writer)
err = disco.Pipeline(cxt, ".", changedDocs, pipelineOptions, nil, nil, writer)
if err != nil {
return fmt.Errorf("failed disco-balling: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions disco/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/project-chip/alchemy/matter/spec"
)

func Pipeline(cxt context.Context, specRoot string, docPaths []string, pipelineOptions pipeline.Options, discoOptions []Option, writer files.Writer[string]) (err error) {
func Pipeline(cxt context.Context, specRoot string, docPaths []string, pipelineOptions pipeline.Options, discoOptions []Option, renderOptions []render.Option, writer files.Writer[string]) (err error) {

var docs pipeline.Map[string, *pipeline.Data[*spec.Doc]]
if specRoot != "" {
Expand Down Expand Up @@ -77,7 +77,7 @@ func Pipeline(cxt context.Context, specRoot string, docPaths []string, pipelineO
return err
}

renderer := render.NewRenderer()
renderer := render.NewRenderer(renderOptions...)
var renders pipeline.Map[string, *pipeline.Data[string]]
renders, err = pipeline.Process[render.InputDocument, string](cxt, pipelineOptions, renderer, normalizedDocs)
if err != nil {
Expand Down
10 changes: 0 additions & 10 deletions test.adoc

This file was deleted.

0 comments on commit 2266b6d

Please sign in to comment.