glaze

package module
v0.0.0-...-4bf040d Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 15 Imported by: 0

README

glaze

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PrimaryGlazeSpec = &hcldec.BlockListSpec{
		TypeName: "session",
		MinItems: 1,
		MaxItems: 1,
		Nested: &hcldec.ObjectSpec{
			"name": &hcldec.BlockLabelSpec{
				Index: 0,
				Name:  "name",
			},
			"reattach_on_start": &hcldec.AttrSpec{
				Name: "reattach_on_start",
				Type: cty.Bool,
			},
			"envs": &hcldec.AttrSpec{
				Name: "env",
				Type: cty.Map(cty.String),
			},
			"starting_directory": &hcldec.ValidateSpec{
				Wrapped: &hcldec.AttrSpec{
					Name: "starting_directory",
					Type: cty.String,
				},
				Func: func(value cty.Value) hcl.Diagnostics {
					return DirectoryDiagnostic("starting directory", value)
				},
			},
			"windows": &hcldec.BlockListSpec{
				TypeName: "window",
				MinItems: 1,
				Nested: &hcldec.ObjectSpec{
					"name": &hcldec.BlockLabelSpec{
						Index: 0,
						Name:  "name",
					},
					"envs": &hcldec.AttrSpec{
						Name: "env",
						Type: cty.Map(cty.String),
					},
					"focus": &hcldec.AttrSpec{
						Name: "focus",
						Type: cty.Bool,
					},
					"starting_directory": &hcldec.ValidateSpec{
						Wrapped: &hcldec.AttrSpec{
							Name: "starting_directory",
							Type: cty.String,
						},
						Func: func(value cty.Value) hcl.Diagnostics {
							return DirectoryDiagnostic("starting directory", value)
						},
					},
					"layout": &hcldec.ValidateSpec{
						Wrapped: &hcldec.AttrSpec{
							Name: "layout",
							Type: cty.String,
						},
						Func: func(value cty.Value) hcl.Diagnostics {
							return ContainsDiagnostic("layout", value, enums.LayoutList)
						},
					},
					"panes": &hcldec.BlockListSpec{
						TypeName: "pane",
						MinItems: 1,
						Nested: &hcldec.ValidateSpec{
							Wrapped: &hcldec.ObjectSpec{
								"name": &hcldec.BlockLabelSpec{
									Index: 0,
									Name:  "name",
								},
								"envs": &hcldec.AttrSpec{
									Name: "env",
									Type: cty.Map(cty.String),
								},
								"focus": &hcldec.AttrSpec{
									Name: "focus",
									Type: cty.Bool,
								},
								"size": &hcldec.ValidateSpec{
									Wrapped: &hcldec.AttrSpec{
										Name: "size",
										Type: cty.String,
									},
									Func: func(value cty.Value) hcl.Diagnostics {
										var diags hcl.Diagnostics

										if !value.IsNull() {
											input := value.AsString()

											matched := regexp.MustCompile(`^(\\d+|\\d+%)$`).MatchString(input)

											if input[len(input)-1] == '%' {
												input = input[:len(input)-1]
											}

											_, err := strconv.Atoi(input)

											if err != nil || !matched {
												diags = diags.Append(&hcl.Diagnostic{
													Severity: hcl.DiagError,
													Summary:  `Invalid size specified`,
													Detail:   `The size value must be either an integer or a percentage.`,
												})
											}
										}

										return diags
									},
								},
								"placement": &hcldec.ValidateSpec{
									Wrapped: &hcldec.AttrSpec{
										Name: "placement",
										Type: cty.String,
									},
									Func: func(value cty.Value) hcl.Diagnostics {
										return ContainsDiagnostic("placement", value, enums.PlacementList)
									},
								},
								"full": &hcldec.ValidateSpec{
									Wrapped: &hcldec.AttrSpec{
										Name: "full",
										Type: cty.String,
									},
									Func: func(value cty.Value) hcl.Diagnostics {
										return ContainsDiagnostic("full", value, enums.FullList)
									},
								},
								"split": &hcldec.ValidateSpec{
									Wrapped: &hcldec.AttrSpec{
										Name: "split",
										Type: cty.String,
									},
									Func: func(value cty.Value) hcl.Diagnostics {
										return ContainsDiagnostic("split", value, enums.SplitList)
									},
								},
								"starting_directory": &hcldec.ValidateSpec{
									Wrapped: &hcldec.AttrSpec{
										Name: "starting_directory",
										Type: cty.String,
									},
									Func: func(value cty.Value) hcl.Diagnostics {
										return DirectoryDiagnostic("starting directory", value)
									},
								},
								"commands": &hcldec.AttrSpec{
									Name: "commands",
									Type: cty.List(cty.String),
								},
							},
							Func: func(value cty.Value) hcl.Diagnostics {
								var diags hcl.Diagnostics

								split := value.GetAttr("split")
								full := value.GetAttr("full")
								placement := value.GetAttr("placement")
								if split.IsNull() || enums.SplitFromString(split.AsString()) == enums.SplitVertical {
									if !placement.IsNull() && enums.PlacementFromString(placement.AsString()) == enums.PlacementAbove {
										diags = diags.Append(WrongAttributeDiagnostic("placement", placement.AsString(), enums.PlacementLeftString))
									}

									if !full.IsNull() && enums.FullFromString(full.AsString()) == enums.FullHeight {
										diags = diags.Append(WrongAttributeDiagnostic("full", full.AsString(), enums.FullWidthString))
									}

									return diags
								}

								if !split.IsNull() && enums.SplitFromString(split.AsString()) == enums.SplitHorizontal {
									if !placement.IsNull() && enums.PlacementFromString(placement.AsString()) == enums.PlacementLeft {
										diags = diags.Append(WrongAttributeDiagnostic("placement", placement.AsString(), enums.PlacementAboveString))

									}

									if !full.IsNull() && enums.FullFromString(full.AsString()) == enums.FullWidth {
										diags = diags.Append(WrongAttributeDiagnostic("full", full.AsString(), enums.FullHeightString))
									}

									return diags
								}

								return nil
							},
						},
					},
				},
			},
		},
	}
)

Functions

func ContainsDiagnostic

func ContainsDiagnostic(field string, value cty.Value, list []string) hcl.Diagnostics

func DirectoryDiagnostic

func DirectoryDiagnostic(field string, value cty.Value) hcl.Diagnostics

func FileExists

func FileExists(path string) bool

func JoinWithAnd

func JoinWithAnd(choices []string) string

func JoinWithOr

func JoinWithOr(choices []string) string

func Prettier

func Prettier(values ...any)

func WrongAttributeDiagnostic

func WrongAttributeDiagnostic(field, have, want string) *hcl.Diagnostic

Types

type Parser

type Parser struct {
	File *hcl.File
	// contains filtered or unexported fields
}

func NewParser

func NewParser(path string) *Parser

func (*Parser) AppendDiag

func (p *Parser) AppendDiag(diag *hcl.Diagnostic)

func (*Parser) Decode

func (p *Parser) Decode(s hcldec.Spec) *models.Session

func (*Parser) HasErrors

func (p *Parser) HasErrors() bool

func (*Parser) WriteDiags

func (p *Parser) WriteDiags() error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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