summaryrefslogtreecommitdiff
path: root/option.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-05 21:57:21 +0300
committerEyal Posener <[email protected]>2017-05-05 21:57:21 +0300
commit5e07cbd4c20a5a3bb5bc84148dc4d4ebffa3d033 (patch)
tree14562796afbc9b220836384339ae80403aa03076 /option.go
parent6311b602abc0f3c0a854c244fca147101b623eba (diff)
Add file completion flag
Diffstat (limited to 'option.go')
-rw-r--r--option.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/option.go b/option.go
new file mode 100644
index 0000000..9333e84
--- /dev/null
+++ b/option.go
@@ -0,0 +1,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)
+}