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

add supporting wildcard in windows #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add supporting wildcard in windows #6

wants to merge 1 commit into from

Conversation

wzshiming
Copy link
Contributor

No description provided.

Copy link
Contributor

@x1ddos x1ddos left a comment

Choose a reason for hiding this comment

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

Could you provide a command sample which would work with this change but otherwise doesn't.

main.go Outdated
@@ -127,7 +137,7 @@ func addLicense(path string, fmode os.FileMode, typ string, data *copyrightData)
lic, err = prefix(typ, data, "", ";; ", "")
case ".erl":
lic, err = prefix(typ, data, "", "% ", "")
case ".hs":
case ".hs", ".sql":
Copy link
Contributor

Choose a reason for hiding this comment

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

This is already added in #7

@@ -95,7 +95,17 @@ type file struct {
mode os.FileMode
}

func walk(ch chan<- *file, start string) {
func walk(ch chan<- *file, path string) {
matches, _ := filepath.Glob(path)
Copy link
Contributor

@x1ddos x1ddos Jul 21, 2018

Choose a reason for hiding this comment

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

So, executing addlicense * doesn't work on Windows?
What kind of "glob" works/doesn't natively on Windows and how much is it different from filepath.Glob?

Copy link
Contributor Author

@wzshiming wzshiming Jul 22, 2018

Choose a reason for hiding this comment

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

Windows wildcards are handled by the program itself, so the program receives the * text instead of matching files.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, sounds reasonable. Although PowerShell does support expansion.
Either way, I wonder what the implications are for the cases were a file name contains meta/expansion characters recognized by filepath.Match. Currently, filepath.Glob does this check:

// hasMeta reports whether path contains any of the magic characters
// recognized by Match.
func hasMeta(path string) bool {
	// TODO(niemeyer): Should other magic characters be added here?
	return strings.ContainsAny(path, "*?[")
}

What if a path is something like ./mydir[hello] and it's passed verbatim in a shell which supports expansion like bash:

addlicense ./mydir\[hello\]/*

It might have undesirable effect, triggering filepath.Glob to try and expand ./mydir[hello].

We could add separate files with +build tags for Windows and Linux, but even on Windows, how would that work in DOS vs PowerShell without a confusion what expands/doesn't and at which point the expansion is done? Because I'm pretty sure filepath.Match has different set of expansion rules compared to PowerShell.

Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative for Windows, when not in PowerShell, could be to have another separate little program called expand and then feed the output of the expand to addlicense. It is probably out of scope for addlicense repo though.

Copy link
Contributor

Choose a reason for hiding this comment

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

@marcacohen maybe you have other ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PowerShell is also only partial command support, which is also command itself support, not PowerShell support.
So I don't think you have to worry about the difference DOS vs PowerShell.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passed verbatim in a shell which supports expansion, this is a problem.

@x1ddos
Copy link
Contributor

x1ddos commented Jul 22, 2018 via email

@mco-gh
Copy link
Contributor

mco-gh commented Jul 22, 2018

If the use case here is 'addlicense *', then would a non-globbing work around would be 'addlicense .' ?

I realize that does help the case of more refined globs (e.g. *.js) but I also feel like using Powershell (or Cygwin) might be acceptable vs. having to build essentially another mode into this comment ("local file globbing") or jump through other hoops for a limited range of use cases. How bad would it be to document this as a limitation of using addlicense with the dos shell?

@x1ddos
Copy link
Contributor

x1ddos commented Dec 18, 2019

Another way to solve this is to move func walk or the matching algorithm into a separate file like walk.go and then have another one named walk_windows.go so that addlicense for Windows expands paths within the program and relies on a shell expansion otherwise. Or use build tags instead of _windows.go suffix.

@wzshiming
Copy link
Contributor Author

This also needs to distinguish between shells, preferably only in the case of dos shell.

@x1ddos
Copy link
Contributor

x1ddos commented Dec 19, 2019

This also needs to distinguish between shells, preferably only in the case of dos shell.

I thought last time you said:

So I don't think you have to worry about the difference DOS vs PowerShell.

Or did you mean something else?

@wzshiming
Copy link
Contributor Author

I got it wrong. no problem.

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