package printer
import "github.com/mmcloughlin/avo/printer"
Package printer implements printing of avo files in various formats.
Index ¶
- type Builder
- type Config
- func NewArgvConfig() Config
- func NewDefaultConfig() Config
- func NewGoRunConfig() Config
- func (c Config) GeneratedBy() string
- func (c Config) GeneratedWarning() string
- type Printer
Examples ¶
Types ¶
type Builder ¶
Builder can construct a printer.
type Config ¶
type Config struct { // Command-line arguments passed to the generator. If provided, this will be // included in a code generation warning. Argv []string // Name of the code generator. Name string // Name of Go package the generated code will belong to. Pkg string }
Config represents general printing configuration.
func NewArgvConfig ¶
func NewArgvConfig() Config
NewArgvConfig constructs a Config from os.Args. The package name is guessed from the current directory.
func NewDefaultConfig ¶
func NewDefaultConfig() Config
NewDefaultConfig produces a config with Name "avo". The package name is guessed from the current directory.
func NewGoRunConfig ¶
func NewGoRunConfig() Config
NewGoRunConfig produces a Config for a generator that's expected to be executed via "go run ...".
func (Config) GeneratedBy ¶
GeneratedBy returns a description of the code generator.
Code:play
Output:Example¶
package main
import (
"fmt"
"github.com/mmcloughlin/avo/printer"
)
func main() {
// Default configuration named "avo".
cfg := printer.NewDefaultConfig()
fmt.Println(cfg.GeneratedBy())
// Name can be customized.
cfg = printer.Config{
Name: "mildred",
}
fmt.Println(cfg.GeneratedBy())
// Argv takes precedence.
cfg = printer.Config{
Argv: []string{"echo", "hello", "world"},
Name: "mildred",
}
fmt.Println(cfg.GeneratedBy())
}
avo
mildred
command: echo hello world
func (Config) GeneratedWarning ¶
GeneratedWarning returns text for a code generation warning. Conforms to https://golang.org/s/generatedcode.
type Printer ¶
Printer can produce output for an avo File.
func NewGoAsm ¶
NewGoAsm constructs a printer for writing Go assembly files.
func NewStubs ¶
NewStubs constructs a printer for writing stub function declarations.
Source Files ¶
- Version
- v0.6.0 (latest)
- Published
- Jan 7, 2024
- Platform
- linux/amd64
- Imports
- 11 packages
- Last checked
- 1 month ago –
Tools for package owners.