summaryrefslogtreecommitdiff
path: root/args.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-11 20:54:26 +0300
committerGitHub <[email protected]>2017-05-11 20:54:26 +0300
commitd3bbb859d52b45987e3cd2098e28423f32edd999 (patch)
tree4265893d0c665ba0e763482a70c9044fa983a1ed /args.go
parentdd2171d085ef5957a1c5c0794d6007822e47849b (diff)
parentba23c350c73d2dfdf071c14c22152bcaf7e7fd7b (diff)
Merge pull request #12 from posener/improves
Enhance program structure and data structures
Diffstat (limited to 'args.go')
-rw-r--r--args.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/args.go b/args.go
new file mode 100644
index 0000000..86dd41a
--- /dev/null
+++ b/args.go
@@ -0,0 +1,39 @@
+package complete
+
+// Args describes command line arguments
+type Args struct {
+ All []string
+ Completed []string
+ Last string
+ LastCompleted string
+}
+
+func newArgs(line []string) Args {
+ completed := removeLast(line)
+ return Args{
+ All: line[1:],
+ Completed: completed,
+ Last: last(line),
+ LastCompleted: last(completed),
+ }
+}
+
+func (a Args) from(i int) Args {
+ a.All = a.All[i:]
+ a.Completed = a.Completed[i:]
+ return a
+}
+
+func removeLast(a []string) []string {
+ if len(a) > 0 {
+ return a[:len(a)-1]
+ }
+ return a
+}
+
+func last(args []string) (last string) {
+ if len(args) > 0 {
+ last = args[len(args)-1]
+ }
+ return
+}