diff options
| author | Eyal Posener <[email protected]> | 2017-05-13 22:44:36 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2017-05-13 22:44:36 +0300 |
| commit | a32482e70da76715645de14fa0a6201eace3df53 (patch) | |
| tree | b4d012d2f5714c479d54e9df3738508237add7c0 /args.go | |
| parent | c7377ba2de5df7097776c07f1ca68ca0fc8ee90e (diff) | |
test: add args tests
Diffstat (limited to 'args.go')
| -rw-r--r-- | args.go | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -28,18 +28,23 @@ type Args struct { // in case that it is not, we fall back to the current directory. func (a Args) Directory() string { if info, err := os.Stat(a.Last); err == nil && info.IsDir() { + if !filepath.IsAbs(a.Last) { + return relativePath(a.Last) + } return a.Last } dir := filepath.Dir(a.Last) - _, err := os.Stat(dir) - if err != nil { + if info, err := os.Stat(dir); err != nil || !info.IsDir() { return "./" } + if !filepath.IsAbs(dir) { + dir = relativePath(dir) + } return dir } func newArgs(line []string) Args { - completed := removeLast(line) + completed := removeLast(line[1:]) return Args{ All: line[1:], Completed: completed, @@ -49,7 +54,14 @@ func newArgs(line []string) Args { } func (a Args) from(i int) Args { + if i > len(a.All) { + i = len(a.All) + } a.All = a.All[i:] + + if i > len(a.Completed) { + i = len(a.Completed) + } a.Completed = a.Completed[i:] return a } |
