summaryrefslogtreecommitdiff
path: root/option.go
blob: 9333e842ffbd0a6e862bf7373db46014ef74ed16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package complete

import (
	"path/filepath"
	"strings"
)

type Option interface {
	String() string
	Matches(prefix string) bool
}

type Arg string

func (a Arg) String() string {
	return string(a)
}

func (a Arg) Matches(prefix string) bool {
	return strings.HasPrefix(string(a), prefix)
}

type ArgFileName string

func (a ArgFileName) String() string {
	return string(a)
}

func (a ArgFileName) Matches(prefix string) bool {
	full, err := filepath.Abs(string(a))
	if err != nil {
		logger("failed getting abs path of %s: %s", a, err)
	}
	prefixFull, err := filepath.Abs(prefix)
	if err != nil {
		logger("failed getting abs path of %s: %s", prefix, err)
	}
	return strings.HasPrefix(full, prefixFull)
}