Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

booleangate
Copy link

@booleangate booleangate commented Sep 13, 2018

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.

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.
Copy link
Owner

@githubnemo githubnemo left a 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{}{}
Copy link
Owner

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?

Copy link
Author

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.

Copy link
Owner

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 "".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reporting what was previously on 371 and is now on 408 (although I should have put that in validateFlags). Not adding it to the list would be ignoring it.

Copy link
Author

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)
Copy link
Owner

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.

Copy link
Author

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)
Copy link
Owner

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)
    }
}

Copy link
Author

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.

@githubnemo
Copy link
Owner

Sorry for not getting back to you sooner. There's still one unaddressed review comment (watchDirectories vs. watchDirectory). Do you still want to address this? It's OK if you don't, I would then merge this PR and address it myself afterwards.

@booleangate
Copy link
Author

I'm a little swamped right now with work so I don't know when I'll be able to make that change.

@sungwoncho
Copy link

I am interested in this feature. Anything I can do to help get this merged?

@booleangate booleangate reopened this Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants