diff options
author | Pacien | 2013-07-01 12:42:28 +0200 |
---|---|---|
committer | Pacien | 2013-07-01 12:42:28 +0200 |
commit | c879511377bdb76615b58b212f030e82fb88d3be (patch) | |
tree | 9c3783284594b98d923e230d361ec76e86200f3b /interactive.go | |
parent | 7b0b720efbf39ded2f72363d36424281df2b0491 (diff) | |
download | foldaweb-c879511377bdb76615b58b212f030e82fb88d3be.tar.gz |
Replace file manipulation functions by the fcmd package
Diffstat (limited to 'interactive.go')
-rw-r--r-- | interactive.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/interactive.go b/interactive.go index 22f5933..1c9ca71 100644 --- a/interactive.go +++ b/interactive.go | |||
@@ -21,6 +21,7 @@ package main | |||
21 | 21 | ||
22 | import ( | 22 | import ( |
23 | "fmt" | 23 | "fmt" |
24 | "github.com/Pacien/fcmd" | ||
24 | "github.com/howeyc/fsnotify" | 25 | "github.com/howeyc/fsnotify" |
25 | "os" | 26 | "os" |
26 | "path" | 27 | "path" |
@@ -30,7 +31,7 @@ import ( | |||
30 | 31 | ||
31 | func watch(dirPath string, watcher *fsnotify.Watcher) *fsnotify.Watcher { | 32 | func watch(dirPath string, watcher *fsnotify.Watcher) *fsnotify.Watcher { |
32 | watcher.Watch(dirPath) | 33 | watcher.Watch(dirPath) |
33 | dirs := explore(dirPath) | 34 | dirs, _ := fcmd.Explore(dirPath) |
34 | for _, dir := range dirs { | 35 | for _, dir := range dirs { |
35 | if !strings.HasPrefix(dir, *settings.outputDir) { | 36 | if !strings.HasPrefix(dir, *settings.outputDir) { |
36 | err := watcher.Watch(dir) | 37 | err := watcher.Watch(dir) |
@@ -70,7 +71,7 @@ func interactive(sourceDir, outputDir string, exts []string, saveAs string) { | |||
70 | fmt.Println(ev) | 71 | fmt.Println(ev) |
71 | 72 | ||
72 | // ignore hidden files | 73 | // ignore hidden files |
73 | if isHidden(ev.Name) { | 74 | if fcmd.IsHidden(ev.Name) { |
74 | break | 75 | break |
75 | } | 76 | } |
76 | 77 | ||
@@ -81,7 +82,7 @@ func interactive(sourceDir, outputDir string, exts []string, saveAs string) { | |||
81 | fmt.Println(err) | 82 | fmt.Println(err) |
82 | return | 83 | return |
83 | } | 84 | } |
84 | } else if ev.IsCreate() && isDir(ev.Name) { | 85 | } else if ev.IsCreate() && fcmd.IsDir(ev.Name) { |
85 | watcher = watch(ev.Name, watcher) | 86 | watcher = watch(ev.Name, watcher) |
86 | } | 87 | } |
87 | 88 | ||
@@ -90,7 +91,7 @@ func interactive(sourceDir, outputDir string, exts []string, saveAs string) { | |||
90 | // remove previously compiled files | 91 | // remove previously compiled files |
91 | if ev.IsDelete() || ev.IsRename() || ev.IsModify() { | 92 | if ev.IsDelete() || ev.IsRename() || ev.IsModify() { |
92 | var err error | 93 | var err error |
93 | if isDir(ev.Name) || !isParsable(ev.Name, exts) { | 94 | if fcmd.IsDir(ev.Name) || !isParsable(ev.Name, exts) { |
94 | err = os.RemoveAll(path.Join(outputDir, strings.TrimPrefix(ev.Name, sourceDir))) | 95 | err = os.RemoveAll(path.Join(outputDir, strings.TrimPrefix(ev.Name, sourceDir))) |
95 | } else { | 96 | } else { |
96 | err = os.RemoveAll(path.Join(outputDir, strings.TrimPrefix(dir, sourceDir))) | 97 | err = os.RemoveAll(path.Join(outputDir, strings.TrimPrefix(dir, sourceDir))) |
@@ -103,7 +104,7 @@ func interactive(sourceDir, outputDir string, exts []string, saveAs string) { | |||
103 | 104 | ||
104 | // recompile changed files | 105 | // recompile changed files |
105 | if ev.IsCreate() || ev.IsModify() { | 106 | if ev.IsCreate() || ev.IsModify() { |
106 | if isDir(ev.Name) { | 107 | if fcmd.IsDir(ev.Name) { |
107 | elements := parseParents(ev.Name, sourceDir, exts) | 108 | elements := parseParents(ev.Name, sourceDir, exts) |
108 | dirPath := path.Join(sourceDir, strings.TrimPrefix(ev.Name, sourceDir)) | 109 | dirPath := path.Join(sourceDir, strings.TrimPrefix(ev.Name, sourceDir)) |
109 | go compile(dirPath, elements, sourceDir, outputDir, saveAs, exts, true) | 110 | go compile(dirPath, elements, sourceDir, outputDir, saveAs, exts, true) |