dao

package
v0.25.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DEFAULT_SHELL         = "sh -c"
	DEFAULT_SHELL_PROGRAM = "sh"
	ACCEPTABLE_FILE_NAMES = []string{"mani.yaml", "mani.yml", ".mani.yaml", ".mani.yml"}

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

	DEFAULT_TARGET = Target{
		Name: "default",

		All:      false,
		Projects: []string{},
		Paths:    []string{},
		Tags:     []string{},
		Cwd:      false,
	}

	DEFAULT_SPEC = Spec{
		Name: "default",

		Output:       "text",
		Parallel:     false,
		IgnoreErrors: false,
		OmitEmpty:    false,
	}
)
View Source
var DefaultTable = Table{
	Box: table.StyleLight.Box,

	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{
			Project: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
			Synced: &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"),
			},
			RelPath: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
			Path: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr("bold"),
			},
			Url: &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{
			Project: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
			Synced: &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(""),
			},
			RelPath: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
			Path: &ColorOptions{
				Fg:    core.Ptr(""),
				Bg:    core.Ptr(""),
				Align: core.Ptr(""),
				Attr:  core.Ptr(""),
			},
			Url: &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:       true,
	HeaderPrefix: "TASK",
	HeaderChar:   "*",
}
View Source
var DefaultTree = Tree{
	Style: "light",
}

Functions

func CheckUserNoColor added in v0.20.0

func CheckUserNoColor(noColorFlag bool)

func EvaluateEnv added in v0.20.0

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

func FormatErrors added in v0.20.0

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

func (re *ResourceErrors[T]) Combine() error {

func MergeEnvs added in v0.20.0

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

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

func ParseNodeEnv added in v0.20.0

func ParseNodeEnv(node yaml.Node) []string

func ParseTaskEnv added in v0.20.0

func ParseTaskEnv(env yaml.Node, userEnv []string, parentEnv []string, configEnv []string) ([]string, error)

func ProjectInSlice

func ProjectInSlice(name string, list []Project) bool

func RenameDuplicates added in v0.20.0

func RenameDuplicates(projects []Project)

func TaskSpinner added in v0.6.1

func TaskSpinner() (yacspin.Spinner, error)

func UpdateProjectsToGitignore

func UpdateProjectsToGitignore(projectNames []string, gitignoreFilename string) error

Types

type BorderColors added in v0.20.0

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

type CellColors added in v0.20.0

type CellColors struct {
	Project *ColorOptions `yaml:"project"`
	Synced  *ColorOptions `yaml:"synced"`
	Tag     *ColorOptions `yaml:"tag"`
	Desc    *ColorOptions `yaml:"desc"`
	RelPath *ColorOptions `yaml:"rel_path"`
	Path    *ColorOptions `yaml:"path"`
	Url     *ColorOptions `yaml:"url"`
	Task    *ColorOptions `yaml:"task"`
	Output  *ColorOptions `yaml:"output"`
}

type ColorOptions added in v0.20.0

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

type Command

type Command struct {
	Name    string    `yaml:"name"`
	Desc    string    `yaml:"desc"`
	Shell   string    `yaml:"shell"` // should be in the format: <program> <command flag>, for instance "sh -c", "node -e"
	Cmd     string    `yaml:"cmd"`   // "echo hello world", it should not include the program flag (-c,-e, .etc)
	Task    string    `yaml:"task"`
	Env     yaml.Node `yaml:"env"`
	EnvList []string  `yaml:"-"`

	// Internal
	ShellProgram string   `yaml:"-"` // should be in the format: <program>, example: "sh", "node"
	CmdArg       []string `yaml:"-"` // is in the format ["-c echo hello world"] or ["-c", "echo hello world"], it includes the shell flag
}

type Config

type Config struct {
	// Internal
	EnvList        []string  `yaml:"-"`
	ImportData     []Import  `yaml:"-"`
	ThemeList      []Theme   `yaml:"-"`
	SpecList       []Spec    `yaml:"-"`
	TargetList     []Target  `yaml:"-"`
	ProjectList    []Project `yaml:"-"`
	TaskList       []Task    `yaml:"-"`
	Path           string    `yaml:"-"`
	Dir            string    `yaml:"-"`
	UserConfigFile *string   `yaml:"-"`

	Shell       string `yaml:"shell"`
	SyncRemotes bool   `yaml:"sync_remotes"`

	// Intermediate
	Env      yaml.Node `yaml:"env"`
	Import   yaml.Node `yaml:"import"`
	Themes   yaml.Node `yaml:"themes"`
	Specs    yaml.Node `yaml:"specs"`
	Targets  yaml.Node `yaml:"targets"`
	Projects yaml.Node `yaml:"projects"`
	Tasks    yaml.Node `yaml:"tasks"`
}

func ReadConfig

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

Function to read Mani configs.

func (*Config) CheckConfigNoColor added in v0.20.0

func (c *Config) CheckConfigNoColor()

func (Config) EditConfig added in v0.10.0

func (c Config) EditConfig() error

Open mani config in editor

func (Config) EditProject added in v0.10.0

func (c Config) EditProject(name string) error

Open mani config in editor and optionally go to line matching the project name

func (Config) EditTask added in v0.10.0

func (c Config) EditTask(name string) error

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

func (Config) FilterProjects

func (c Config) FilterProjects(
	cwdFlag bool,
	allProjectsFlag bool,
	projectsFlag []string,
	projectPathsFlag []string,
	tagsFlag []string,
) ([]Project, error)

func (Config) GetCommand

func (c Config) GetCommand(taskName string) (*Command, error)

func (*Config) GetContext added in v0.20.0

func (c *Config) GetContext() string

func (*Config) GetContextLine added in v0.20.0

func (c *Config) GetContextLine() int

func (Config) GetCwdProject

func (c Config) GetCwdProject() (Project, error)

func (Config) GetEnvList added in v0.10.0

func (c Config) GetEnvList() []string

Returns the config env list as a string splice in the form [key=value, key1=$(echo 123)]

func (*Config) GetImportList added in v0.20.0

func (c *Config) GetImportList() ([]Import, []ResourceErrors[Import])

Populates SpecList and creates a default spec if no default spec is set.

func (Config) GetProject added in v0.10.0

func (c Config) GetProject(name string) (*Project, error)

func (*Config) GetProjectList added in v0.10.0

func (c *Config) GetProjectList() ([]Project, []ResourceErrors[Project])

func (Config) GetProjectNames

func (c Config) GetProjectNames() []string

func (Config) GetProjectPaths added in v0.10.0

func (c Config) GetProjectPaths() []string

*

  • For each project path, get all the enumerations of dirnames.
  • Example:
  • Input:
  • - /frontend/tools/project-a
  • - /frontend/tools/project-b
  • - /frontend/tools/node/project-c
  • - /backend/project-d
  • Output:
  • - /frontend
  • - /frontend/tools
  • - /frontend/tools/node
  • - /backend

func (Config) GetProjectUrls

func (c Config) GetProjectUrls() []string

func (Config) GetProjectsByName

func (c Config) GetProjectsByName(projectNames []string) ([]Project, error)

func (Config) GetProjectsByPath added in v0.10.0

func (c Config) GetProjectsByPath(dirs []string) ([]Project, error)

Projects must have all dirs to match. If user provides a path which does not exist, then return error containing all the paths it didn't find.

func (Config) GetProjectsByTags

func (c Config) GetProjectsByTags(tags []string) ([]Project, error)

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

func (Config) GetProjectsTree added in v0.6.1

func (c Config) GetProjectsTree(dirs []string, tags []string) ([]TreeNode, error)

func (Config) GetSpec added in v0.12.0

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

func (*Config) GetSpecList added in v0.12.0

func (c *Config) GetSpecList() ([]Spec, []ResourceErrors[Spec])

Populates SpecList and creates a default spec if no default spec is set.

func (Config) GetSpecNames added in v0.12.0

func (c Config) GetSpecNames() []string

func (Config) GetTagAssocations added in v0.10.0

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

func (Config) GetTags

func (c Config) GetTags() []string

func (Config) GetTarget added in v0.12.0

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

func (*Config) GetTargetList added in v0.12.0

func (c *Config) GetTargetList() ([]Target, []ResourceErrors[Target])

Populates TargetList and creates a default target if no default target is set.

func (Config) GetTargetNames added in v0.12.0

func (c Config) GetTargetNames() []string

func (Config) GetTask added in v0.6.1

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

func (*Config) GetTaskList added in v0.10.0

func (c *Config) GetTaskList() ([]Task, []ResourceErrors[Task])

func (Config) GetTaskNameAndDesc added in v0.20.0

func (c Config) GetTaskNameAndDesc() []string

func (Config) GetTaskNames added in v0.6.1

func (c Config) GetTaskNames() []string

func (Config) GetTaskProjects added in v0.12.0

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

func (Config) GetTasksByNames added in v0.6.1

func (c Config) GetTasksByNames(names []string) ([]Task, error)

func (Config) GetTheme added in v0.10.0

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

func (*Config) GetThemeList added in v0.10.0

func (c *Config) GetThemeList() ([]Theme, []ResourceErrors[Theme])

Populates ThemeList

func (Config) GetThemeNames added in v0.10.0

func (c Config) GetThemeNames() []string

type ConfigResources added in v0.10.0

type ConfigResources struct {
	Imports  []Import
	Themes   []Theme
	Specs    []Spec
	Targets  []Target
	Tasks    []Task
	Projects []Project
	Envs     []string

	ThemeErrors   []ResourceErrors[Theme]
	SpecErrors    []ResourceErrors[Spec]
	TargetErrors  []ResourceErrors[Target]
	TaskErrors    []ResourceErrors[Task]
	ProjectErrors []ResourceErrors[Project]
	ImportErrors  []ResourceErrors[Import]
}

Used for config imports

type FoundCyclicDependency added in v0.20.0

type FoundCyclicDependency struct {
	Cycles []NodeLink
}

func (*FoundCyclicDependency) Error added in v0.20.0

func (c *FoundCyclicDependency) Error() string

type Import added in v0.20.0

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

func (*Import) GetContext added in v0.20.0

func (i *Import) GetContext() string

func (*Import) GetContextLine added in v0.20.0

func (i *Import) GetContextLine() int

type Node added in v0.20.0

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

type Project

type Project struct {
	Name       string   `yaml:"name"`
	Path       string   `yaml:"path"`
	Desc       string   `yaml:"desc"`
	Url        string   `yaml:"url"`
	Clone      string   `yaml:"clone"`
	Tags       []string `yaml:"tags"`
	Sync       *bool    `yaml:"sync"`
	EnvList    []string `yaml:"-"`
	RemoteList []Remote `yaml:"-"`

	Env     yaml.Node `yaml:"env"`
	Remotes yaml.Node `yaml:"remotes"`

	RelPath string
	// contains filtered or unexported fields
}

func FindVCSystems

func FindVCSystems(rootPath string) ([]Project, error)

func GetIntersectProjects

func GetIntersectProjects(a []Project, b []Project) []Project

func GetUnionProjects

func GetUnionProjects(ps ...[]Project) []Project

func InitMani added in v0.10.0

func InitMani(args []string, initFlags core.InitFlags) ([]Project, error)

func (*Project) GetContext added in v0.20.0

func (p *Project) GetContext() string

func (*Project) GetContextLine added in v0.20.0

func (p *Project) GetContextLine() int

func (Project) GetValue

func (p Project) GetValue(key string, _ int) string

func (Project) IsSync added in v0.20.0

func (p Project) IsSync() bool

type Remote added in v0.24.0

type Remote struct {
	Name string
	Url  string
}

func ParseRemotes added in v0.24.0

func ParseRemotes(node yaml.Node) []Remote

type Resource added in v0.20.0

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

type ResourceErrors added in v0.20.0

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

type Row added in v0.20.0

type Row struct {
	Columns []string
}

func (Row) GetValue added in v0.20.0

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

type Spec added in v0.12.0

type Spec struct {
	Name              string `yaml:"name"`
	Output            string `yaml:"output"`
	Parallel          bool   `yaml:"parallel"`
	IgnoreErrors      bool   `yaml:"ignore_errors"`
	IgnoreNonExisting bool   `yaml:"ignore_non_existing"`
	OmitEmpty         bool   `yaml:"omit_empty"`
	// contains filtered or unexported fields
}

func (*Spec) GetContext added in v0.20.0

func (s *Spec) GetContext() string

func (*Spec) GetContextLine added in v0.20.0

func (s *Spec) GetContextLine() int

type Table added in v0.20.0

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 added in v0.20.0

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

type TableFormat added in v0.20.0

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

type TableOptions added in v0.20.0

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 added in v0.20.0

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

type Tag added in v0.20.0

type Tag struct {
	Name     string
	Projects []string
}

func (Tag) GetValue added in v0.20.0

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

type Target added in v0.10.0

type Target struct {
	Name     string   `yaml:"name"`
	All      bool     `yaml:"all"`
	Projects []string `yaml:"projects"`
	Paths    []string `yaml:"paths"`
	Tags     []string `yaml:"tags"`
	Cwd      bool     `yaml:"cwd"`
	// contains filtered or unexported fields
}

func (*Target) GetContext added in v0.20.0

func (t *Target) GetContext() string

func (*Target) GetContextLine added in v0.20.0

func (t *Target) GetContextLine() int

type Task added in v0.6.1

type Task struct {
	SpecData   Spec
	TargetData Target
	ThemeData  Theme

	Name     string    `yaml:"name"`
	Desc     string    `yaml:"desc"`
	Shell    string    `yaml:"shell"`
	Cmd      string    `yaml:"cmd"`
	Commands []Command `yaml:"commands"`
	EnvList  []string  `yaml:"-"`

	Env    yaml.Node `yaml:"env"`
	Spec   yaml.Node `yaml:"spec"`
	Target yaml.Node `yaml:"target"`
	Theme  yaml.Node `yaml:"theme"`

	// Internal
	ShellProgram string   `yaml:"-"` // should be in the format: <program>, example: "sh", "node"
	CmdArg       []string `yaml:"-"` // is in the format ["-c echo hello world"] or ["-c", "echo hello world"], it includes the shell flag
	// contains filtered or unexported fields
}

func (*Task) GetContext added in v0.20.0

func (t *Task) GetContext() string

func (*Task) GetContextLine added in v0.20.0

func (t *Task) GetContextLine() int

func (Task) GetValue added in v0.10.0

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

func (*Task) ParseTask added in v0.10.0

func (t *Task) ParseTask(config Config, taskErrors *ResourceErrors[Task])

ParseTask parses tasks and builds the correct "AST". Depending on if the data is specified inline, or if it is a reference to resource, it will handle them differently.

type Text added in v0.20.0

type Text struct {
	Prefix       bool     `yaml:"prefix"`
	PrefixColors []string `yaml:"prefix_colors"`
	Header       bool     `yaml:"header"`
	HeaderChar   string   `yaml:"header_char"`
	HeaderPrefix string   `yaml:"header_prefix"`
}

type Theme added in v0.10.0

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

func (*Theme) GetContext added in v0.20.0

func (t *Theme) GetContext() string

func (*Theme) GetContextLine added in v0.20.0

func (t *Theme) GetContextLine() int

type Tree added in v0.20.0

type Tree struct {
	Style string `yaml:"style"`
}

type TreeNode added in v0.20.0

type TreeNode struct {
	Name     string
	Children []TreeNode
}

func AddToTree added in v0.20.0

func AddToTree(root []TreeNode, names []string) []TreeNode

Jump to

Keyboard shortcuts

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