predict

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: MIT Imports: 6 Imported by: 28

Documentation

Overview

Package predict provides helper functions for completion predictors.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Something is used to indicate that does not completes somthing. Such that other prediction
	// wont be applied.
	Something = Set{""}

	// Nothing is used to indicate that does not completes anything.
	Nothing = Set{}
)

Functions

func Or

func Or(ps ...complete.Predictor) complete.Predictor

Or unions prediction functions, so that the result predication is the union of their predications.

Types

type Config

type Config struct {
	complete.Predictor
	// contains filtered or unexported fields
}

Config stores prediction options.

func Options

func Options(os ...Option) Config

Options return a config from a list of options.

func (Config) Check

func (c Config) Check(value string) error

Check checks that value is one of the predicted values, in case that the check field was set.

func (Config) Predict

func (c Config) Predict(prefix string) []string

type FilesPredictor

type FilesPredictor struct {
	// contains filtered or unexported fields
}

func Dirs

func Dirs(pattern string) FilesPredictor

Dirs returns a predictor that predict directory paths. If a non-empty pattern is given, the predicted paths will match that pattern.

func Files

func Files(pattern string) FilesPredictor

Dirs returns a predictor that predict file or directory paths. If a non-empty pattern is given, the predicted paths will match that pattern.

func (FilesPredictor) Predict

func (f FilesPredictor) Predict(prefix string) (options []string)

Predict searches for files according to the given prefix. If the only predicted path is a single directory, the search will continue another recursive layer into that directory.

type FilesSet

type FilesSet []string

FilesSet predict according to file rules to a given fixed set of file names.

func (FilesSet) Predict

func (s FilesSet) Predict(prefix string) (prediction []string)

type Option

type Option func(*Config)

Option provides prediction through options pattern.

Usage:

func(o ...predict.Option) {
	cfg := predict.Options(o)
	// use cfg.Predict...
}

func OptCheck

func OptCheck() Option

OptCheck enforces the valid values on the predicted flag.

func OptPredictor

func OptPredictor(p complete.Predictor) Option

OptPredictor allows to set a custom predictor.

func OptValues

func OptValues(values ...string) Option

OptValues allows to set a desired set of valid values for the flag.

type Set

type Set []string

Set predicts a set of predefined values.

func (Set) Predict

func (p Set) Predict(_ string) (options []string)

Jump to

Keyboard shortcuts

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