pkg

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DConditionInstallingBots = func(ctx *Context, args AnySlice) bool {
	if len(args) == 0 {
		return false
	}

	for _, arg := range args {
		if bot, ok := arg.(string); ok {
			log.Trace().Str("bot", bot).Msg("Checking if installing bot")
			if !ctx.installingBot(bot) {
				return false
			}
		} else {
			log.Error().Str("bot", bot).
				Msgf("%s predicate can only accept strings, not %T", edn.Keyword("bot"), bot)
			return false
		}
	}

	return true
}
View Source
var Directives map[edn.Keyword]directiveConstructor

Functions

func ExpandTilde

func ExpandTilde(homeDir, path string) string

*

  • Substitute ~/ for homeDir in path

func FindExistingFile

func FindExistingFile(paths ...string) (string, error)

*

  • return the first path in paths that points to an existing file.
  • if there's an error while stating any file, immeadiately returns
  • cancelling any pending file checks.

func GetShell

func GetShell() string

func JoinPath

func JoinPath(paths ...string) string

*

  • Join paths in a unixy (pythonic) way. if all the supplied paths are relative
  • their joined together. If one of them is absolute, only the path from the last
  • absolute path to the final non-absolute path are joined together. *
  • Any paths prefixed with ~/ is considered to be pointing to the users home directory
  • and is treated as absolute. *
  • NOTE: Trailing slashes aren't stripped by this implementation
  • joinPath("~/foo", "bar/") // => "~/foo/bar/"

func LoadEdnSlice

func LoadEdnSlice(fpath string, callback func(AnySlice))

load an edn slice of directives from the file at fpath and pass the result to callback.

func ParseDirective

func ParseDirective(directive edn.Keyword, ctx *Context, args AnySlice)

*

  • find the directive constructor associated with directive and initialise
  • it with the given arguments and context.

func PathExistsCheck

func PathExistsCheck(path string, extraCheck func(os.FileInfo) bool, def bool, followSymlinks bool) (bool, error)

func StringSliceContains

func StringSliceContains(strs []string, val string) bool

Types

type Any

type Any = interface{}

type AnySlice

type AnySlice = []Any

type Context

type Context struct {
	Root string
	Cwd  string

	// home directory for the current user.
	// It's kept here because the it shouldn't be modifiable.
	Home string

	// The default shell used for subprocesses, this can be overridden.
	// using envOpts.
	Shell string

	Bots []string

	OnlyDirectives   []string
	ExceptDirectives []string

	// send parsed directives through here.
	DirChan chan directive
	// contains filtered or unexported fields
}

Context - store for contextual information in the dotty runtime.

func CreateContext

func CreateContext() *Context

Notes

Bugs

  • evaluation of tags takes place before construction of Context so we're creating a dummy context here to evaluate any env variables in the paths. The only substitutions these can manage will be environment variables. Any changes made to the local context won't appear.

    A decent workaround would be to spread out recursively built paths, such as (("foo" ("bar" "baz"))) => (("foo" ("bar") ("foo" ("baz"))) but that would require reimplementing a good chunk of the logic in recursiveBuildPath to support chanelling String slices instead of strings. I'll wait until go adds generics to fix this, it's personally low priority.

    To summarise, we shouold go from: #dot/link-gen (:link

    "~/.foo"
    (".foo" ".bar" ".baz" (".bag"))
    ("${XDG_CONFIG_HOME}"
    (".bar" ".baz" ".bag"))
    ;; or dest if it's missing instead
    {:src "local_file"
    :mkdirs false}
    ;; when both are present, #dot/link-gen is ignored.
    {:src "local_file" :dest "dest_file"}
    ;; more complex structures lead to more complex maps.
    {:src ("local_file" ("foo" "bar"))})
    

    to: (:link ("$XDG_CONFIG_HOME" (".bar")) "bar"

    ("$XDG_CONFIG_HOME" (".baz")) "baz"
    ("$XDG_CONFIG_HOME" (".bag")) "bag"
    {:src "local_file"
    :dest "~/.local_file"
    :mkdirs false}
    {:src "local_file"
    :dest "dest_file"}
    {:src "local_file"
    :dest "dest_file"}
    {:src "local_file/foo"
    :dest "~/.foo"}
    {:src "local_file/bar"
    :dest "~/.bar"})
    

Jump to

Keyboard shortcuts

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