tools

package
v0.0.0-...-cca5969 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package tools has been designed to run different tools either directly or though Docker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Busted

type Busted struct {
	Tool
}

Busted represents a Busted tool.

func NewBusted

func NewBusted() (*Busted, error)

NewBusted creates a new Busted instance.

func (*Busted) LoadVersion

func (b *Busted) LoadVersion() (string, error)

LoadVersion loads a Busted version.

func (*Busted) Test

func (b *Busted) Test() (result Lint, err error)

Test runs tests.

type Controller

type Controller interface {
	SetToolsRunInDocker(bool)
	LookPaths()
	LoadVersions()
}

Controller is the interface that wraps the Tools methods.

type Docker

type Docker struct {
	Tool
}

Docker represents a Docker tool.

func NewDocker

func NewDocker() (*Docker, error)

NewDocker creates a new Docker instance.

func (*Docker) LoadVersion

func (d *Docker) LoadVersion() (string, error)

LoadVersion loads a Docker version.

type Dockerized

type Dockerized struct {
	// Image hold the image name and tag.
	//
	// Default: dstmodders/dst-mod:latest
	Image string

	// Remove sets whether a container should be removed right after running.
	//
	// Default: true
	Remove bool

	// User holds a username or UID to run a container as.
	//
	// Default: dst-mod
	User string

	// Volume holds a volume to mount. By default, points to a working directory.
	Volume string
	// contains filtered or unexported fields
}

Dockerized represents a Docker arguments to run a tool.

func NewDockerized

func NewDockerized() *Dockerized

NewDockerized creates a new Dockerized instance.

func (*Dockerized) Args

func (d *Dockerized) Args() []string

Args returns arguments prepared using PrepareArgs.

func (*Dockerized) IsImageAvailable

func (d *Dockerized) IsImageAvailable() bool

IsImageAvailable checks whether an image is available locally.

func (*Dockerized) PrepareArgs

func (d *Dockerized) PrepareArgs() (result []string, err error)

PrepareArgs prepare arguments to return later using Args.

func (*Dockerized) PullImage

func (d *Dockerized) PullImage() bool

PullImage pulls an image.

type FileState

type FileState int

FileState represents a single linting or formatting file result state.

const (
	// FileStateWarning represents a state of the file having some issues.
	FileStateWarning FileState = iota

	// FileStateSuccess represents a state of the file after successful fix.
	FileStateSuccess
)

type Format

type Format struct {
	Files []FormatFile
}

Format represents a formatting result.

type FormatFile

type FormatFile struct {
	// Path holds a file path.
	Path string

	// State holds a file state.
	State FileState
}

FormatFile represents a single formatting file.

type Krane

type Krane struct {
	Ktools
}

Krane represents a ktools/krane tool.

func NewKrane

func NewKrane() (*Krane, error)

NewKrane creates a new Krane instance.

type Ktech

type Ktech struct {
	Ktools
}

Ktech represents a ktools/ktech tool.

func NewKtech

func NewKtech() (*Ktech, error)

NewKtech creates a new Ktech instance.

type Ktools

type Ktools struct {
	Tool
}

Ktools represents a Ktools tool.

func NewKtools

func NewKtools(name, cmd string) (*Ktools, error)

NewKtools creates a new Ktools instance.

func (*Ktools) LoadVersion

func (k *Ktools) LoadVersion() (string, error)

LoadVersion loads a Ktools version.

type LDoc

type LDoc struct {
	Tool
}

LDoc represents an LDoc tool.

func NewLDoc

func NewLDoc() (*LDoc, error)

NewLDoc creates a new LDoc instance.

func (*LDoc) LoadVersion

func (l *LDoc) LoadVersion() (string, error)

LoadVersion loads an LDoc version.

type Lint

type Lint struct {
	Files  []LintFile
	Stdout string
}

Lint represents a linting result.

type LintFile

type LintFile struct {
	// Path holds a file path.
	Path string

	// State holds a file state.
	State FileState

	// Issues holds the found issues.
	Issues []LintFileIssue
}

LintFile represents a single linting file.

type LintFileIssue

type LintFileIssue struct {
	// Name holds a file name.
	Name string

	// StartLine holds the start line number which corresponds to this issue.
	StartLine int

	// EndLine holds the end line number which corresponds to this issue.
	EndLine int

	// Issue holds the issue description.
	Description string
}

LintFileIssue represents a single issue in a file.

type Luacheck

type Luacheck struct {
	Tool
}

Luacheck represents a Luacheck tool.

func NewLuacheck

func NewLuacheck() (*Luacheck, error)

NewLuacheck creates a new Luacheck instance.

func (*Luacheck) Lint

func (l *Luacheck) Lint(arg ...string) (result Lint, err error)

Lint lints provided files.

func (*Luacheck) LoadVersion

func (l *Luacheck) LoadVersion() (string, error)

LoadVersion loads a Luacheck version.

type Prettier

type Prettier struct {
	Tool

	// DefaultExt holds default extensions: ".md", ".xml", ".yml".
	DefaultExt []string

	// ListDifferent sets whether only different files should be listed.
	ListDifferent bool
}

Prettier represents a Prettier tool.

func NewPrettier

func NewPrettier() (*Prettier, error)

NewPrettier creates a new Prettier instance.

func (*Prettier) Check

func (p *Prettier) Check(arg ...string) (result Format, err error)

Check checks formatting in the provided files.

func (*Prettier) Fix

func (p *Prettier) Fix(arg ...string) (result Format, err error)

Fix fixes formatting in the provided files.

func (*Prettier) LoadVersion

func (p *Prettier) LoadVersion() (string, error)

LoadVersion loads a Prettier version.

type StyLua

type StyLua struct {
	Tool

	// DefaultExt holds default extensions: ".lua".
	DefaultExt []string
}

StyLua represents a StyLua tool.

func NewStyLua

func NewStyLua() (*StyLua, error)

NewStyLua creates a new StyLua instance.

func (*StyLua) Check

func (s *StyLua) Check(arg ...string) (result Format, err error)

Check checks formatting in the provided files.

func (*StyLua) Fix

func (s *StyLua) Fix(arg ...string) (result Format, err error)

Fix fixes formatting in the provided files.

func (*StyLua) LoadVersion

func (s *StyLua) LoadVersion() (string, error)

LoadVersion loads a StyLua version.

type Tool

type Tool struct {
	// Cmd holds a command.
	Cmd string

	// CmdArgs holds a command arguments.
	CmdArgs []string
	// contains filtered or unexported fields
}

Tool represents a single tool.

func NewTool

func NewTool(name, cmd string) (*Tool, error)

NewTool creates a new Tool instance.

func (*Tool) DockerImage

func (t *Tool) DockerImage() string

DockerImage gets the Docker image.

func (*Tool) ExecCommand

func (t *Tool) ExecCommand(arg ...string) *exec.Cmd

ExecCommand executes the command with the passed arguments either directly or through a Docker container.

func (*Tool) ExistsInDocker

func (t *Tool) ExistsInDocker() bool

ExistsInDocker checks if the tool exists inside a Docker container.

func (*Tool) ExistsOnSystem

func (t *Tool) ExistsOnSystem() bool

ExistsOnSystem checks if the tool exists on the system.

func (*Tool) IsDockerImageAvailable

func (t *Tool) IsDockerImageAvailable() bool

IsDockerImageAvailable checks if the Docker image is available.

func (*Tool) LookPath

func (t *Tool) LookPath() (string, error)

LookPath looks for a direct path of the tool which can be retrieved later using Path.

func (*Tool) Name

func (t *Tool) Name() string

Name returns a name of the tool.

func (*Tool) Path

func (t *Tool) Path() string

Path returns a path of the tool found earlier using LookPath.

func (*Tool) PullDockerImage

func (t *Tool) PullDockerImage() bool

PullDockerImage pull the Docker image.

func (*Tool) SetDockerImage

func (t *Tool) SetDockerImage(image string)

SetDockerImage sets the Docker image.

func (*Tool) SetDockerized

func (t *Tool) SetDockerized(dockerized *Dockerized) error

SetDockerized sets dockerized.

func (*Tool) SetIgnore

func (t *Tool) SetIgnore(ignore []string)

SetIgnore sets ignore list.

func (*Tool) SetRunInDocker

func (t *Tool) SetRunInDocker(runInDocker bool)

SetRunInDocker sets whether a tool should be run in Docker.

func (*Tool) Version

func (t *Tool) Version() string

Version returns a version of the tool for both direct and Dockerized usage.

type Tooler

type Tooler interface {
	Name() string
	Path() string
	Version() string
	SetDockerized(*Dockerized) error
	DockerImage() string
	SetDockerImage(image string)
	IsDockerImageAvailable() bool
	PullDockerImage() bool
	SetIgnore([]string)
	SetRunInDocker(bool)
	ExecCommand(...string) *exec.Cmd
	LookPath() (string, error)
	ExistsOnSystem() bool
	ExistsInDocker() bool
	LoadVersion() (string, error)
	// contains filtered or unexported methods
}

Tooler is the interface that wraps the Tool methods.

type Tools

type Tools struct {
	Busted   *Busted
	Docker   *Docker
	Krane    *Krane
	Ktech    *Ktech
	LDoc     *LDoc
	Luacheck *Luacheck
	Prettier *Prettier
	StyLua   *StyLua
	// contains filtered or unexported fields
}

Tools represents all the supported tools.

func New

func New() (*Tools, error)

New creates a new Tools instance.

func (*Tools) LoadVersions

func (t *Tools) LoadVersions()

LoadVersions loads versions of all tools.

func (*Tools) LookPaths

func (t *Tools) LookPaths()

LookPaths looks for paths of all tools.

func (*Tools) SetToolsRunInDocker

func (t *Tools) SetToolsRunInDocker(runInDocker bool)

SetToolsRunInDocker sets all tools to be run in Docker.

Jump to

Keyboard shortcuts

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