dao

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ACCEPTABLE_FILE_NAMES = []string{"sake.yaml", "sake.yml", ".sake.yaml", ".sake.yml"}

	DEFAULT_SHELL = "bash -c"

	DEFAULT_THEME = Theme{
		Name:  "default",
		Table: DefaultTable,
		Text:  DefaultText,
	}

	DEFAULT_TARGET = Target{
		Name:    "default",
		All:     false,
		Servers: []string{},
		Tags:    []string{},
	}

	DEFAULT_SPEC = Spec{
		Name:              "default",
		Output:            "text",
		Parallel:          false,
		AnyErrorsFatal:    false,
		IgnoreUnreachable: false,
		IgnoreErrors:      false,
		OmitEmpty:         false,
	}
)
View Source
var DefaultTable = Table{
	Style: "default",
	Box:   StyleBoxASCII,

	Format: &TableFormat{
		Header: core.Ptr("title"),
		Row:    core.Ptr(""),
	},

	Options: &TableOptions{
		DrawBorder:      core.Ptr(false),
		SeparateColumns: core.Ptr(true),
		SeparateHeader:  core.Ptr(true),
		SeparateRows:    core.Ptr(false),
		SeparateFooter:  core.Ptr(false),
	},

	Color: &TableColor{
		Border: &BorderColors{
			Header: &ColorOptions{
				Fg:   core.Ptr(""),
				Bg:   core.Ptr(""),
				Attr: core.Ptr("faint"),
			},

			Row: &ColorOptions{
				Fg:   core.Ptr(""),
				Bg:   core.Ptr(""),
				Attr: core.Ptr("faint"),
			},

			RowAlternate: &ColorOptions{
				Fg:   core.Ptr(""),
				Bg:   core.Ptr(""),
				Attr: core.Ptr("faint"),
			},

			Footer: &ColorOptions{
				Fg:   core.Ptr(""),
				Bg:   core.Ptr(""),
				Attr: core.Ptr("faint"),
			},
		},

		Header: &CellColors{
			Server: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
			Tag: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
			Desc: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
			Host: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
			User: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
			Local: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
			Port: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
			Task: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
			Output: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
		},

		Row: &CellColors{
			Server: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
			Tag: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
			Desc: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
			Host: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
			User: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
			Local: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
			Port: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
			Task: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
			Output: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
		},
	},
}
View Source
var DefaultText = Text{
	Prefix:       true,
	PrefixColors: []string{"green", "blue", "red", "yellow", "magenta", "cyan"},
	Header:       `{{ .Style "TASK" "bold" }}{{ if ne .NumTasks 1 }} ({{ .Index }}/{{ .NumTasks }}){{end}}{{ if and .Name .Desc }} [{{.Style .Name "bold"}}: {{ .Desc }}] {{ else if .Name }} [{{ .Name }}] {{ else if .Desc }} [{{ .Desc }}] {{end}}`,
	HeaderFiller: "*",
}
View Source
var StyleBoxASCII = table.BoxStyle{
	BottomLeft:       "+",
	BottomRight:      "+",
	BottomSeparator:  "+",
	EmptySeparator:   text.RepeatAndTrim(" ", text.RuneCount("+")),
	Left:             "|",
	LeftSeparator:    "+",
	MiddleHorizontal: "-",
	MiddleSeparator:  "+",
	MiddleVertical:   "|",
	PaddingLeft:      " ",
	PaddingRight:     " ",
	PageSeparator:    "\n",
	Right:            "|",
	RightSeparator:   "+",
	TopLeft:          "+",
	TopRight:         "+",
	TopSeparator:     "+",
	UnfinishedRow:    " ~",
}
View Source
var StyleBoxLight = table.BoxStyle{
	BottomLeft:       "└",
	BottomRight:      "┘",
	BottomSeparator:  "┴",
	EmptySeparator:   text.RepeatAndTrim(" ", text.RuneCount("┼")),
	Left:             "│",
	LeftSeparator:    "├",
	MiddleHorizontal: "─",
	MiddleSeparator:  "┼",
	MiddleVertical:   "│",
	PaddingLeft:      " ",
	PaddingRight:     " ",
	PageSeparator:    "\n",
	Right:            "│",
	RightSeparator:   "┤",
	TopLeft:          "┌",
	TopRight:         "┐",
	TopSeparator:     "┬",
	UnfinishedRow:    " ≈",
}

Functions

func CheckIsMappingNode

func CheckIsMappingNode(node yaml.Node) error

func CheckIsScalarNode

func CheckIsScalarNode(node yaml.Node) error

func CheckIsSequenceNode

func CheckIsSequenceNode(node yaml.Node) error

func CheckUserNoColor

func CheckUserNoColor(noColorFlag bool)

func EvaluateEnv

func EvaluateEnv(envList []string) ([]string, error)

func EvaluatePassword

func EvaluatePassword(password string) (string, error)

func FormatErrors

func FormatErrors(re Resource, errs []error) error

FormatErrors concats one or many errors attached to it for a single resource.

func IsNullNode

func IsNullNode(node yaml.Node) bool

func MergeEnvs

func MergeEnvs(envs ...[]string) []string

MergeEnvs merges environment variables. Priority is from highest to lowest (1st env takes precedence over the last entry).

func ParseNodeEnv

func ParseNodeEnv(node yaml.Node) []string

func ParseTaskEnv

func ParseTaskEnv(cmdEnv []string, userEnv []string, parentEnv []string, configEnv []string) ([]string, error)

func SelectFirstNonEmpty

func SelectFirstNonEmpty(values ...string) string

SelectFirstNonEmpty selects first non-empty string.

func ServerInSlice

func ServerInSlice(name string, list []Server) bool

Types

type BorderColors

type BorderColors struct {
	Header       *ColorOptions `yaml:"header"`
	Row          *ColorOptions `yaml:"row"`
	RowAlternate *ColorOptions `yaml:"row_alt"`
	Footer       *ColorOptions `yaml:"footer"`
}

type CellColors

type CellColors struct {
	Server *ColorOptions `yaml:"server"`
	Tag    *ColorOptions `yaml:"tag"`
	Desc   *ColorOptions `yaml:"desc"`
	Host   *ColorOptions `yaml:"host"`
	User   *ColorOptions `yaml:"user"`
	Port   *ColorOptions `yaml:"port"`
	Local  *ColorOptions `yaml:"local"`
	Task   *ColorOptions `yaml:"task"`
	Output *ColorOptions `yaml:"output"`
}

type ColorOptions

type ColorOptions struct {
	Fg    *string `yaml:"fg"`
	Bg    *string `yaml:"bg"`
	Align *string `yaml:"align"`
	Attr  *string `yaml:"attr"`
}

type Config

type Config struct {
	DisableVerifyHost bool
	KnownHostsFile    string
	Shell             string
	Envs              []string
	Themes            []Theme
	Specs             []Spec
	Targets           []Target
	Servers           []Server
	Tasks             []Task
	Path              string
}

func ReadConfig

func ReadConfig(configFilepath string, userConfigPath string, noColor bool) (Config, error)

Function to read sake configs.

func (*Config) CheckConfigNoColor

func (c *Config) CheckConfigNoColor()

func (Config) EditConfig

func (c Config) EditConfig() error

Open sake config in editor

func (Config) EditServer

func (c Config) EditServer(name string) error

Open sake config in editor and optionally go to line matching the server name

func (Config) EditTask

func (c Config) EditTask(name string) error

Open sake config in editor and optionally go to line matching the task name

func (Config) FilterServers

func (c Config) FilterServers(
	allServersFlag bool,
	serversFlag []string,
	tagsFlag []string,
) ([]Server, error)

FilterServers returns servers matching filters, it does a union select.

func (Config) GetRemoteServerNameAndDesc

func (c Config) GetRemoteServerNameAndDesc() []string

func (Config) GetServer

func (c Config) GetServer(name string) (*Server, error)

func (Config) GetServerHosts

func (c Config) GetServerHosts() []string

func (Config) GetServerNameAndDesc

func (c Config) GetServerNameAndDesc() []string

func (Config) GetServerNames

func (c Config) GetServerNames() []string

func (Config) GetServersByName

func (c Config) GetServersByName(serverNames []string) ([]Server, error)

func (Config) GetServersByTags

func (c Config) GetServersByTags(tags []string) ([]Server, error)

Servers must have all tags to match. For instance, if --tags frontend,backend is passed, then a server must have both tags. We only return error if the flags provided do not exist in the sake config.

func (Config) GetSpec

func (c Config) GetSpec(name string) (*Spec, error)

func (Config) GetSpecNames

func (c Config) GetSpecNames() []string

func (Config) GetTagAssocations

func (c Config) GetTagAssocations(tags []string) ([]Tag, error)

func (Config) GetTags

func (c Config) GetTags() []string

func (Config) GetTarget

func (c Config) GetTarget(name string) (*Target, error)

func (Config) GetTargetNames

func (c Config) GetTargetNames() []string

func (Config) GetTask

func (c Config) GetTask(id string) (*Task, error)

func (Config) GetTaskIDAndDesc

func (c Config) GetTaskIDAndDesc() []string

func (Config) GetTaskNames

func (c Config) GetTaskNames() []string

func (Config) GetTaskServers

func (c Config) GetTaskServers(task *Task, runFlags *core.RunFlags) ([]Server, error)

func (Config) GetTasksByIDs

func (c Config) GetTasksByIDs(ids []string) ([]Task, error)

func (Config) GetTheme

func (c Config) GetTheme(name string) (*Theme, error)

func (Config) GetThemeNames

func (c Config) GetThemeNames() []string

type ConfigResources

type ConfigResources struct {
	DisableVerifyHost *bool
	KnownHostsFile    *string
	Shell             string
	Imports           []Import
	Themes            []Theme
	Specs             []Spec
	Targets           []Target
	Tasks             []Task
	Servers           []Server
	Envs              []string

	ConfigErrors []ResourceErrors[ConfigYAML]
	ImportErrors []ResourceErrors[Import]
	ThemeErrors  []ResourceErrors[Theme]
	SpecErrors   []ResourceErrors[Spec]
	TargetErrors []ResourceErrors[Target]
	TaskErrors   []ResourceErrors[Task]
	ServerErrors []ResourceErrors[Server]
}

Used for config imports

func (ConfigResources) GetSpec

func (c ConfigResources) GetSpec(name string) (*Spec, error)

func (ConfigResources) GetTarget

func (c ConfigResources) GetTarget(name string) (*Target, error)

func (ConfigResources) GetTask

func (c ConfigResources) GetTask(id string) (*Task, error)

func (ConfigResources) GetTheme

func (c ConfigResources) GetTheme(name string) (*Theme, error)

type ConfigYAML

type ConfigYAML struct {
	// Internal
	Path           string  `yaml:"-"`
	Dir            string  `yaml:"-"`
	UserConfigFile *string `yaml:"-"`

	// Intermediate
	DisableVerifyHost *bool     `yaml:"disable_verify_host"`
	KnownHostsFile    *string   `yaml:"known_hosts_file"`
	Shell             string    `yaml:"shell"`
	Import            yaml.Node `yaml:"import"`
	Env               yaml.Node `yaml:"env"`
	Themes            yaml.Node `yaml:"themes"`
	Specs             yaml.Node `yaml:"specs"`
	Targets           yaml.Node `yaml:"targets"`
	Servers           yaml.Node `yaml:"servers"`
	Tasks             yaml.Node `yaml:"tasks"`
	// contains filtered or unexported fields
}

func (*ConfigYAML) GetContext

func (c *ConfigYAML) GetContext() string

func (*ConfigYAML) GetContextLine

func (c *ConfigYAML) GetContextLine() int

func (*ConfigYAML) ParseImportsYAML

func (c *ConfigYAML) ParseImportsYAML() ([]Import, []ResourceErrors[Import])

func (*ConfigYAML) ParseServersYAML

func (c *ConfigYAML) ParseServersYAML() ([]Server, []ResourceErrors[Server])

ParseServersYAML parses the servers dictionary and returns it as a list.

func (*ConfigYAML) ParseSpecsYAML

func (c *ConfigYAML) ParseSpecsYAML() ([]Spec, []ResourceErrors[Spec])

ParseSpecsYAML parses the specs dictionary and returns it as a list.

func (*ConfigYAML) ParseTargetsYAML

func (c *ConfigYAML) ParseTargetsYAML() ([]Target, []ResourceErrors[Target])

ParseTargetsYAML parses the target dictionary and returns it as a list.

func (*ConfigYAML) ParseTasksYAML

func (c *ConfigYAML) ParseTasksYAML() ([]Task, []ResourceErrors[Task])

ParseTasksYAML parses the task dictionary and returns it as a list. This function also sets task references. Valid formats (only one is allowed):

cmd: |
  echo pong

task: ping

tasks:
  - task: ping
  - task: ping
  - cmd: echo pong

func (*ConfigYAML) ParseThemesYAML

func (c *ConfigYAML) ParseThemesYAML() ([]Theme, []ResourceErrors[Theme])

Populates ThemeList

type FoundCyclicDependency

type FoundCyclicDependency struct {
	Cycles []NodeLink
}

func (*FoundCyclicDependency) Error

func (c *FoundCyclicDependency) Error() string

type FoundCyclicTaskDependency

type FoundCyclicTaskDependency struct {
	Cycles []TaskLink
}

func (*FoundCyclicTaskDependency) Error

func (c *FoundCyclicTaskDependency) Error() string

type FoundDuplicateHosts

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

func (*FoundDuplicateHosts) Error

func (c *FoundDuplicateHosts) Error() string

type FoundDuplicateImports

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

func (*FoundDuplicateImports) Error

func (c *FoundDuplicateImports) Error() string

type Import

type Import struct {
	Path string
	// contains filtered or unexported fields
}

func (*Import) GetContext

func (i *Import) GetContext() string

func (*Import) GetContextLine

func (i *Import) GetContextLine() int

type Node

type Node struct {
	Path     string
	Imports  []Import
	Visiting bool
	Visited  bool
}
type NodeLink struct {
	A Node
	B Node
}

type Resource

type Resource interface {
	GetContext() string
	GetContextLine() int
}

type ResourceErrors

type ResourceErrors[T any] struct {
	Resource *T
	Errors   []error
}

type Row

type Row struct {
	Columns []string
}

func (Row) GetValue

func (r Row) GetValue(_ string, i int) string

type Server

type Server struct {
	Name         string
	Desc         string
	Host         string
	User         string
	Port         uint16
	Local        bool
	Tags         []string
	Envs         []string
	Shell        string
	WorkDir      string
	IdentityFile *string
	Password     *string
	// contains filtered or unexported fields
}

func GetFirstRemoteServer

func GetFirstRemoteServer(servers []Server) (Server, error)

func GetUnionServers

func GetUnionServers(s ...[]Server) []Server

func InitSake

func InitSake(args []string) ([]Server, error)

func (*Server) GetContext

func (s *Server) GetContext() string

func (*Server) GetContextLine

func (s *Server) GetContextLine() int

func (Server) GetValue

func (s Server) GetValue(key string, _ int) string

type ServerYAML

type ServerYAML struct {
	Name         string    `yaml:"-"`
	Desc         string    `yaml:"desc"`
	Host         string    `yaml:"host"`
	User         string    `yaml:"user"`
	Port         uint16    `yaml:"port"`
	Local        bool      `yaml:"local"`
	Tags         []string  `yaml:"tags"`
	Env          yaml.Node `yaml:"env"`
	Shell        string    `yaml:"shell"`
	WorkDir      string    `yaml:"work_dir"`
	IdentityFile *string   `yaml:"identity_file"`
	Password     *string   `yaml:"password"`
}

type Spec

type Spec struct {
	Name              string `yaml:"_"`
	Output            string `yaml:"output"`
	Parallel          bool   `yaml:"parallel"`
	AnyErrorsFatal    bool   `yaml:"any_errors_fatal"`
	IgnoreErrors      bool   `yaml:"ignore_errors"`
	IgnoreUnreachable bool   `yaml:"ignore_unreachable"`
	OmitEmpty         bool   `yaml:"omit_empty"`
	// contains filtered or unexported fields
}

func (*Spec) GetContext

func (s *Spec) GetContext() string

func (*Spec) GetContextLine

func (s *Spec) GetContextLine() int

type Table

type Table struct {
	// Stylable via YAML
	Name    string        `yaml:"name"`
	Style   string        `yaml:"style"`
	Color   *TableColor   `yaml:"color"`
	Format  *TableFormat  `yaml:"format"`
	Options *TableOptions `yaml:"options"`

	// Not stylable via YAML
	Box table.BoxStyle `yaml:"-"`
}

type TableColor

type TableColor struct {
	Border *BorderColors `yaml:"border"`
	Header *CellColors   `yaml:"header"`
	Row    *CellColors   `yaml:"row"`
}

type TableFormat

type TableFormat struct {
	Header *string `yaml:"header"`
	Row    *string `yaml:"row"`
}

type TableOptions

type TableOptions struct {
	DrawBorder      *bool `yaml:"draw_border"`
	SeparateColumns *bool `yaml:"separate_columns"`
	SeparateHeader  *bool `yaml:"separate_header"`
	SeparateRows    *bool `yaml:"separate_rows"`
	SeparateFooter  *bool `yaml:"separate_footer"`
}

type TableOutput

type TableOutput struct {
	Headers []string
	Rows    []Row
}

type Tag

type Tag struct {
	Name    string
	Servers []string
}

func (Tag) GetValue

func (t Tag) GetValue(key string, _ int) string

type Target

type Target struct {
	Name    string   `yaml:"name"`
	All     bool     `yaml:"all"`
	Servers []string `yaml:"servers"`
	Tags    []string `yaml:"tags"`
	// contains filtered or unexported fields
}

func (*Target) GetContext

func (t *Target) GetContext() string

func (*Target) GetContextLine

func (t *Target) GetContextLine() int

type Task

type Task struct {
	ID      string
	Name    string
	Desc    string
	TTY     bool
	Local   bool
	Attach  bool
	WorkDir string
	Shell   string
	Envs    []string
	Cmd     string
	Tasks   []TaskCmd
	Spec    Spec
	Target  Target
	Theme   Theme

	TaskRefs  []TaskRef
	SpecRef   string
	TargetRef string
	ThemeRef  string
	// contains filtered or unexported fields
}

func (*Task) GetContext

func (t *Task) GetContext() string

func (*Task) GetContextLine

func (t *Task) GetContextLine() int

func (Task) GetDefaultEnvs

func (t Task) GetDefaultEnvs() []string

func (Task) GetValue

func (t Task) GetValue(key string, _ int) string

type TaskCmd

type TaskCmd struct {
	ID      string
	Name    string
	Desc    string
	WorkDir string
	Shell   string
	RootDir string
	Cmd     string
	Local   bool
	TTY     bool
	Envs    []string
}

This is the struct that is added to the Task.Tasks in import_task.go

type TaskLink struct {
	A TaskNode
	B TaskNode
}

type TaskNode

type TaskNode struct {
	ID       string
	TaskRefs []TaskRef
	Visiting bool
}

type TaskRef

type TaskRef struct {
	Name    string
	Desc    string
	Cmd     string
	WorkDir string
	Shell   string
	Task    string
	Local   *bool
	TTY     *bool
	Envs    []string
}

This is the struct that is added to the Task.TaskRefs

type TaskRefYAML

type TaskRefYAML struct {
	Name    string    `yaml:"name"`
	Desc    string    `yaml:"desc"`
	WorkDir string    `yaml:"work_dir"`
	Shell   string    `yaml:"shell"`
	Cmd     string    `yaml:"cmd"`
	Task    string    `yaml:"task"`
	Local   *bool     `yaml:"local"`
	TTY     *bool     `yaml:"tty"`
	Env     yaml.Node `yaml:"env"`
}

This is the struct that will be unmarsheld from YAML

type TaskResources

type TaskResources struct {
	Tasks      []Task
	TaskErrors []ResourceErrors[Task]
}

Used for config imports

type TaskYAML

type TaskYAML struct {
	Name    string        `yaml:"name"`
	Desc    string        `yaml:"desc"`
	Local   bool          `yaml:"local"`
	TTY     bool          `yaml:"tty"`
	Attach  bool          `yaml:"attach"`
	WorkDir string        `yaml:"work_dir"`
	Shell   string        `yaml:"shell"`
	Cmd     string        `yaml:"cmd"`
	Task    string        `yaml:"task"`
	Tasks   []TaskRefYAML `yaml:"tasks"`
	Env     yaml.Node     `yaml:"env"`
	Spec    yaml.Node     `yaml:"spec"`
	Target  yaml.Node     `yaml:"target"`
	Theme   yaml.Node     `yaml:"theme"`
}

type Text

type Text struct {
	Prefix       bool     `yaml:"prefix"`
	PrefixColors []string `yaml:"prefix_colors"`
	Header       string   `yaml:"header"`
	HeaderFiller string   `yaml:"header_filler"`
}

type Theme

type Theme struct {
	Name  string `yaml:"name"`
	Table Table  `yaml:"table"`
	Text  Text   `yaml:"text"`
	// contains filtered or unexported fields
}

func (*Theme) GetContext

func (t *Theme) GetContext() string

func (*Theme) GetContextLine

func (t *Theme) GetContextLine() int

Jump to

Keyboard shortcuts

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