config

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "grab"
View Source
const VersionMajor = 0
View Source
const VersionMinor = 1
View Source
const VersionPatch = 2

Variables

View Source
var AssetSpec = &hcldec.ObjectSpec{
	"name": &hcldec.BlockLabelSpec{
		Index: 0,
		Name:  "name",
	},
	"pattern": &hcldec.AttrSpec{
		Name:     "pattern",
		Type:     cty.String,
		Required: true,
	},
	"capture": &hcldec.AttrSpec{
		Name:     "capture",
		Type:     cty.String,
		Required: true,
	},
	"find_all": &hcldec.AttrSpec{
		Name:     "find_all",
		Type:     cty.Bool,
		Required: false,
	},
	"network": &hcldec.BlockSpec{
		TypeName: "network",
		Required: false,
		Nested:   NetworkSpec,
	},
	"transforms": &hcldec.BlockTupleSpec{
		TypeName: "transform",
		MinItems: 0,
		MaxItems: 2,
		Nested:   TransformSpec,
	},
}
View Source
var BuildArch = "unknown"
View Source
var BuildOS = "unknown"
View Source
var BuildType = "devel"
View Source
var CommitHash = "unknown"
View Source
var ConfigSpec = &hcldec.ObjectSpec{
	"global": &hcldec.BlockSpec{
		TypeName: "global",
		Required: true,
		Nested:   GlobalSpec,
	},
	"sites": &hcldec.BlockTupleSpec{
		TypeName: "site",
		MinItems: 1,
		Nested:   SiteSpec,
	},
}
View Source
var GlobalSpec = &hcldec.ObjectSpec{
	"location": &hcldec.AttrSpec{
		Name:     "location",
		Required: true,
		Type:     cty.String,
	},
	"network": &hcldec.BlockSpec{
		TypeName: "network",
		Required: false,
		Nested:   RootNetworkSpec,
	},
}
View Source
var InfoSpec = &hcldec.ObjectSpec{
	"name": &hcldec.BlockLabelSpec{
		Index: 0,
		Name:  "name",
	},
	"pattern": &hcldec.AttrSpec{
		Name:     "pattern",
		Type:     cty.String,
		Required: true,
	},
	"capture": &hcldec.AttrSpec{
		Name:     "capture",
		Type:     cty.String,
		Required: true,
	},
}
View Source
var NetworkSpec = &hcldec.ObjectSpec{
	"inherit": &hcldec.AttrSpec{
		Name:     "inherit",
		Required: false,
		Type:     cty.Bool,
	},
	"timeout": &hcldec.AttrSpec{
		Name:     "timeout",
		Required: false,
		Type:     cty.Number,
	},
	"retries": &hcldec.AttrSpec{
		Name:     "retries",
		Required: false,
		Type:     cty.Number,
	},
	"headers": &hcldec.AttrSpec{
		Name:     "headers",
		Required: false,
		Type:     cty.Map(cty.String),
	},
}
View Source
var RootNetworkSpec = &hcldec.ObjectSpec{
	"timeout": &hcldec.AttrSpec{
		Name:     "timeout",
		Required: false,
		Type:     cty.Number,
	},
	"retries": &hcldec.AttrSpec{
		Name:     "retries",
		Required: false,
		Type:     cty.Number,
	},
	"headers": &hcldec.AttrSpec{
		Name:     "headers",
		Required: false,
		Type:     cty.Map(cty.String),
	},
}
View Source
var SiteSpec = &hcldec.ObjectSpec{
	"name": &hcldec.BlockLabelSpec{
		Index: 0,
		Name:  "name",
	},
	"test": &hcldec.AttrSpec{
		Name:     "test",
		Type:     cty.String,
		Required: true,
	},
	"network": &hcldec.BlockSpec{
		TypeName: "network",
		Required: false,
		Nested:   NetworkSpec,
	},

	"assets": &hcldec.BlockTupleSpec{
		TypeName: "asset",
		MinItems: 0,
		Nested:   AssetSpec,
	},

	"infos": &hcldec.BlockTupleSpec{
		TypeName: "info",
		MinItems: 0,
		Nested:   InfoSpec,
	},
	"subdirectory": &hcldec.BlockSpec{
		TypeName: "subdirectory",
		Required: false,
		Nested:   SubdirectorySpec,
	},
}
View Source
var SubdirectorySpec = &hcldec.ObjectSpec{
	"pattern": &hcldec.AttrSpec{
		Name:     "pattern",
		Type:     cty.String,
		Required: true,
	},
	"capture": &hcldec.AttrSpec{
		Name:     "capture",
		Type:     cty.String,
		Required: true,
	},
	"from": &hcldec.AttrSpec{
		Name:     "from",
		Type:     cty.String,
		Required: true,
	},
}
View Source
var TransformSpec = &hcldec.ObjectSpec{
	"name": &hcldec.BlockLabelSpec{
		Index: 0,
		Name:  "name",
	},
	"pattern": &hcldec.AttrSpec{
		Name:     "pattern",
		Type:     cty.String,
		Required: true,
	},
	"replace": &hcldec.AttrSpec{
		Name:     "replace",
		Type:     cty.String,
		Required: true,
	},
}

must validate that there is only one "url" and only one "filename"

Functions

func BuildRegexCache

func BuildRegexCache(root *hclsyntax.Body, ctx *hcl.EvalContext) (map[string]*regexp.Regexp, hcl.Diagnostics)

validate all regexp attributes - site*.test - site*.assets*.pattern - site*.assets*.transform*.pattern - site*.info*.pattern - site*.subdirectory.pattern

func EvaluateRegexPattern

func EvaluateRegexPattern(attr *hclsyntax.Attribute, ctx *hcl.EvalContext) (string, *regexp.Regexp, hcl.Diagnostics)

func Resolve

func Resolve(filename, path string) (string, error)

NOTE: the path must be absolute! use filepath.Abs(".") or os.Getwd()

func ValidateConfig

func ValidateConfig(root *hclsyntax.Body, ctx *hcl.EvalContext) hcl.Diagnostics

func ValidateSpec

func ValidateSpec(body *hcl.Body, ctx *hcl.EvalContext) hcl.Diagnostics

Types

type AssetConfig

type AssetConfig struct {
	Name       string            `hcl:"name,label"`
	Pattern    string            `hcl:"pattern"`
	Capture    string            `hcl:"capture"`
	FindAll    *bool             `hcl:"find_all"`
	Network    *NetworkConfig    `hcl:"network,block"`
	Transforms []TransformConfig `hcl:"transform,block"`
	// computed
	Downloads map[string]string
}

type Config

type Config struct {
	Global GlobalConfig `hcl:"global,block"`
	Sites  []SiteConfig `hcl:"site,block"`
}

func Parse

func Parse(b []byte, filename string) (*Config, *hcl.EvalContext, map[string]*regexp.Regexp, hcl.Diagnostics)

type GlobalConfig

type GlobalConfig struct {
	Location string             `hcl:"location"`
	Network  *RootNetworkConfig `hcl:"network,block"`
}

type InfoConfig

type InfoConfig struct {
	Name    string `hcl:"name,label"`
	Pattern string `hcl:"pattern"`
	Capture string `hcl:"capture"`
}

type NetworkConfig

type NetworkConfig struct {
	Inherit *bool              `hcl:"inherit"`
	Timeout *int               `hcl:"timeout"`
	Retries *int               `hcl:"retries"`
	Headers *map[string]string `hcl:"headers"`
}

type RootNetworkConfig

type RootNetworkConfig struct {
	Timeout *int               `hcl:"timeout"`
	Retries *int               `hcl:"retries"`
	Headers *map[string]string `hcl:"headers"`
}

type SiteConfig

type SiteConfig struct {
	Name         string              `hcl:"name,label"`
	Test         string              `hcl:"test"`
	Network      *NetworkConfig      `hcl:"network,block"`
	Subdirectory *SubdirectoryConfig `hcl:"subdirectory,block"`
	Assets       []AssetConfig       `hcl:"asset,block"`
	Infos        []InfoConfig        `hcl:"info,block"`
	// computed
	URLs       []string
	InfoMap    map[string]map[string]string // location -> info -> value
	HasMatches bool
}

type SubdirectoryConfig

type SubdirectoryConfig struct {
	Pattern string `hcl:"pattern"`
	Capture string `hcl:"capture"`
	From    string `hcl:"from"`
}

type TransformConfig

type TransformConfig struct {
	Name    string `hcl:"name,label"`
	Pattern string `hcl:"pattern"`
	Replace string `hcl:"replace"`
}

Jump to

Keyboard shortcuts

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