printer: doc for exported symbols

Updates #9
This commit is contained in:
Michael McLoughlin
2019-01-04 19:03:02 -08:00
parent cfce8d94df
commit 88eff53893
4 changed files with 51 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
// Package printer implements printing of avo files in various formats.
package printer
import (
@@ -10,18 +11,29 @@ import (
"github.com/mmcloughlin/avo/internal/stack"
)
// Printer can produce output for an avo File.
type Printer interface {
Print(*avo.File) ([]byte, error)
}
// Builder can construct a printer.
type Builder func(Config) Printer
// Config represents general printing configuration.
type Config struct {
Name string
// Command-line arguments passed to the generator. If provided, this will be
// included in a code generation warning.
Argv []string
Pkg string
// Name of the code generator.
Name string
// Name of Go package the generated code will belong to.
Pkg string
}
// NewDefaultConfig produces a config with Name "avo".
// The package name is guessed from the current directory.
func NewDefaultConfig() Config {
return Config{
Name: "avo",
@@ -29,6 +41,8 @@ func NewDefaultConfig() Config {
}
}
// NewArgvConfig constructs a Config from os.Args.
// The package name is guessed from the current directory.
func NewArgvConfig() Config {
return Config{
Argv: os.Args,
@@ -53,6 +67,7 @@ func NewGoRunConfig() Config {
}
}
// GeneratedBy returns a description of the code generator.
func (c Config) GeneratedBy() string {
if c.Argv == nil {
return c.Name
@@ -60,6 +75,7 @@ func (c Config) GeneratedBy() string {
return fmt.Sprintf("command: %s", strings.Join(c.Argv, " "))
}
// GeneratedWarning returns text for a code generation warning. Conforms to https://golang.org/s/generatedcode.
func (c Config) GeneratedWarning() string {
return fmt.Sprintf("Code generated by %s. DO NOT EDIT.", c.GeneratedBy())
}