template

package
v0.9.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2025 License: BSD-3-Clause Imports: 15 Imported by: 1

Documentation

Overview

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileGenerator

type FileGenerator interface {
	GenerateFile(ctx context.Context, c *OutputContext, name string) error
}

func Contents

func Contents(contents any) FileGenerator

Contents generates a file with the given contents. Contents is either a string, []byte, or io.Reader, which is copied to the output file of the given name. As a special case, if contents is some other type, it is JSON encoded.

func Gofmt

func Gofmt() FileGenerator

func Mode

func Mode(mode fs.FileMode) FileGenerator

func Template

func Template(tt Interface, namedata ...any) FileGenerator

Template generates a file by executing a template.

func Touch

func Touch() FileGenerator

Touch touches the file.

type FileGeneratorFunc

type FileGeneratorFunc func(context.Context, *OutputContext, string) error

func (FileGeneratorFunc) GenerateFile

func (f FileGeneratorFunc) GenerateFile(ctx context.Context, c *OutputContext, name string) error

type FileMode

type FileMode int
const (
	Executable FileMode = 0755
	ReadOnly   FileMode = 0600
)

File mode bits

func (FileMode) GenerateFile

func (m FileMode) GenerateFile(_ context.Context, c *OutputContext, name string) error

type Generator

type Generator interface {
	Generate(ctx context.Context, c *OutputContext) error
}

Generator is the interface for generating files.

func Data

func Data(name string, value any) Generator

func Dir

func Dir(name string, contents ...Generator) Generator

func File

func File(name string, ops ...FileGenerator) Generator

File generates a file with the given operations

func GoGet

func GoGet(pkgs ...string) Generator

GoGet assumes that the current template is a Go module and adds the given go module via go get. An error results if the project is not a go module.

type Interface

type Interface interface {
	Execute(out io.Writer, data any) error
}

Interface provides the interface of a template. The primary implementation is usually from the text/template package.

type OutputContext

type OutputContext struct {
	Vars      map[string]any
	Overwrite bool
	DryRun    bool
	FS        cli.FS
	// contains filtered or unexported fields
}

func (*OutputContext) Chmod

func (c *OutputContext) Chmod(name string, mode fs.FileMode) error

func (*OutputContext) Chown

func (c *OutputContext) Chown(name string, uid, gid int) error

func (*OutputContext) Chtimes

func (c *OutputContext) Chtimes(name string, atime time.Time, mtime time.Time) error

func (*OutputContext) Create

func (c *OutputContext) Create(name string) (fs.File, error)

func (*OutputContext) Do

func (c *OutputContext) Do(ctx context.Context, gens ...Generator) error

func (*OutputContext) Exists

func (c *OutputContext) Exists(name string) bool

func (*OutputContext) File

func (c *OutputContext) File(name string) string

func (*OutputContext) Mkdir

func (c *OutputContext) Mkdir(name string, perm fs.FileMode) error

func (*OutputContext) MkdirAll

func (c *OutputContext) MkdirAll(path string, perm fs.FileMode) error

func (*OutputContext) Open

func (c *OutputContext) Open(name string) (fs.File, error)

func (*OutputContext) OpenContext

func (c *OutputContext) OpenContext(ctx context.Context, name string) (fs.File, error)

func (*OutputContext) OpenFile

func (c *OutputContext) OpenFile(name string, flag int, perm fs.FileMode) (fs.File, error)

func (*OutputContext) PopDir

func (c *OutputContext) PopDir() error

func (*OutputContext) PushDir

func (c *OutputContext) PushDir(name string) error

func (*OutputContext) Remove

func (c *OutputContext) Remove(name string) error

func (*OutputContext) RemoveAll

func (c *OutputContext) RemoveAll(path string) error

func (*OutputContext) Rename

func (c *OutputContext) Rename(oldpath, newpath string) error

func (*OutputContext) SetData

func (c *OutputContext) SetData(name string, value any)

func (*OutputContext) Stat

func (c *OutputContext) Stat(name string) (fs.FileInfo, error)

func (*OutputContext) WorkDir

func (c *OutputContext) WorkDir() string

WorkDir is the path to the working directory

type Root

type Root struct {
	Sequence         Sequence
	Overwrite        bool
	DryRun           bool
	WorkingDirectory string
}

Root is the root of a template, used to compose a sequence and configuration

func New

func New(items ...Generator) *Root

func (*Root) DryRunFlag

func (r *Root) DryRunFlag() cli.Prototype

DryRunFlag obtains a conventions-based flag for overwriting

func (*Root) Execute

func (r *Root) Execute(ctx context.Context) error

func (*Root) Generate

func (r *Root) Generate(ctx context.Context, c *OutputContext) error

func (*Root) OverwriteFlag

func (r *Root) OverwriteFlag() cli.Prototype

OverwriteFlag obtains a conventions-based flag for overwriting

func (*Root) SetDryRun

func (r *Root) SetDryRun(v bool) error

SetDryRun sets whether to do a dry run. This function is for bindings

func (*Root) SetOverwrite

func (r *Root) SetOverwrite(v bool) error

SetOverwrite sets whether to overwrite. This function is for bindings

type Sequence

type Sequence []Generator

Sequence is a sequence of template generators

func (Sequence) Generate

func (s Sequence) Generate(ctx context.Context, c *OutputContext) error

type Vars

type Vars map[string]any

Vars contains template variables. Variables are copied into the template context

func (Vars) Generate

func (v Vars) Generate(_ context.Context, c *OutputContext) error

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL