imports

package
v0.0.0-...-720af6a Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package imports provides handling of claw.mod, local.replace and global.replace files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendImports

func AppendImports(ctx context.Context, pkgPath string) context.Context

AppendImports extracts the ImportFlow in the Context and appends pkgPath to it and returns the new Context.

func FindClawFile

func FindClawFile(fs fs.ReadDirFS, path string) (string, error)

FindClawFile will return the absolute path of the .claw file at path.

func ValidModuleName

func ValidModuleName(module string) error

ValidModuleName determines if a module name is valid.

Types

type ACL

type ACL struct {
	Path string
}

type ClawImports

type ClawImports struct {
	// Directive informs where to put all external repository imports.
	Directive Directive
}

ClawImports represents a claw.imports file and includes halfpike methods to decode the file. A claw.imports file looks like the following:

directive {
	path: "claw/external/imports"
}

func (*ClawImports) ParseDirective

func (c *ClawImports) ParseDirective(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn

func (*ClawImports) SkipLinesWithComments

func (c *ClawImports) SkipLinesWithComments(p *halfpike.Parser)

func (*ClawImports) Start

Start is the start point for reading the claw.imports file.

func (*ClawImports) Validate

func (c *ClawImports) Validate() error

type Config

type Config struct {
	Root *idl.File
	// Imports is a mapping of all package paths to their IDL. If the idl.File == nil but
	// there is a key, then there is a replacement, check the LocalReplace.
	Imports       map[string]*idl.File
	Module        *Module
	LocalReplace  LocalReplace
	GlobalReplace map[string]Replace
	// contains filtered or unexported fields
}

Config just holds the overall union of claw.mod, local.replace and global.replace.

func NewConfig

func NewConfig() *Config

NewConfig creates a new Config.

func (*Config) Abs

func (c *Config) Abs(p string) (string, error)

Abs returns the absolute path to p in the root file git repo.

func (*Config) InRootRepo

func (c *Config) InRootRepo(pkgPath string) bool

InRootRepo will determine if pkgPath is in the root file's repo.

func (*Config) Read

func (c *Config) Read(ctx context.Context, clawFilePath string) error

Read reads the .claw file at clawFilePath, any claw.mod files found, any local.replace file, and uses it to build up our Config with all the files that are imported and that they import until we error or have all the files needed to begin building our Claw language files.

func (*Config) RootDir

func (c *Config) RootDir() string

RootDir returns the root directory for the repo of the root file.

func (Config) Validate

func (c Config) Validate(f *idl.File) error

type Directive

type Directive struct {
	// Path is the path to the location in the git repo to store the imports.
	Path string
}

Directive is a directive on where to store our external package renders.

func (Directive) Validate

func (d Directive) Validate() error

Validate validates the Directive Path for format errors. This doesn't mean the path is good.

type ImportFlow

type ImportFlow []string

ImportFlow is a list of imports that have been imported in this import path. It is used when going down the tree of imports to make sure we do not see ourselves already in the path, which would indicate a cyclic import.

func ExtractImports

func ExtractImports(ctx context.Context) ImportFlow

ExtractImports extracts a list of packages that have been imported in this import chain from the Context object. A nil return indicates you are at the first file.

func (ImportFlow) String

func (i ImportFlow) String() string

type LocalReplace

type LocalReplace struct {
	Replace []Replace
	// contains filtered or unexported fields
}

LocalReplace represents the local.replace file and includes halfpike methods to decode the file.

func NewLocalReplace

func NewLocalReplace(fs neededFS, f *idl.File) LocalReplace

func (*LocalReplace) FindNext

func (*LocalReplace) ParseReplace

func (l *LocalReplace) ParseReplace(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn

func (*LocalReplace) ReplaceMe

func (l *LocalReplace) ReplaceMe(path string) Replace

ReplaceMe returns the replacement for path. Use Replace.IsZero() to dermine if it was found or not.

func (*LocalReplace) SkipLinesWithComments

func (l *LocalReplace) SkipLinesWithComments(p *halfpike.Parser)

func (*LocalReplace) Start

Start is the start point for reading the IDL.

func (*LocalReplace) Validate

func (l *LocalReplace) Validate() error

type Module

type Module struct {
	// Path is the module path.
	Path string
	// Required is a list of specific versions of packages that must be imported.
	Required []Require
	// Replace is a list of packages that should be replaced with a different location.
	Replace []Replace
	// ACLs are a list of ACLs that are provided. If it is set to acls = public, then
	// the first and only ACL will be *.
	ACLs []ACL
}

Module represents a claw.mod file and includes halpike methods to decode the file.

func (*Module) FindNext

func (m *Module) FindNext(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn

FindNext is used to scan lines until we find the next thing to parse and direct to the halfpike.ParseFn responsible.

func (*Module) ParseACLs

func (m *Module) ParseACLs(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn

func (*Module) ParseModule

func (m *Module) ParseModule(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn

func (*Module) ParseReplace

func (m *Module) ParseReplace(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn

func (*Module) ParseRequire

func (m *Module) ParseRequire(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn

func (*Module) SkipLinesWithComments

func (m *Module) SkipLinesWithComments(p *halfpike.Parser)

func (*Module) Start

func (m *Module) Start(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn

Start is the start point for reading the IDL.

func (*Module) Validate

func (m *Module) Validate() error

type Replace

type Replace struct {
	FromPath    string
	FromVersion Version
	ToPath      string
	ToVersion   Version
}

func (Replace) IsZero

func (r Replace) IsZero() bool

type Require

type Require struct {
	// Path is the path the package is located at.
	Path string
	// Version is the version of the package we want. If this is the zero value,
	// we will use the ID.
	Version Version
	// ID is whatever the version control's ID is going to be.
	ID string
}

type Version

type Version struct {
	Major int
	Minor int
	Patch int
}

func (*Version) FromString

func (v *Version) FromString(s string) error

func (Version) IsZero

func (v Version) IsZero() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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