Documentation
¶
Index ¶
- Constants
- Variables
- type Predictor
- func Cached(name string, ttl time.Duration, load func() []string) Predictor
- func Dirs(pattern string) Predictor
- func FileSet(files []string) Predictor
- func Files(pattern string) Predictor
- func Func(inner func(args.Args) []string) Predictor
- func Or(predictors ...Predictor) Predictor
- func ScopedCache(scope string, name string, ttl time.Duration, load func() []string) Predictor
- func Set(options ...string) Predictor
Constants ¶
const ( // CachedDir is the parent directory under the user cache dir that cached suggestions // will be stored CachedDir = "tab_complete" )
Variables ¶
Anything expects something, but nothing particular, such as a number or arbitrary name.
var UserCacheDir = func() (string, error) { return os.UserCacheDir() }
Allow overriding for tests, but defaults to the operating system's preferred location.
Functions ¶
This section is empty.
Types ¶
type Predictor ¶
Predictor implements a predict method, in which given command line arguments returns a list of options it predicts.
It's given context about what the user has typed for the predictor to make the decision.
var Nothing Predictor
Nothing does not expect anything after.
func Cached ¶
Cached returns a predictor that can re-use previous values for some time until needing to regenerate.
This is useful when the source of truth for items is expensive to calculate, like requiring a network request.
Suggestions are written to a file in the preferred cache directory for the user's OS. The contents of the file a line-delimeted, with every entry being a suggestion. The file's modification time is used to determine whether to refresh or not.
An example filepath might look like: ~/.cache/tab_complete/cmd/name
Where 'cmd' is os.Args[0] and 'name' is provided to this function. CachedDir can be written to customize the containing directory.
func Dirs ¶
Dirs will search for directories in the given started to be typed path, if no path was started to be typed, it will complete to directories in the current working directory.
func Files ¶
Files will search for files matching the given pattern in the started to be typed path, if no path was started to be typed, it will complete to files that match the pattern in the current working directory. To match any file, use "*" as pattern. To match go files use "*.go", and so on.
func Func ¶
Func determines what terms can follow a command or a flag It is used for auto completion, given last - the last word in the already in the command line, what words can complete it.
func Or ¶
Or unions two predicate functions, so that the result predicate returns the union of their predication
func ScopedCache ¶
ScopedCache returns a cached predictor that is scoped manually instead of by the command.
This is useful if you have multiple command-line programs that want to share tab-complete suggestions without duplicating the results.