-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple -directory flags #32
base: master
Are you sure you want to change the base?
Support multiple -directory flags #32
Conversation
A single -directory flag assumes a specific project structure wherein the app entry point and all of its dependencies are accessible in a single directory tree. However, this is not always the case. Consider mono-repos with multiple applications. Often, there are directories for each application and shared dependencies are in a different directory tree along side those applications. Additionally, applications may be categorized (for example backend, frontend, infrastructure, etc), which exacerbates the need for more flexibility in defining watchable directories. Allowing multiple -directory flags maintains the existing functionality and interface while also supporting different project organizations without having to create complicated and harder to maintain -exclude-dir configurations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for the PR :)
If I understand you correctly then you want to add support for directory whitelists in addition to the existing blacklist approach (-exclude-dir
). In that case the PR looks fine with the exception of some minor comments.
} | ||
|
||
// dirList must be unique, use a zero-byte struct map as a set. | ||
(*d)[clean_value] = struct{}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why we would add a directory entry if value == ""
. Is this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we can report the error later, which I believe maintains the existing functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what's there to report? You'd simply have (*d)[""] = struct{}{}
, which would also mean that the length of the dir list would be non-zero (although there was an invalid directory supplied) and .First()
will return ""
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved directory validation into validateFlags
to be more clear.
daemon.go
Outdated
flag_build_dir = &default_build_dir | ||
} else { | ||
fmt.Fprintf(os.Stderr, "-build-dir is required when specifying multiple watch directeries.\n") | ||
os.Exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to use log.Fatal()
here which does both of these things in one call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. I cut+pasted this from somewhere else so I was just following what existied.
log.Fatal("watcher.Add():", err) | ||
} | ||
} | ||
watchDirectories(watcher) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not the best way to refactor this. How about this:
func watchDirectory(dir string, watcher *fsnotify.Watcher) {
// ...
}
func main() {
// ...
for dir := range flag_directories {
watchDirectory(dir, watcher)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I structured it this way (along with validateFlags
) with an eye on cleaning up the main
function since it's doing a lot directly (many things could stand to be broken out into more functions). However, it's not that big of a deal so I'm happy to make the change.
Sorry for not getting back to you sooner. There's still one unaddressed review comment ( |
I'm a little swamped right now with work so I don't know when I'll be able to make that change. |
I am interested in this feature. Anything I can do to help get this merged? |
A single
-directory
flag assumes a specific project structure wherein the app entry point and all of its dependencies are accessible in a single directory tree. However, this is not always the case.Consider mono-repos with multiple applications. Often, there are directories for each application and shared dependencies are in a different directory tree along side those applications. Additionally, applications may be categorized (for example backend, frontend, infrastructure, etc), which exacerbates the need for more flexibility in defining watchable directories.
Allowing multiple
-directory
flags maintains the existing functionality and interface while also supporting different project organizations without having to create complicated and harder to maintain-exclude-dir
configurations.