typgo

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ProjectName of application.
	ProjectName string
	// ProjectVersion of application.
	ProjectVersion string
)

only available in project scope as supplied when compile using typgo.GoBuild or ldflags

View Source
var (
	// ProjectPkg only available in BuildTool scope. The BuildTool must be compiled by wrapper.
	ProjectPkg string
	// TypicalTmp only available in BuildTool scope. The BuildTool must be compiled by wrapper.
	TypicalTmp string
)

only available in build-tool scope

View Source
var ColorSet = struct {
	Project color.Attribute
	Task    color.Attribute
	Command color.Attribute
	Warn    color.Attribute
}{
	Project: color.FgHiCyan,
	Task:    color.FgCyan,
	Command: color.FgGreen,
	Warn:    color.FgYellow,
}

ColorSet color set

Functions

func BuildTool

func BuildTool(d *Descriptor) *cli.App

BuildTool app

func CliFunc

func CliFunc(d *Descriptor, a Action) func(*cli.Context) error

CliFunc return urfave cli function from Action

func GoImports

func GoImports(c *Context, target string) error

GoImports run goimports

func InstallTool

func InstallTool(c *Context, name, source string) (string, error)

InstallTool install tool to typical-tmp folder

func Start

func Start(d *Descriptor)

Start typical build-tool

Types

type Action

type Action interface {
	Execute(*Context) error
}

Action responsible to execute process

type Actions

type Actions []Action

Actions for composite execution

func (Actions) Execute

func (a Actions) Execute(c *Context) error

Execute actions

type BuildVars

type BuildVars map[string]string

BuildVars to injected variable when build

func (BuildVars) Keys

func (b BuildVars) Keys() []string

Keys return sorted key

func (BuildVars) String

func (b BuildVars) String() string

type Command

type Command struct {
	Name   string
	Args   []string
	Stdout io.Writer
	Stderr io.Writer
	Stdin  io.Reader
	Dir    string
	Env    []string
}

Command is wrapper to exec.Command

func CommandLine

func CommandLine(line string) *Command

CommandLine create bash command line

func (*Command) Command

func (b *Command) Command(extras ...string) *Command

Command return Command

func (*Command) ExecCmd

func (b *Command) ExecCmd(ctx context.Context) *exec.Cmd

ExecCmd return exec.Cmd

func (*Command) Execute

func (b *Command) Execute(c *Context) error

Execute bash

func (Command) String

func (b Command) String() string

type Commander

type Commander interface {
	Command(extras ...string) *Command
}

Commander responsible to Command

type Context

type Context struct {
	*cli.Context
	Logger
	Descriptor *Descriptor
	// contains filtered or unexported fields
}

Context related with build task

func NewContext

func NewContext(c *cli.Context, d *Descriptor) *Context

NewContext return instance of context

func (*Context) Ctx

func (c *Context) Ctx() context.Context

Ctx return golang context

func (*Context) ExecuteCommand

func (c *Context) ExecuteCommand(basher Commander) error

ExecuteCommand execute a command

func (*Context) ExecuteCommandLine

func (c *Context) ExecuteCommandLine(commandLine string) error

ExecuteCommandLine execute bash command

func (*Context) PatchBash

func (c *Context) PatchBash(mocks []*MockCommand) func(t *testing.T)

PatchBash typgo.RunBash for testing purpose

type Descriptor

type Descriptor struct {
	ProjectName    string // By default, is same with project folder. Only allowed characters(a-z,A-Z), underscore or dash.
	ProjectVersion string // By default, it is 0.0.1
	Environment    EnvLoader
	Tasks          []Tasker
	Stdout         io.Writer
}

Descriptor describe the project

type DotEnv

type DotEnv string

DotEnv file

func (DotEnv) EnvLoad

func (d DotEnv) EnvLoad() (map[string]string, error)

EnvLoad load environment from dotenv file

type EnvLoader

type EnvLoader interface {
	EnvLoad() (map[string]string, error)
}

EnvLoader responsible to load env

type Environment

type Environment map[string]string

Environment variable

func (Environment) EnvLoad

func (e Environment) EnvLoad() (map[string]string, error)

EnvLoad load environment from dotenv file

type GoBuild

type GoBuild struct {
	MainPackage string // By default, is "cmd/PROJECT_NAME"
	Output      string // By default, is "bin/PROJECT_NAME"
	// By default is set variable typgo.ProjectName to PROJECT_NAME
	// and typgo.ProjectVersion to PROJECT-VERSION
	Ldflags fmt.Stringer
}

GoBuild command

func (*GoBuild) Command

func (p *GoBuild) Command(extras ...string) *Command

Command for go-build

func (*GoBuild) Execute

func (p *GoBuild) Execute(c *Context) error

Execute standard compile

func (*GoBuild) Task

func (p *GoBuild) Task() *Task

Task for gobuild

type GoTest

type GoTest struct {
	Timeout  time.Duration
	NoCover  bool
	Verbose  bool
	Includes []string
	Excludes []string
}

GoTest command test

func (*GoTest) Execute

func (t *GoTest) Execute(c *Context) error

Execute standard test

func (*GoTest) Task

func (t *GoTest) Task() *Task

Task for gotest

type LogHeader

type LogHeader struct {
	Text  string
	Color color.Attribute
}

func LogHeaders

func LogHeaders(taskNames ...string) []LogHeader

type Logger

type Logger struct {
	Headers []LogHeader
	Stdout  io.Writer
}

Logger logger

func (Logger) Command

func (c Logger) Command(bash *Command)

Command information

func (Logger) Info

func (c Logger) Info(a ...interface{})

Info log text

func (Logger) Infof

func (c Logger) Infof(format string, a ...interface{})

Infof formatted text

func (Logger) Warn

func (c Logger) Warn(a ...interface{})

Warn log text

func (Logger) Warnf

func (c Logger) Warnf(format string, a ...interface{})

Warnf formatted text

type MockCommand

type MockCommand struct {
	CommandLine string
	OutputBytes []byte
	ErrorBytes  []byte
	ReturnError error
}

MockCommand is the test expectation

type MockCommandRunner

type MockCommandRunner struct {
	Mocks []*MockCommand
	Ptr   int
}

MockCommandRunner mocking bash

func (*MockCommandRunner) Close

func (r *MockCommandRunner) Close() error

Close mocker

func (*MockCommandRunner) Expectation

func (r *MockCommandRunner) Expectation() *MockCommand

Expectation for bash

func (*MockCommandRunner) Run

func (r *MockCommandRunner) Run(bash *Command) error

Run bash

type NewAction

type NewAction func(*Context) error

ExecuteFn is execution function

func (NewAction) Execute

func (a NewAction) Execute(c *Context) error

Execute action

type RunBinary

type RunBinary struct {
	Before Action
	Binary string
}

RunBinary standard run

func (*RunBinary) Execute

func (r *RunBinary) Execute(c *Context) error

Execute standard run

func (*RunBinary) Task

func (r *RunBinary) Task() *Task

Task to run binary

type Task

type Task struct {
	Name            string
	Aliases         []string
	Usage           string
	Flags           []cli.Flag
	SkipFlagParsing bool
	Action          Action
	Before          Action
	SubTasks        []*Task
}

Task to run action

func (*Task) CliCommand

func (t *Task) CliCommand(d *Descriptor) *cli.Command

CliCommand return cli command from task

func (*Task) Task

func (t *Task) Task() *Task

Task command

type TaskNames

type TaskNames []string

TaskNames run command in current BuildSys

func (TaskNames) Execute

func (r TaskNames) Execute(c *Context) error

Execute BuildCmdRuns

type Tasker

type Tasker interface {
	Task() *Task
}

Tasker interface return cli.Command method

Jump to

Keyboard shortcuts

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