diff options
| author | Eyal Posener <[email protected]> | 2017-05-13 22:57:37 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-05-13 22:57:37 +0300 |
| commit | 6c02dfed2415ac952a3f5436fc237a8c6a9c8232 (patch) | |
| tree | 36a3d5b930747578ffef5ac62d07c5f2b5a9048f /args.go | |
| parent | 8bad6313cc30fa10f960b2758dd8db1c83add570 (diff) | |
| parent | a32482e70da76715645de14fa0a6201eace3df53 (diff) | |
Merge pull request #21 from posener/tests
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 } |
