common

package
v1.9.8 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const BuildDirName = "build"

BuildDirName defines the name of the build folder

View Source
const CmdDirName = "cmd"

CmdDirName defines the name of the cmd folder

View Source
const DockerIgnoreFileName = ".dockerignore"

DockerIgnoreFileName defines the name for .dockerignore

View Source
const DockerfileFileName = "Dockerfile"

DockerfileFileName defines the name for Dockerfile

View Source
const GitIgnoreFileName = ".gitignore"

GitIgnoreFileName defines the name for .gitignore

View Source
const GitRepoFileName = ".git"

GitRepoFileName defines the name for .git

View Source
const GoModFileName = "go.mod"

GoModFileName defines the name for go.mod

View Source
const LicenseFileName = "LICENSE"

LicenseFileName defines the name for LICENSE

View Source
const ReadmeFileName = "README.md"

ReadmeFileName defines the name for README.md

View Source
const ScriptDirName = "scripts"

ScriptDirName defines the name of the scripts folder

View Source
const ScriptPostBuild = "post_build"

ScriptPostBuild defines the name of the post_build script

View Source
const ScriptPreBuild = "pre_build"

ScriptPreBuild defines the name of the pre_build script

View Source
const VersionInfoFileName = "versioninfo.go"

VersionInfoFileName defines the name for versioninfo.go

View Source
const VersionInfoPackage = "versioninfo"

VersionInfoPackage defines the name for the version info package

Variables

View Source
var (
	// ErrArgsMissing is what is returned when no arguments could be found
	ErrArgsMissing = errors.New("No arguments were found")

	// ErrArgsDecodeError is what is returned when the arguments could be decoded (empty or invalid JSON)
	ErrArgsDecodeError = errors.New("Failed to decode arguments")
)
View Source
var (
	// ErrEmptyCommand is returned when the command is empty
	ErrEmptyCommand = errors.New("No command specified")
)

Functions

func InitGetLogger added in v1.9.4

func InitGetLogger(logLvl string) *logrus.Logger

func PackageNameToShort

func PackageNameToShort(packageName string) string

PackageNameToShort converts a package name to it's short version

Types

type Badge

type Badge struct {
	Title string // The title of the badge
	Link  string // The link to link to
	Image string // The src of the image for the badge
}

Badge is used to link with a badge to a specific URL

func (Badge) MarkdownString

func (badge Badge) MarkdownString() string

MarkdownString returns the badge as a Markdown string

type BuildArgs added in v1.9.4

type BuildArgs struct {
	ProjectPath        string   `json:"project_path,omitempty"`        // The root path of the project
	OutputPath         string   `json:"output_path,omitempty"`         // The absolute build path
	GOOS               string   `json:"GOOS,omitempty"`                // The GOOS for which was compiled
	GOARCH             string   `json:"GOARCH,omitempty"`              // The GOARCH for which was compiled
	ProjectName        string   `json:"project_name,omitempty"`        // The project name
	ProjectDescription string   `json:"project_description,omitempty"` // The project description
	ProjectCopyright   string   `json:"project_copyright,omitempty"`   // The project copyright
	Version            string   `json:"version,omitempty"`             // The version info
	Revision           string   `json:"revision,omitempty"`            // The project revision
	Branch             string   `json:"branch,omitempty"`              // The project branch
	RawBuildCommand    []string `json:"raw_build_command,omitempty"`   // The raw build command which is executed
}

BuildArgs are the arguments which are passed to the pre_build.go and post_build.go scripts

func ParseBuildArgs added in v1.9.4

func ParseBuildArgs() (BuildArgs, error)

ParseBuildArgs parses the build arguments from os.Args

func (BuildArgs) AsMap added in v1.9.4

func (b BuildArgs) AsMap() map[string]string

AsMap returns the build arguments as a map

type CommandRunner

type CommandRunner struct {
	FileSystem
	Encoding
}

CommandRunner is what can be injected into a subcommand when you need to run system commands

func (CommandRunner) RunInteractive

func (commandRunner CommandRunner) RunInteractive(cmdLine []string, workdir string, env map[string]string) error

RunInteractive and interactive command

func (CommandRunner) RunProjectHook

func (commandRunner CommandRunner) RunProjectHook(project Project, hookName string, args BuildArgs) error

RunProjectHook runs the given hook in the context of the project passing the args to ti

func (CommandRunner) RunReturnOutput

func (commandRunner CommandRunner) RunReturnOutput(cmdLine []string, workdir string, env map[string]string) (string, error)

RunReturnOutput runs the command and returns the result as a string

func (CommandRunner) RunScriptIfExistsReturnOutput

func (commandRunner CommandRunner) RunScriptIfExistsReturnOutput(scriptPath string, args BuildArgs, workdir string, env map[string]string) (string, error)

RunScriptIfExistsReturnOutput runs the given script if it exists using "go run" and outputs the result to stdout/stderr

func (CommandRunner) RunScriptReturnOutput

func (commandRunner CommandRunner) RunScriptReturnOutput(scriptPath string, args BuildArgs, workdir string, env map[string]string) (string, error)

RunScriptReturnOutput runs the given script using "go run" and outputs the result to stdout/stderr

func (CommandRunner) RunScriptToStdout

func (commandRunner CommandRunner) RunScriptToStdout(scriptPath string, args BuildArgs, workdir string, env map[string]string) error

RunScriptToStdout runs the given script using "go run" and outputs the result to stdout/stderr

func (CommandRunner) RunToStdout

func (commandRunner CommandRunner) RunToStdout(cmdLine []string, workdir string, env map[string]string) error

RunToStdout runs the command and outputs the result to stdout/stderr

type Compressor

type Compressor struct{}

Compressor is what can be injected into a subcommand when you need zip / tgz functions

func (Compressor) CreateTgz

func (c Compressor) CreateTgz(tgzPath string) compressors.Compressor

CreateTgz creates a tgz file from a path

func (Compressor) CreateZip

func (c Compressor) CreateZip(zipPath string) compressors.Compressor

CreateZip creates a zip file from a path

type Encoding

type Encoding struct{}

Encoding is what can be injected into a subcommand when you need encoding-related items

func (Encoding) ToFormattedString

func (e Encoding) ToFormattedString(data interface{}) string

ToFormattedString returns a JSON formatted string encoding data

func (Encoding) ToJSON

func (e Encoding) ToJSON(data interface{}) []byte

ToJSON returns a JSON byte slice encoding data

func (Encoding) ToJSONString

func (e Encoding) ToJSONString(data interface{}) string

ToJSONString returns a JSON string encoding data

type FileSystem

type FileSystem struct {
}

FileSystem is what can be injected into a subcommand when you need file system access

func (FileSystem) DirExists

func (fileSystem FileSystem) DirExists(path string) bool

DirExists is a helper function to check if a directory exists or not

func (FileSystem) FileExists

func (fileSystem FileSystem) FileExists(path string) bool

FileExists is a helper function to check if a file exists or not

func (FileSystem) PathExists

func (fileSystem FileSystem) PathExists(path string) bool

PathExists is a helper function to check if a path exists or not

func (FileSystem) WriteJSONFile

func (fileSystem FileSystem) WriteJSONFile(path string, data interface{}) error

WriteJSONFile marshals the data into a JSON file

func (FileSystem) WriteJSONFileIfNotExists

func (fileSystem FileSystem) WriteJSONFileIfNotExists(path string, data interface{}) error

WriteJSONFileIfNotExists writes JSON into a file if it doesn't exist yet

func (FileSystem) WriteTextFile

func (fileSystem FileSystem) WriteTextFile(path string, data string) error

WriteTextFile creates a text with with data as its contents

func (FileSystem) WriteTextFileIfNotExists

func (fileSystem FileSystem) WriteTextFileIfNotExists(path string, data string) error

WriteTextFileIfNotExists writes a text file if it doesn't exist yet

type GlobalOptions added in v1.9.4

type GlobalOptions struct {
	Verbose  bool
	LogLevel string
	LogDir   string
	Graph    bool
}

GlobalOptions implements the "build" command

type Golang

type Golang struct{}

Golang is what can be injected into a subcommand when you need Go specific items

func (Golang) GoBin

func (g Golang) GoBin(subpath ...string) string

GoBin returns a relative path inside $GOPATH/bin

func (Golang) GoPath

func (g Golang) GoPath(subpath ...string) string

GoPath returns a relative path inside $GOPATH

func (Golang) IsDebug

func (g Golang) IsDebug() bool

IsDebug returns true of the DEBUG env var is set

type Project

type Project struct {
	FileSystem

	Path string
	// contains filtered or unexported fields
}

Project defines a Go project based on Go modules

func NewProject

func NewProject(path string, packageName string) Project

NewProject returns a new Project instance

func (Project) Badges

func (project Project) Badges() []Badge

Badges returns the list of badges which should be shown for the project

func (Project) Package

func (project Project) Package() (string, error)

Package gets the main package of the project from the go.mod file

func (Project) RelPath

func (project Project) RelPath(subpath ...string) string

RelPath returns a relative path inside the project

func (Project) ShortPackageName

func (project Project) ShortPackageName() string

ShortPackageName returns the package name for the main package

type Template

type Template struct {
	FileSystem
}

Template is what can be injected into a subcommand when you need text templates

func (Template) RenderTextTemplate

func (t Template) RenderTextTemplate(templateData string, params interface{}) (string, error)

RenderTextTemplate renders a text template

func (Template) WriteTextTemplateIfNotExists

func (t Template) WriteTextTemplateIfNotExists(path string, templateData string, params interface{}) error

WriteTextTemplateIfNotExists renders a text template and writes it to a file if it doesn't exist yet

type Timer

type Timer struct {
	// contains filtered or unexported fields
}

Timer is what can be injected into a subcommand when you need a timer

func (*Timer) PrintElapsed

func (t *Timer) PrintElapsed(prefix string)

PrintElapsed prints the elapsed time to stdout

func (*Timer) StartTimer

func (t *Timer) StartTimer()

StartTimer starts the timer

type Version

type Version struct {
	CommandRunner
}

Version is used to get version information

func (Version) BranchName

func (version Version) BranchName(project Project) string

BranchName returns the name of the current branch

func (Version) Revision

func (version Version) Revision(project Project) string

Revision returns the Git revision in it's short format

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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